





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






t^
SPIM A MIPS Si
l t
Lecture 4 – SPIM: A MIPS Simulator
SPIM lets you write MIPS assembly language code
y^
y^
g^
g
and run it on a PC, linux, or mac
-^
PCSpim should be installed on the machines in theA&S
t^
l b
A&S computer lab
-^
You can download versions for Windows and allvarieties of *nix (including MacOS X) from the webvarieties of
nix (including MacOS X) from the web
site– Trade hints on the discussion list if you have
t^
bl
b ildi
/i^
t lli
it
troubles building/installing it
built on 10.5 intel should install ok on 10.6.built on 10.5 intel should install ok on 10.6.
3
5
You can use any (plain) text editor you like to write
y (p
y
the source code–
Not
Microsoft Word
Textpad notepad++ etc
on PC’s
Textpad, notepad++, etc., on PC s
-^
jEdit also provides a MIPS assembly highlighter
-^
emacs can do anything including asm – but has apretty steep learning curve
-^
A few examples follow on the next slides
6
-^
SPIM reads a program written in MIPS assembly
p^
g^
y
language, translates it to machine code(001011001100…), then executes it
-^
Programs have two sectionsPrograms have two sections– .data – storage for constants and variables– .text – program codeSections can be repeated (alternated) as often as needed
-^
Code must contain a label
main:
Execution begins here; SPIM
“calls” main
calls
main
jr
$ra
)
-^
Much, much more in the book and upcoming lectures onfunction calling conventions
8
.data
one:
word
1
one:
.word
1
two:
.word
2
sum:
.word
t^
t .text
main:
lw
$t0,one
lw
$t1,two
add
$t2,$t0,$t
sw
$t2,sum
jr^
$ra # return
jr^
$ra # return
9