25.12.2012 Views

MIPS Assembly Language Programming

MIPS Assembly Language Programming

MIPS Assembly Language Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

2.3. USING SPIM 23<br />

# end of add.asm<br />

2.3 Using SPIM<br />

At this point, we should have a working program. Now, it’s time to try running it to<br />

see what happens.<br />

To run SPIM, simply enter the command spim at the commandline. SPIM will<br />

print out a message similar to the following 5 :<br />

% spim<br />

SPIM Version 5.4 of Jan. 17, 1994<br />

Copyright 1990-1994 by James R. Larus (larus@cs.wisc.edu).<br />

All Rights Reserved.<br />

See the file README a full copyright notice.<br />

Loaded: /home/usr6/cs51/de51/SPIM/lib/trap.handler<br />

(spim)<br />

Whenever you see the (spim) prompt, you know that SPIM is ready to execute<br />

a command. In this case, since we want to run the program that we just wrote, the<br />

first thing we need to do is load the file containing the program. This is done with<br />

the load command:<br />

(spim) load "add.asm"<br />

The load command reads and assembles a file containing <strong>MIPS</strong> assembly language,<br />

and then loads it into the SPIM memory. If there are any errors during the<br />

assembly, error messages with line number are displayed. You should not try to execute<br />

a file that has not loaded successfully– SPIM will let you run the program, but<br />

it is unlikely that it will actually work.<br />

Once the program is loaded, you can use the run command to execute it:<br />

(spim) run<br />

The program runs, and then SPIM indicates that it is ready to execute another<br />

command. Since our program is supposed to leave its result in register $t0, we can<br />

verify that the program is working by asking SPIM to print out the contents of $t0,<br />

using the print command, to see if it contains the result we expect:<br />

5 The exact text will be different on different computers.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!