Starting from:
$30

$24

CS 2110 Final Exam: LC-3 Assembly

2.1 Purpose




The purpose of this coding section of the final exam is to test your understanding of coding in LC-3 assembly.




2.2 Task




In this section of the final exam, you will be implementing a short assembly program. Please see the detailed instructions on the following page. We have provided pseudocode for the program—you should follow the algorithm when writing your assembly code.




2.3 Criteria




This section will be graded based on your ability to correctly translate the given pseudocode for an algorithm into LC-3 assembly code. Please use the LC-3 instruction set when writing these programs. Check the Deliverables section for what you must submit to Gradescope.




You must produce and save the correct value for the algorithm, and your code must assemble with no warnings or errors (Complx and the autograder will tell you if there are any). If your code does not assemble, we will not be able to grade that file and you will not receive any points.

 Instructions and Implementation



For the LC-3 Assembly coding section of the final exam, you will be implementing a subroutine that calculates the greatest common divisor (GCD) of two integers. The result should be stored on the stack in accordance with the LC-3 Calling Convention. You must implement the recursive version to get full credit. We provide a helper subroutine called MOD. It is encoded in hexadecimal, but you still can call it like any normal subroutine!




3.1 gcd algorithm




Implement the recursive Euclidean algorithm:




If b is 0, then the GCD is a. Else, try again with a ← b and b ← a % b. We provide a helper subroutine MOD that can calculate a % b for you. Pseudocode:




int gcd(int a, int b) {




if (b == 0) {




return a;




}




c = mod(a, b); // MOD subroutine has already been provided return gcd(b, c);




}




Example:




GCD(56, 36)




36̸=0




GCD(36, 56 % 36) = GCD(36, 20)




20̸=0




GCD(20, 36 % 20) = GCD(20, 16)




16̸=0




GCD(16, 20 % 16) = GCD(16, 4)




4̸=0




GCD(16, 16 % 4) = GCD(4, 0)




0 = 0 → return 4




GCD(56, 36) = 4




Please refer to Grading for details on how gcd will be graded.

 Grading



Point distribution for this coding portion of the final exam is broken down as follows:




gcd (85 points): Correct return value.



Calling Convention (15 points): Appropriately calls mod and correctly follows LC-3 Calling Convention.






Deliverables



Turn in the following file on Gradescope during your assigned final exam coding period:




gcd.asm
 Local Autograder




To run the autograder locally, follow the steps below depending upon your operating system:




Mac/Linux Users:



Navigate to the directory your files are in (in your terminal on your host machine, not in the Docker container via your browser)



Run the command sudo chmod +x grade.sh



Now run ./grade.sh



Windows Users:



In Git Bash (or Docker Quickstart Terminal for legacy Docker installations), navigate to the directory your files are in



Run chmod +x grade.sh



Run ./grade.sh
 LC-3 Assembly Programming Requirements and Tips




7.1 Overview




Your code must assemble with no warnings or errors. To assemble your program, open the file with Complx. It will complain if there are any issues. If your code does not assemble, you will get a zero for that file.



Do not assume that your registers start out initialized to zero. Assume everything is initialized with random garbage data.



Do not add any comments beginning with @plugin or change any comments of this kind.



You should not use a compiler that outputs LC3 to do this assignment.



Test your assembly. Don’t just assume it works and turn it in.



Comment your code! (not a hard requirement, but will make your life much easier) This is especially important in assembly, because it’s much harder to interpret what is happening later, and you’ll be glad you left yourself notes on what certain instructions are contributing to the code. Comment things like what registers are being used for and what less intuitive lines of code are actually doing. To comment code in LC-3 assembly just type a semicolon (;), and the rest of that line will be a comment.



Avoid stating the obvious in your comments, it doesn’t help in understanding what the code is doing. Good Comment




   ADD R3,
R3, -1
; counter--
BRp LOOP
; if counter == 0 don’t loop again
Bad Comment


ADD
R3,
R3, -1
; Decrement R3
BRp
LOOP
; Branch to LOOP if positive
 Appendix



8.1 Appendix A: LC-3 Instruction Set Architecture

  


   

More products