<5 points>
| Total points | Explanation |
|---|---|
| 0 | Not handed in |
| 1 | Handed in late |
| 2 | Handed in on time, not every problem fully worked through and clearly identifying the solution |
| 3 | Handed in on time, each problem answered a boxed answer, each problems answered with a clearly worked through solution, and less than majority of problems answered correctly |
| 4 | Handed in on time, majority of problems answered correctly, each solution boxed clearly, and each problem fully worked through |
| 5 | Handed in on time, every problem answered correctly, every solution boxed clearly, and every problem fully worked through. |
Chapter 2, sections 2.7-2.10, 2.12-2.14, 2.21, 2.22 of our textbook Read 2.20 if GPUs or parallel computing is of interest to you.
§ means “section,” and §§ means “sections”
These are tailored to test you understanding of loops, memory addresses, and the stack.
Task: Write a program that takes two integers from the user, multiplies the first by 8 using a shift instruction (not mul), adds the second integer to that result, and stores the final sum in a memory location labeled final_val.
sll for powers of 2 and sw for memory storage.print final_val in SPIM to verify the math.Task: Given an array of signed integers, write a loop that counts how many numbers in the array are negative (less than 0). Store the final count in register $s0.
array: .word 5, -2, 18, -1, -30slt to check if a number is less than $zero.$s0 increment only when a negative number is loaded.Task: Write a function calc_perimeter that takes two arguments (length and width in $a0 and $a1$) and returns the perimeter of a rectangle (2 x (length + width)).
$s registers are modified without being saved and restored.Task: Create a procedure called square_plus_one. It should take one argument (n), calculate n^2 + 1, and return the result.
jal, jr, and stack pointer ($sp) manipulation.main. Verify that $v0 contains 17 after the function returns.Task: Write a procedure average_of_squares.
square, for each argument.$ra (Return Address) on the stack. If they don’t save $ra, the program will enter an infinite loop when it tries to return to main.Task: Implement the Factorial function (n!).
Use this checklist when you get “stuck” on the exercises:
addi $t0, $t0, 1)..word is 4 bytes? (Your offset must be i * 4 because MIPS is byte-addressable).main values change after calling a function, check if you saved your $s registers on the stack.jr $ra? Ensure you restored $ra from the stack if your procedure called another procedure (nested calls).