$24
Before You Begin
Please take the time to read the entire document before starting the assignment. We have made some important updates, and it is your responsibility to follow the instructions and rules.
Timed Lab Rules - Please Read
2.1 General Rules
You are allowed to submit this timed lab starting at the moment the assignment is released, until you are checked o by your TA as you leave the recitation classroom. Gradescope submissions will remain open until 7:15 pm - but you are not allowed to submit after you leave the recitation classroom under any circumstances. Submitting or resubmitting the assignment after you leave the classroom is a violation of the honor code - doing so will automatically incur a zero on the assignment and might result in you being referred to the O ce of Student Integrity.
Make sure to give your TA your Buzzcard before beginning the Timed Lab, and to pick it up and get checked o before you leave. Students who leave the recitation classroom without getting checked o or submit after getting checked o will receive a zero.
Although you may ask TAs for clari cation, you are ultimately responsible for what you submit. The information provided in this Timed Lab document takes precedence. If in doubt, please make sure to indicate any con icting information to your TAs.
Resources you are allowed to use during the timed lab:
Assignment les
Previous homework and lab submissions Your mind
Blank paper for scratch work (please ask for permission from your TAs if you want to take paper from your bag during the Timed Lab)
Resources you are NOT allowed to use:
The Internet (except for submissions)
Any resources that are not given in the assignment
Textbook or notes on paper or saved on your computer Email/messaging
Contact in any form with any other person besides TAs
Before you start, make sure to close every application on your computer. Banned resources, if found to be open during the Timed Lab period, will be considered a violation of the Timed Lab rules.
We reserve the right to monitor the classroom during the Timed Lab period using cameras, packet capture software, and other means.
2.2 Submission Rules
1. Follow the guidelines under the Deliverables section.
You are also responsible for ensuring that what you turn in is what you meant to turn in. After submitting, you should be sure to download your submission into a brand new folder and test if it works. There are no excuses if you submit the wrong les; what you turn in is what we grade. In addition, your assignment must be turned in via Gradescope. Under no circumstances whatsoever will we accept any email submission of an assignment. Note: if you were granted an extension, you will still turn in the assignment over Gradescope.
Do not submit links to les. We will not grade assignments submitted this way as it is easy to change the les after the submission period ends.
2.3 Is collaboration allowed?
Absolutely NOT. No collaboration is allowed for timed labs.
Overview
For this assignment, you will implement the subroutine called converge in LC-3 assembly according to the calling convention you have learned in lecture and practiced in Homework 07.
This subroutine recursively calls itself (as well as calls divide) until the parameter n converges to one.
3.1 The divide Subroutine
The divide subroutine takes two arguments:
: the numerator d : the denominator
The subroutine returns n / d.
Consider the following example outputs:
divide(15, 2) == 7
divide(100, 5) == 20
divide(n, d):
var q = 0
var r = n
while (r = d):
q = q + 1
r = r - d
return q ;; q == n / d
Note: The divide subroutine has already been written and assembled for your use in timedlab4.asm!
3.2 Reminder: JSR vs. JSRR
Subroutines are sometimes farther away in memory than JSR’s PCoffset11 allows. Recall that JSRR BaseR jumps to the address speci ed in BaseR, as opposed to an o set (i.e. JSR LABEL)!
3.3 Reference Sheets
You’ve been provided with two extra PDFs under reference/:
lc3-boilerplate.pdf
lc3-convention.pdf
3.3.1 The LC-3 Calling Convention
Please reference lc3-convention.pdf for some guidance on the LC-3 calling convention. Also, consider the following visual representation of a stack frame:
Last Local
R6: Stack pointer
R5: Frame pointer
First Local
Old Frame Pointer
Return Address
Return Value
First Argument
Last Argument
3.3.2 The LC-3 Boilerplate
Please reference lc3-boilerplate.pdf for templates and guidance translating pseudocode to LC-3 assembly.
Instructions
The following les have been provided for you:
timedlab4.asm
reference/
lc3-boilerplate.pdf
lc3-convention.pdf
You will be editing timedlab4.asm. We have de ned the assembly language label STACK. You should not access or alter the value at this label, as it is intended for use by the tester.
The subroutine converge takes the following arguments:
n: an integer
Given any value of n, this subroutine will recursively call itself until n converges to one. The return value is the number of recursive calls it took to converge.
For example:
converge(8): converge(4) -- converge(2) -- converge(1) which returns 3.
converge(3): converge(10) -- converge(5) -- converge(16) --
converge(8) -- converge(4) -- converge(2) -- converge(1) which returns 7.
Note: You need not understand why this works to complete the assignment!
Note: In the above examples, there would also be calls to divide.
4.1 Pseudocode
Implement this pseudocode following the label converge in timedlab4.asm:
converge(n):
if (n == 1):
return 0
var div = divide(n, 2)
var mod = n % 2 ;; Hint: a % b == a & (b - 1) in this case
;; since b is a power of 2!
if (mod == 0):
return converge(div) + 1
else:
return converge((3 * n) + 1) + 1
Notice you’ll need to call the divide subroutine. The address of this subroutine is provided at the label DIV ADDR. Refer to the prior section for information on this subroutine’s arguments and return value.
4.2 Restrictions
You are not allowed to use Appendix A or the textbook during this assignment.
5Testing Your Work
To test your program, upload timedlab4.asm to the Timed Lab 4 assignment on Gradescope. You may resubmit your work as many times as needed, until you sign out and leave the classroom.
Common Errors
To trace problems with your code, load the le into complx, the LC-3 simulator. To use complx:
In the Terminal, type complx
In the File menu, click Reload, and open your assembly le (timedlab4.asm)
Use the Step button to run each instruction one step at a time, or use the Run button to execute all of the instructions until HALT
Rubric
The output of the Gradescope autograder is an approximation of your score on this assignment. The tool is provided so you can evaluate whether your submission ful lls the assignment expectations.
However, we reserve the right to run additional tests, fewer tests, di erent tests, or potentially change individual tests { your nal score will be determined by your instructors, and there is no guarantee your score will correlate with the tester output.
Deliverables
Please upload the following le to the assignment on Gradescope:
timedlab4.asm
Do NOT upload an archive; upload the le individually.
Be sure to check your Gradescope test score before you leave the room.
LC-3 Assembly Programming Requirements
9.1 Overview
Your code must assemble with NO WARNINGS OR ERRORS. To assemble your program, open the le with Complx. It will complain if there are any issues. If the code in this le does not assemble, you WILL get a zero for that le.
Comment your code! 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. Try to write high-level pseudo-code instead!
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
DO NOT assume that ANYTHING in the LC-3 is already zero. Treat the machine as if your program was loaded into a machine with random values stored in the memory and register le.
Following from 3. You can randomize the memory and load your program by doing File ! Randomize and Load.
Do not add any comments beginning with @plugin or change any comments of this kind.
Test your assembly. Don’t just assume it works and turn it in.
7