CS 270
|
NOTE: For IntMul, you may assume that Param2 is either 0 or positive (Param1 could be anything). For the shift operations, you should fill the vacant positions with 0's. In other words, you don't have to worry about sign extension in the left and right shift subroutines because we will be doing logical shifts (as opposed to arithmetic shifts). Also, the number of bits (Param2) for left or right shifts will never be negative or zero.
IMPORTANT:
The protocol for debugging this assignment is presented in the lab. Note that you worked on the first three subroutines in the recitation.
P5.asm
with your favorite editor and study it.
~cs270/lc3tools/lc3as P5.asm
~cs270/lc3tools/lc3sim-tk &
Value
field and enter the value you
want to store in that memory location and press the left
Enter
key on the keyboard.
HALT
instruction in the Main
subroutine. Run your program by clicking on the Continue
button.
Reset
button and return to step 9) to start a new test.
When you reset the simulator, all breakpoints will be cleared and you
will need to place them again. Also, the memory locations that you
changed manually will be reset to the default values. An alternative to
changing the memory locations manually every time you reset the
simulator is to hard code the values in the program. To do this, change
the .BLKW 1
to .FILL xNNNN
for the
Option, Param1, and Param2 labels (NNNN is the
hexadecimal number you want). This is the one change you're allowed to
make to the reserved section. You may want to use the Step
button instead of Continue
if you need to see what happens
after every instruction in your program.
Note: when programming in assembly, it is easy to forget the syntax of each instruction (e.g., where do the source and destination registers go). Please refer to this document (starting on page 6) for a description of the assembly syntax for each LC-3 instruction.
Unlike left shifting, right shifting is not a trivial operation to implement in the LC-3. Let's go through an example of how to right shift. For this example, we will be using 5 bits instead of 16.
Suppose I want to do 10110 >> 2.
First, I will initialize my result to be 00000. The idea is that I will walk through the bits copying from left to right as follows:
Step 1
Notice that the first two bits starting from the right will go away. Hence, I'll start by copying bit 2 in my parameter to bit 0 in my result:
Parameter = 10110 Result = 00001
Step 2
Now, I move to the next bit. The next bit is 0, so I don't need to copy that bit to the result because the result was initialized to 0's:
Parameter = 10110 Result = 00001
Step 3
Now, I move to the next bit. The next bit is 1, so I need to copy that to the result:
Parameter = 10110 Result = 00101
Step 4
It looks like I've gone through all the bits in the parameter, so I'm done.
Parameter = 10110 Result = 00101
To inspect and copy bits, you will need to use masks and bitwise operations. Below is a flowchart that shows you the general algorithm for right shifting. You will need to take care of the details. Remember that numbers in the LC-3 are 16 bits wide (not 5).
P5.asm
to the Checkin tab on the
course website, as you were shown in the recitation, and check your
preliminary results.