Starting from:

$70

CMSC311 Lab 4 Solution

For this lab you will implement a basic LC3 assembly program which calculates the sum of all odd numbers stored between x3200 and x32FF inclusive.

Program Details

Your program will start at x3000 in memory and sum all odd numbers stored at memory locations x3200 to x32FF. Please note that while the autograder will populate these memory address with data values, when testing your program, you will need to place these values into memory manually. I recommend doing so by modifying the memory values via the simulator rather than using assembly code. Because the range of values is so large, I recommend placing a few values at the start of the memory range and a few at the end leaving the middle addresses empty. This will allow you to both confirm that your program is covering all necessary memory locations and also produce a result which is easy to verify.

The final sum will be stored at memory location x3300. Once stored, your program will halt the machine using the HALT command.

You must place any .FILL pseudo-ops after your HALT command. Placing .FILL pseudo-ops before the HALT will cause the data stored at those locations to be executed as instructions. This can cause your code to produce unexpected results and prevent Gradescope from executing correctly.

Bonus: +10 points for making and using an IsEven subroutine to determine if a specific value is even or odd. The subroutine must start at a label named IsEven and expect a single input parameter (a 2s complement number) in R0. If the given number is even, the subroutine will return 0. If the number is odd, it will return any non-zero value. The result of the subroutine will be stored in R0. You must define your subroutine after your halt instruction so that the subroutine will only execute if jumped to.

The IsEven subroutine must also implement callee save and preserve the values of registers R1-R5. NOTE: If your subroutine doesn't touch a register (i.e. modify its value) then you don't need to push that registers value onto the stack!

Development Notes

If you are looking for algorithmic inspiration (specifically for how to determine if a number is even or odd) I highly recommend the Unit 6 Lecture Slides along with the First50PrimesDemo.asm file on Canvas and their associated lecture recordings

When testing if a number is odd or even, please remember that a number can be negative or positive and to account for that in your program. Also note that if you use the user stack, you will need to initialize R6 with the stack pointer value first. The user stack should always start at xFDFF per the LC3 ISA.

For developing and testing your assembly program I recommend using the online LC3 simulator at: https://wchargin.com/lc3web/ . While this is the simulator I recommend, you are allowed to use any LC3 simulator to develop this project. **I also highly recommend downloading the LC3’s ISA from Canvas to use as a reference for this project. It is an invaluable resource which is vital for the project.** When saving your assembly program for Gradescope, you will need to use a text editor such as sublime text or notepad++

Please note that all lab submissions are required to have comments of some kind documenting the behavior of your program. Comments should describe the purpose / high level behavior of groups of instructions. They should not describe what an individual instruction literally does. For the statement:

AND R0,R0,#0

A good comment would be: ;sets R0 to 0

A poor comment would be: ;ANDs the value of R0 to 0 and stores the result

Final Notes

When completed, save your assembly program as Lab4.asm and submit your completed file to Gradescope. Although Gradescope is expected to descriptively report all errors it may sometimes produce errors which are opaque or unclear. In such case please do not hesitate to reach out to me via email or DM

Rubric

Category Points
Autograder 70
Code Formatting 15
Comments 15

More products