<< Assembly Unit Home

 ! 
 difficulty rating
Objectives
  • Write small programs using MIPS machine instructions.
  • Properly format assembly programs.

Valid HTML 4.01!

 ! 
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.

You should be able to translate this C assignment using information from the first lecture on Chapter 2 of your textbook.

Your assembly code must be properly formatted (check code samples around these pages for examples).

Also check the How-to link on formatting assembly code in the assembly unit homepage.

Load and run in SPIM to verify your code. Use the following input to test:

b = 0x10000000 the address where b is stored

Remember that the array variable name represents the address of the first byte in memory where the array is stored. In other words, it is just an address (the variable is really a label used by the compiler to symbolically refer to the address).

screenshot shows how to load the word 5 (at index 2 of array b) in addr 0x1000000c

4-word array b = {3,2,7,5} load 3 in Ox10000000, 2 in 0x10000004, 7 in 0x10000008, 5 in 0x1000000c

i = 2 load to register $s1 the input array index 2 where word value 7 is stored (at addr 0x10000008)

a = 3, c = 4, and sum = 0x10000010

The result should be 6 in DATA memory address 0x10000018.

Notice

Programming in assembly quickly becomes tedious (tiresome) because of the detailed nature of assembly language. That is why assemblers always offer ways to make assembly programming easier. You will learn more about these "services" in later exercises.

Back