You will complete an LC3 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 retuned 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.

strcat(dest, src) - on entry R0 contains
dest, and R1 contains src.
On exit, src has been appended to the end of dest
and R0 contains dest.

printCC() - print the word NEGATIVE, ZERO, POSITIVE
depending on the value in register R0. At exit, register
R0 contains the original value. Each word is followed by a
newline. Do not depend on the condition code being set on entry.
The test of strcmp() uses this method.

strcmp(s1, s2) - on entry R0 contains
s1, and R1 contains s2. On
exit R0 contains a negative number if s1 < s2,
zero if s1 == s2 and a positive number if
s1 > s2.

pack(b1, b2) - combine the lower 8 bits of R0
and the lower 8 bits of R1 and pack them into a single
16 bit quantity in R0. The lower 8 bits of R0
will be in the upper 8 bits of the result.

getsp(dest) - on entry R0 contains the
address of a buffer. Read characters from the keyboard until an end-of-line
character is read. The end-of-line character may be either a CR of a LF
depending on the source and/or operating system.
Each pair of characters is packed into a single 16
bit value and stored in dest. The end-of-line is not
stored, but a NULL is stored to mark the end of the string.
On exit R0 contains dest. Your code must handle
input of either an even or odd number of characters. You will need to
experiment with LC3 to determine the order of 8 bit characters in the
16 bit word. Alternatively, you may read the lc3os.asm
for the PUTSP trap instruction.

unpack(b) - unpack the 16 bits in R0 into
registers R0,R1 such that the upper 8 bits of R0
are stored in the lower 8 bits of R0 and the lower 8 bits
of R0 are stored in the lower 8 bits of R1.

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 effeciency.

You might first write pseudo-code in a C or java like syntax to understand
the algorithum for a subroutine. You may find C implementations of various
string functions
here. If your code uses variables, you may
want to declare these variables for your 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 LC3 code for a subroutine, you may find it helpfull if you
add comments in each subroutine that explain how you are using the registers.
For example, you might write that ;R4 is the count.

Testing/debugging each individual subroutines follows a pattern:

Write/modify the code for a single subroutines.

Assemble your program using lc3as.

Load your program into the simulator/debugger.

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.

Set a break point at the entry of your subroutine, or wherever you would
like to start your debugging.

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.

When the program halts, examine output and/or memory locations for results.

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 (or TRAP) from another subroutine requires carefull
handling of the return address (R7).

Assignments Submission

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