next up previous
Next: MIPS Memory Layout Up: SAL & SPIM Previous: Arithmetic Instructions

Example: Average Integers

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.

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:

  1. The address of the instruction in hexadecimal.
  2. The instruction in hexadecimal.
  3. The TAL instruction.
  4. 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