Programming Assignment P7 - LC-3 String Library

P7a - Due Sunday, Oct. 25 at 10:00pm, late submission at 11:59pm.

P7b - Due Sunday, Nov. 1 at 10:00pm, late submission at 11:59pm.

See the details of which subroutines must be implemented for P7a and P7b below.
This assignment has a number of objectives: You will complete an LC-3 assembly language program that implements a number of subroutines. Several of these subroutines are duplicates of C functions for strings. Subroutine parameters will be passed in register(s) R0/R1 and results will be returned in register(s). You may find that you do not have enough registers to keep all of your variables in registers. In this case, you will create variables to hold them.

The following list is the set of subroutines you must implement.


Getting Started

Start with the file string.asm. You may assemble and run the program. For many of the subroutines you will be prompted to enter a string (see the blue "console"). Enter whatever you like (< 256 chars). Your entry is terminated when you press the Enter key. As with any project, incremental development will improve your efficiency.

You might first write pseudo-code in a C or Java syntax to understand the algorithum for a subroutine. If your pseudo code uses variables, you may want to declare these variables for you subroutine. Declare them before the first statement of the subroutine. Although using variables may make your code a little longer, it is likely that you will get correct results more quickly if you use them. When you need a value, simply load it from the memory. When you update the value, write it back to memory. This is the load/store model.

When you write the LC-3 code for a subroutine, you may find it helpful if you add comments in each subroutine that explain how you are allocating the registers. For example, you might write ; R4 holds the count.

Testing/debugging each individual subroutines follows a pattern:

  1. Write/modify the code for a single subroutines.
  2. Assemble your program using lc3as.
  3. Load your program into the simulator/debugger.
  4. Set the variable Option to the index of the routine you wish to test. You may want to change the .FILL value so that you do not need to continually reset it as you write, and debug your subroutine.
  5. Set a break point at the entry of your subroutine, or wherever you would like to start your debugging.
  6. Continue the simulator/debugger. If you have set a breakpoint, it will stop when your program reaches that line. Use Step/Next to watch your code execute and examine registers and memory locations for correctness. You will want to use Next so that you do NOT step into the traps GETS, PUTS, PUTSP, GETC, OUT. You may step into them, but you will find them very tedious to step through.
  7. When the program halts, examine output and/or memory locations for results.
  8. Test your code with multiple test values and verify results
When you have completed one subroutine, move on to the next one.

You may want to call one subroutine from another, or add subroutines to accomplish specific tasks. Do not duplicate code in multiple places. Recall that calling a subroutine from another subroutine requires careful handling of the return address (R7), and that registers from the calling routine may be overwritten.

Grading Criteria

First installment of assignment (P7a): Second installment of assignment (P7b):


Assignments Submission

Submit the single file string.asm using the Checkin tab of the course website.