<< Assembly Unit Home
Objectives
- Write small programs using MIPS machine instructions.
- Properly format assembly programs.
|
! SPIM Exercise 1.1 30 Minutes
Compile (or write equivalent MIPS assembly)
sum[i]=a+b[i]-c;
using $s0-$s4 to substitute for sum, i, a, b, c, respectively. Explain each step with a comment.
Your assembly code must be properly formatted (check code samples around these pages for examples).
Load and run in SPIM to verify your code. Use the following input to test:
screenshot
b = 0x10000000 (see the DATA window in SPIM)
4-word array b = {3,2,7,5},
i = 2 (word value 7 at index 2),
a = 3, c = 4, and
sum = 0x10000010
The answer is 6. Show me how!
! SPIM Exercise 1.2 30 Minutes
Write the while-loop necessary to compute array sum[] from Exercise 1.1. Again
assume a,b[],c as in 1.1 above. Hint: write the
loop structure first then fill the loop body. Check your solution in SPIM.
! SPIM Exercise 1.3 20 Minutes
Repeat 1.2 using a for-loop. Again, write the loop structure first. Check your solution in SPIM.
! SPIM Exercise 1.4 20 Minutes
Compile i=0; do { g=f+h; i=i+1; } while (i < j);. Trace your
code in SPIM assuming j=4. (Hint: j instruction is not
needed).
! SPIM Exercise 1.5 30 Minutes
Compile for (j=4; j>0; j--) { ... }. Use this loop structure to compute array sum[]. Check your code in SPIM.
! SPIM Exercise 1.6 20 Minutes
Change the loop condition in 1.4 to i≤j (less or equal). Trace
your code to ensure that the loop is executed 5 times instead of 4.
|