Programming Assignment P5 - Some Assembly Required

Due Sunday, Oct. 2 at 10:00pm, late submission at 11:59pm.


This assignment has three objectives:
  1. To introduce you to the process of writing LC3 assembly code.
  2. To extend your familiarity with the LC3 instruction set.
  3. 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: 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:
  1. Loading your program into the LC3 simulator.
  2. Storing the operands into memory at one or more specified labels.
  3. Running (or initially stepping and debugging) your program.
  4. 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:
  1. Create a P5 directory in your cs270 directory for this assignment.
  2. Copy the starter file P5.asm into the directory.
  3. Open the file P5.asm with your favorite editor and study it.
  4. Assemble the program with the command
    		~cs270/lc3tools/lc3as P5.asm
  5. Implement one of the functions in the file (see testing below).
  6. Fix all assembler errors and make sure that P5.obj and P5.sym are created.
  7. Start the simulator with the command
    		~cs270/lc3tools/lc3sim-tk &
  8. Use the button to browse for and load your object code, called P5.obj.
  9. Click in the Address field and enter the label of the memory location, for example Option, Param1, Param2.
  10. After entering a label, you must press the left Enter key on the keyboard to go to that label.
  11. Click in the Value field and enter the value you want to store there and press Enter on the keyboard.
  12. 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.
  13. Place a breakpoint at the HALT instruction in the Main subroutine. Run your program by clicking on the Continue button.
  14. When the program stops, examine the value stored at memory location Result.
  15. 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): Final Testing (75 points):

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.