Programming Assignment P5 - Some Assembly Required
Due Sunday, Oct. 2 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 in terms of instructions that the LC-3 can understand.
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. 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:For intMul, you may assume that Param2 is either 0 or positive
(Param1 could be anything). For leftShift, you should shift zeros on the right
side. For rightShift, you should shift zeroes on the left side. In other words,
you don't have to worry about sign extension in these two subroutines. 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 debugging this assignment is 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 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 label, you must press the left
Enter
key on the
keyboard to go to that label.
- Click in the
Value
field and enter the value you
want to store there and press Enter
on the keyboard.
- Repeat steps 9 to 11 for each value you need to set. To test intAdd, you
need to make Option = 0. To test intSub, you need to make Option = 1. And so on.
- Place a breakpoint at the
HALT
instruction in the Main
subroutine. 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 9) to start a new test
(Note: all breakpoints will be cleared and you will need to place them again). 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.
Grading Criteria
Preliminary Testing (25 points):
- 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)
Final Testing (75 points):
- Correct implementation of the binaryOr function.
- Correct implementation of the leftShift function.
- Correct implementation of the rightShift function.
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.