Programming Assignment P5 - Some Assembly Required
Due Sunday, Feb. 28 at 10:00pm, late submission at 11:59pm.
This assignment has three objectives:
- To introduce you to the process of writing LC3 assembly code.
- To extend your familiarity with the LC3 instruction set.
- To help you learn the LC3 tools including the assembler and simulator.
The Assignment
This assignment requires you to write a number of functions in LC3
assembly code. As the LC3 has a limited instruction set, you will find
that you must write code to perform operations that you take for granted
in high level programming languages such as C. For example, the left and
right shift operators (<< and >>) do not exist in LC3, nor is
there a bitwise OR operator (|). Therefore, you must write functions to
perform these operations. For all operations, the Param1 and Param2 variables
are the two operands and the answer is stored in the Result variable. All
numbers are 16-bit integers stored in 2's complement representation, and
all results are limited to 16-bits. You should have already completed the
first three functions during the lab. No detection of overflow is necessary.
Here is a description of the functions you must write:
- intAdd - Result = Param1 + Param2;
- intSub - Result = Param1 - Param2;
- intMul - Result = Param1 * Param2;
- binaryOr - Result = Param1 | Param2;
- leftShift - Result = Param1 << Param2;
- rightShift - Result = Param1 >> Param2;
NOTE:You should shift zeros on the right side for left shift, and onto
the left side for right shift. In other words, you don't have to worry about
signed numbers or sign extension. Also, the number of bits (Param2) for left
or right shifts will never be negative or zero.
To avoid making you write extensive I/O code for
LC3
, we will let you manually test code by:
- Loading your program into the LC3 simulator.
- Storing the operands into memory at one or more specified labels.
- Running (or initially stepping and debugging) your program.
- Examining one or more memory locations at specified labels for your results.
The protocol for this assignment has already been presented in the lab.
You can follow the same procedure when debugging your program, as shown below.
Getting Started
Perform the following steps:
- Create a P5 directory in your cs270 directory for this assignment.
- Copy the starter file P5.asm into the directory.
- Open the file
P5.asm
with your favorite editor and study it.
- Assemble the program with the command
~cs270/lc3tools/lc3as P5.asm
.
- Implement at least one of the functions in the file (see testing below).
- Fix all assembler errors and make sure that P5.obj and P5.sym are created.
- Start the simulator with the command
~cs270/lc3tools/lc3sim-tk &
.
- Use the button to browse for and load your object code, called P5.obj.
- Click in the
Address
field and enter the label of the memory
location, for example Option, Param1, Param2.
- After entering a value you must press
Enter
on the keyboard.
- Click in the
Value
field and enter the value you
want to store there and press Enter
on the keyboard.
- Repeat steps 9) and 10) for each value you need to set
- Run your program by clicking on the
Continue
button.
- When the program stops, examine the value stored at memory location Result.
- Hit the
Reset
button and return to step 8) to start a new test.
Grading Criteria
For P5, the preliminary testing will cover the functions listed below.
No additional testing will be performed, so your grade on P5 will be
determined by the result of preliminary testing.
- Program assembles without errors or warnings. (5 points)
- Correct implementation of the intAdd function. (5 points)
- Correct implementation of the intSub function. (5 points)
- Correct implementation of the intMul function. (10 points)
- Correct implementation of the binaryOr function. (25 points)
- Correct implementation of the leftShift function. (25 points)
- Correct implementation of the rightShift function. (25 points)
Here is an answer key that may help you to figure out the algorithms for
each function. The first colun is the test name, the second column is the
number of points, and the third column shows the test values and expected
result.
compileTest % 5 % make clean >/dev/null; make
integerAdd0 % 2 % Option = 0, Param1 = x5678, Param2 = x1234, Result = x68AC
integerAdd1 % 2 % Option = 0, Param1 = x1234, Param2 = xFFEC, Result = x1220
integerAdd2 % 1 % Option = 0, Param1 = x0000, Param2 = x1234, Result = x1234
integerSub0 % 2 % Option = 1, Param1 = x5678, Param2 = x1234, Result = x4444
integerSub1 % 2 % Option = 1, Param1 = x1234, Param2 = xFFEC, Result = x1248
integerSub2 % 1 % Option = 1, Param1 = xAA55, Param2 = x3355, Result = x7700
integerMul0 % 4 % Option = 2, Param1 = x5678, Param2 = x0000, Result = x0000
integerMul1 % 3 % Option = 2, Param1 = x1234, Param2 = x0010, Result = x2340
integerMul2 % 3 % Option = 2, Param1 = x1234, Param2 = x0003, Result = x369C
binaryOr0 % 10 % Option = 3, Param1 = x5678, Param2 = x0000, Result = x5678
binaryOr1 % 10 % Option = 3, Param1 = x0AA0, Param2 = x0550, Result = x0FF0
binaryOr2 % 5 % Option = 3, Param1 = x1234, Param2 = x6789, Result = x77BD
lshift0 % 10 % Option = 4, Param1 = x1234, Param2 = x0004, Result = x2340
lshift1 % 10 % Option = 4, Param1 = xAAAA, Param2 = x0001, Result = x5554
lshift2 % 5 % Option = 4, Param1 = x8765, Param2 = x0008, Result = x6500
rShift0 % 10 % Option = 5, Param1 = x1234, Param2 = x0005, Result = x0091
rShift1 % 10 % Option = 5, Param1 = x4321, Param2 = x0008, Result = x0043
rShift2 % 5 % Option = 5, Param1 = xA5A5, Param2 = x0002, Result = x2969
Assignment Submission
Submit the single file P5.asm
to the Checkin tab on the
course website, as you were shown in the recitation, and check your
preliminary results.
© 2016 CS270 Colorado State University. All Rights Reserved.