CSCI 221 F20

Lec 09-1

MIPS32 Programming


Below are several examples of MIPS32 programs that can be run within the SPIM simulator. They are all variations of summing a sequence of integers, many of them using SPIM’s syscall facility.


sum1to100.s
sum1to100output.s
sum_interacts.s
sum_evens.s
product.s
output100.s
hellobye.s


You can run each of these in the SPIM simulator. To obtain a copy of the simulator click on this “tarball” link. You’ll obtain a compressed binary archive file that contains the C source code for the simulator. Type the following commands in the console while in your MIPS work folder:

tar xvfpz spim-reedcs.tgz 
pushd spim-reedcs/spim
make
popd

This will make the SPIM simulator as an executable file named spim. You’ll want to make copies of that simulator executable (along with a supporting file) and put them within this repo folder so you can complete your work. Type these commands:

cp spim-reedcs/spim/spim .
cp spim-reedcs/CPU/exceptions.s .
cp spim-reedcs/helloworld.s .
./spim -f helloworld.s

The last line will actually run SPIM on a simple MIPS32 assembly program, one that greets the world.

To instead run our sample code, type something like

./spim -f sum1to100.s

It will run to completion, doing its work silently. A more interesting program to run is sum1to100output.s. This outputs the summed result to the console.

./spim -f sum1to100output.s

There are several resources you can access to learn the details of MIPS and SPIM, listed below:
the SPIM simulator
the MIPS32 processor family
SPIM’s MIPS information links
the MIPS32 programmer’s guide
a MIPS32 quick reference card
a SPIM system call reference