Next: MIPS Memory Layout
Up: SAL & SPIM
Previous: Arithmetic Instructions
The following Pascal statement averages three integers:
-
- avg := (i1 + i2 + i3) / 3 ;
The same computation in SAL requires 3 instructions:
add avg, i1, i2
add avg, avg, i3
div avg, avg, 3
To run the program on the SPIM simulator, certain
declarations must be added.
- The variables used in the program must be declared in the
.data section of the program;
- A .text directive must precede the executable
instructions;
- The first instruction in the program must begin with the label
__start: (this label begins with two underscores);
- The program must end with a done instruction, which
tells the CPU to terminate execution of the program.
A terminal session from the SPIM simulator can be logged using the Unix
script command. The output from the simulator for the above program is
shown below.
Note the use of the simulator load, step, and
print commands to control program execution.
Each line of output
from the simulator step command consists of:
- The address of the instruction in hexadecimal.
- The instruction in hexadecimal.
- The TAL instruction.
- A comment field beginning with # containing the SAL instruction.
For more information on running the simulator, please refer to the
SPIM simulator reference manual.
CS 301 Class Account
Wed Sep 20 17:20:34 ADT 2000