$29.99
CS 2110 Lab 9 Assignment: Stack Subtract
Contents
1 Problem 1
1.1 Problem Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Pseudocode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3 Important Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2 Testing and Autograder 2
2.1 Testing in Complx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.2 Autograder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1 Problem
1.1 Problem Description
For this lab, you will have to write an LC-3 subroutine called subtract which subtracts one number from
another. You will also need to write the main function which will call this subroutine. You will write your
solution in stacksubtract.asm.
1.2 Pseudocode
You will be implementing subtract from the pseudocode available below. We have provided a code skeleton
for you to complete. We recommend you write this first.
You will also be implementing a main routine which will run when the LC-3 starts up. Please code main()
in between .orig x3000 and HALT.
int subtract(int a, int b) {
return a + (-b);
}
void main() {
int a = MEM[A];
int b = MEM[B];
int result = subtract(a,b);
MEM[RESULT] = result;
}
1
1.3 Important Details
• The inputs are stored at labels A and B.
• You must properly handle the stack when writing subtract and calling subtract. Keep in mind that
you are passing two arguments to this function.
• Please check out the slides and lab guide for information on how to structure your stack frame. This
lab is designed to make you think about how to implement the stack frame yourself.
• You should write the result into RESULT.
2 Testing and Autograder
2.1 Testing in Complx
1. Load the stacksubtract.asm file into Complx inside your Docker container.
2. Run the program. At the end, you may check the RESULT label in memory to determine the result.
See if it matches what you expect.
NOTE: To test your subtract subroutine before implementing main, you may find it helpful to use the
“Debug → Simulate Subroutine Call” feature of Complx.
2.2 Autograder
• On Mac or Linux
1. Navigate in your host machine terminal to the same directory as stacksubtract.asm
2. Run sudo chmod +x grade.sh
3. Run ./grade.sh
• On Windows
1. Navigate in Git Bash (or Docker Quickstart Terminal for legacy Docker installations) to the same
directory as stacksubtract.asm
2. Run ./grade.sh
Once you’re done, complete the Lab 9 quiz that’s available in Canvas! Your TAs should have already given
you the quiz code at the start of lab.