CS 12 -- Lab 9

Today, we will do a bit of assembly programming using SPIM, the (not-so-cleverly named) MIPS simulator. We'll run a couple of simple programs, and then give a shot at writing one.


Running SPIM

So that we can write and run simple assembly programs, we are going to use SPIM, which simulates the operation of a MIPS chip. Most critically, this program will allow us to step through the instructions, one at a time, while observing how the registers change with each instruction. We will begin by examining two existing assembly programs whose operation you should be able to follow. Grab these two programs from my directory:

~sfkaplan/public/cs12/add-two-numbers.s
~sfkaplan/public/cs12/simple-conditional.s

Open the first of these files with XEmacs and take a look. The instructions should be generally familiar, but there are going to be some unfamiliar pieces that we will cover during lab, particularly system calls. This program simply seeks to add two values together and then print the results.

Now try using SPIM itself on this file, like so:

spim add-two-numbers.s

You will get a new, perhaps preplexing window. On top are the registers and their current values. Somewhere in the middle is the code from the file, although perhaps a bit mutated -- we will have to discuss psuedo-instructions to see why. The middle of the window has some buttons that control the execution of the program. We'll use those to step through, one instruction at a time, and see what each instruction does. Then we'll do the same for simple-conditional.s.


Your assignment

Now that you see how to use SPIM to run some simple assmebly programs, you need to write a new one. This program should perform a loop. Specifically, create the new program in a file named count-down.s, and write a loop that counts down from some arbitrary value to 0.

In this program, one register should be chosen as the counter register. That register should be set to some initial counter value (say, 5). The loop should then count down from 5 to 0, printing the value of the counter to a new line during each iteration of the loop. That is, if the counter begins at 5, the output should be:

5
4
3
2
1

Note that assembly should be commented. Since the program is simple, these comments should simply indicate what role each group of instructions plays in performing the loop.


What you must submit

Once you have written and tested your loop program, you must use the cs12-submit command to submit it. Submit this assignment as lab-9 when you use the cs12-submit command.


This assignment is due on Sunday, May 2nd, at 11:59 pm.

Scott F. Kaplan
Last modified: Sun Nov 5 22:48:52 EST 2000