$24
Please take the time to read the entire document before starting the assignment. It is your responsibility to follow the instructions and rules.
Timed Lab Rules - Please Read
1.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 be 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 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.
1.2 Submission Rules
Follow the guidelines under the Deliverables section.
You are also responsible for ensuring that what you turned 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. 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.
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.
1.3 Is collaboration allowed?
Absolutely NOT. No collaboration is allowed for timed labs.
Overview
In this timed lab, you will writing code to sum either all the negative or all the positive numbers in the array, depending on whether the last element is negative or positive. You will be graded on 3 \checkpoints." For each checkpoint you achieve you will earn a set number of points. The address of the array will be stored at the label \ARRAY" and the length of the array will be stored at the label \LEN". The pseudocode for this algorithm is provided and includes the checkpoints.
Instructions
3.1 Checkpoint 1: Last Element (20 points)
Take the last element of the array, and store it in memory at the label \CHECKPOINT1"
3.2 Checkpoint 2: Negative/Positive (20 points)
Check to see if the last element of the array is negative or positive. If the last element is negative, store the integer value -1 in memory at the label \CHECKPOINT2". If the last element is positive, store the integer value 1 in memory at the label \CHECKPOINT2".
3.3 Checkpoint 3: Sum (60 points)
If the the last element of the array is negative, sum all the negative integers in the array, if it is positive, sum all the positive integers in the array. Store the respective sum in memory at the label \CHECKPOINT3"
3.4 Zero
If the last element of the array was zero, store zero in both \CHECKPOINT2" and \CHECKPOINT3"
3.5 Pseudocode
You will only be writing the body of this function, it is not recursive, you do not need to use the stack.
void sumNegPos(int[] ARRAY, int LEN) {
CHECKPOINT1 = ARRAY[LEN - 1];
int sum = 0;
if (ARRAY[LEN - 1] < 0) {
CHECKPOINT2 = -1;
for (int i = 0; i < LEN; i++) {
if (ARRAY[i] < 0) {
sum += ARRAY[i];
}
}
CHECKPOINT3 = sum
} else if (ARRAY[LEN - 1] 0) { CHECKPOINT2 = 1
for (int i = 0; i < LEN; i++) { if (ARRAY[i] 0) {
sum += ARRAY[i];
}
}
CHECKPOINT3 = sum; } else {
CHECKPOINT2 = 0;
CHECKPOINT3 = 0;
}
}
Local Grader
To run the autograder locally, follow the steps below depending upon your operating system:
Mac/Linux Users:
Navigate to the directory your timed lab is in. In your terminal, not in your browser
Run the command sudo chmod +x grade.sh
Now run ./grade.sh
Windows Users:
On docker quickstart, navigate to the directory your homework is in
Run ./grade.sh
The output of the autograder is an approximation of your score on this timed lab. It is a tool provided to students so that you can evaluate how much of the assignment expectations your submission ful lls. However, we reserve the right to run additional tests, fewer tests, di erent tests, or change individual tests - your nal score will be determined by your instructors and no guarantee of tester output correlation is given.
Deliverables
Please upload the following les to Gradescope:
1. tl3.asm
Download and test your submission to make sure you submitted the right les
LC-3 Assembly Programming Requirements
6.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 your code does not assemble you WILL get a zero for that le.
4
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.
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.
Use the LC-3 calling convention. This means that all local variables, frame pointer, etc. . . must be pushed onto the stack. Our autograder will be checking for correct stack setup.
Start the stack at xF000. The stack pointer always points to the last used stack location. This means you will allocate space rst, then store onto the stack pointer.
Do NOT execute any data as if it were an instruction (meaning you should put . lls after HALT or RET).
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.
5