
HELP WITH SPIM
4th. edition of the textbook :
Appendix B is the best reference on SPIM. See pages B-20 – B-26 (skip
recursive procedures) and B-40 – B-50. All instructions are discussed on
B-51 &ndash B-80.
3rd. revised edition of the textbook : Appendix
A is the best reference on SPIM. See pages A-20 – A-26 (skip
recursive procedures) and A-40 – A-49. All instructions are discussed on
A-50 – A-79.
For the MIPS instruction set see
Spim Instruction Set.
Examples of SPIM Programs:
See the ~cse220/examples/spim directory on sparky.
|
Installing
the SPIM simulator on your PC:
There are two simulators available to you for download and installation on your PC that you can use to run SPIM programs:
- PCSpim, which is available on the CD that comes with the textbook. Below, we provide some guidance on how to install, test and use PCSpim.
- MARS MIPS Simulator. This is perhaps somewhat more “user-friendly” to use than PCSpim, so you might prefer to adopt it instead.
Note that neither PCSpim nor MARS provide an editor for you to develop and edit SPIM program files (these files always have a ‘.s’ or ‘.asm’ extension in their name, just like, for example, Java program files always have ‘.java’ / ‘.jar’ extensions, etc.).
You will need some kind of text editor such as
winedit
or emacs (or whatever text editior you currently use on your PC) to write/view/edit .s or .asm files.
|
Installing PCSpim:
The textbook has PCSpim on the CD that comes with
it. There are some related help documents available there as well.
(You can also download PCSpim from this link instead.)
- Unzip or unpack the file.
- Run "pcspim.exe"
- Once open, there should be a window titled "PCSpim"
and
a second window another window titled "Console". This means your PCSpim
has been correctly installed.
The download (zip file) for PCSpim includes a file named
`trap.handler'. For unknown reasons, setup.exe does not move this file
to the install directory. After you run setup.exe and the
installation is completed, you should copy trap.handler to the
directory where you installed PCSpim. Then start PCSpim and select the
simulator->settings menu. Under `trap file' browse for the
"trap.handler" file.
Testing
PCSpim installation
- Create
a text file called "test.asm" for testing PCSpim with it.
- Place
the following text in the file. Make sure you don't copy any html tags
or additional assci characters.
.text
.globl main
main:
li $v0, 4
la $a0, str
syscall # print string
li $v0, 10
syscall # exit
.data
str: .asciiz "Hello World!!!"
########### End of test.asm ############ |
- Run
"pcspim.exe"
- Open
the file menu in PCSpim, choose open and find the file "test.asm". After
you open it press F5, a menu pops up - choose ok for that window. In
your console window you should see the message "Hello World!!!".
Opening the file menu and loading the .asm files successfully
means that the file has assembled (compiled) correctly, otherwise
there are syntax errors in that program causing it not to be loaded
by PCSpim. PCSpim tells you which line the error(s) is.
Once loaded, press F5 to run it, -- ok that pop up window. Output will
be in the Console window.
The top 3 split windows in PCSpim are as follows.
The top window is called register display. It shows contents
of all registers in the MIPS CPU (general registers and floating
point registers). This display is updated whenever your program stops
running.
The next window is called text segments. It displays instructions both
from your program and the machine code that is assembled (compiled)
from the program you load. Each instruction is displayed on a line that
looks like:
|
[0x00400000] |
0x8fa40000 |
lw $4, 0($29) ; |
102: lw $a0, 0($sp) |
| Address |
Contents in Hex |
Machine Instruction |
Actual Statement in your program |
The first number on the line, in square brackets, is the hexadecimal
memory address of the instruction. Note that each instruction is one
word or 4 bytes long. Check the address of the next one. The second
number on the same line is the instruction's numerical encoding in hex,
which starts as 0x...... The third item is the machine instruction's
description. Everything following the semicolon is the actual line from
your assembly language program that produced the machine instruction
displayed. The number 102 is the line number in your program file.
Sometimes nothing is on the line after the semicolon. This means that
the instruction was produced by SPIM as part of translating a
pseudo-instruction.
The next window is called the data and stack segments. It displays the
data loaded into your program's data area and contents of the program's
stack.
The bottom window gives information of what PCSpim has done
such as a file being successfully loaded.
|