This assignment is the first in which you will actually write code in LC-3 assembly language. Be sure to start early, because learning how to use the LC-3 tools will take some time. Please see the LC-3 Simulator Guide for instructions on getting and using the simulator.
For your convenience, you can download all the code associated with this assignment (all test scripts and assembly code, including the LC-3 OS) as a ZIP archive. Note that this does not include the simulator itself: that's available here.
Write LC-3 assembly code to increment the value in R2 by 1 and place the result in R5. Actually, this is so simple that we'll give you the code for it here. Don't turn anything in for this problem, the objective here is to try running the code using the simulator and the test scripts (script1 script2 script3) we provide. Please see the LC-3 Simulator Guide for step-by-step instructions on setting up and using the simulator.
Write LC-3 assembly code to subtract the value in R2 from the value in R3 and place the result in R5. That is, write the assembly code for R5 := R3 - R2. Your program can destroy the values in R2 and R3; the only value that we will check is that in R5.
We've provided some skeleton code to help you get started. For this problem, you should electronically turn in a file named p1.asm, per the submission instructions, below. The LC-3 Simulator Guide contains general instructions on how to go about writing and testing LC-3 code in the simulator. Make sure to check your code against the test cases we provide ( script1 script2 script3 script4 ), as well as additional test cases that you create.
You may have noticed that the LC-3 doesn't have an OR instruction. Using your knowledge of logical completeness and DeMorgan's Laws, write LC-3 assembly code that takes the values in R2 and R3 and puts the result of OR-ing them together into R5. That is, implement R5 := R2 OR R3. Your program can destroy the values in R2 and R3; the only value that we will check is that in R5.
Start from the skeleton code, and debug and test your code as you did for the previous problem. Test your code using our test cases ( script1 script2 script3 script4 ) plus additional ones you create. Turn in a file named p2.asm per the submission instructions, below.
These problems involve finding bugs in small assembly programs. The problems themselves are described on another handout. Please write your answers on that handout, and turn it in before the start of class on the due date.
You should also grab the assembly code for each problem: the code for problem 3 is here, and for problem 4 here.
In the original implementation of the LC-3 ISA, there was no multiply instruction. The current LC-3 uses the reserved opcode 1101 for multiply. In the spirit of those who have taken the class before you, write LC-3 assembly code to take the value in R2, multiply it by the value in R3, and place the result in R5. Of course, you are not allowed to use the MUL instruction! You can make two simplifying assumptions in your solution: the values in both R2 and R3 will be >= 0, and the result of the multiplication will not overflow a 16-bit representation. Essentially, implement R5 := R2 x R3. Your program can destroy the values in R2 and R3; the only value that we will check is that in R5.
You can start from the skeleton code, as with the other problems, and test your code with scripts ( script1 script2 script3 script4 ). Turn in a file named p5.asm per the submission instructions, below. HINT: This program took us about 7 instructions to implement; if you're using many more than this, you may want to reconsider your approach.
Your solutions for this homework must be submitted before class on the due date. Please write down your answers for problems 3 and 4 on the provided PDF handout and turn them in before the start of lecture. You will turn in your solutions to problems 1, 2 and 5 electronically. The electronic homework submission form for this class is located at http://fling-l.seas.upenn.edu/~cse240/submission/submit.php. You have to login using your PennKey, but the process should be fairly intuitive. You may submit the assignment as many times as you like; however, only the last submission will be graded.