Docsity

MIPS Simulator - Computer Systems - Lecture Slides, Slides of Computer Science

Partial preview of the text

Download MIPS Simulator - Computer Systems - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

CSE 410Computer Systems

L^

t^

SPIM A MIPS Si

l t

Lecture 4 – SPIM: A MIPS Simulator

SPIM simulatorSPIM

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

  • Known bug: won’t build on OS X 10.6; binaries

built on 10.5 intel should install ok on 10.6.built on 10.5 intel should install ok on 10.6.

3

5

Editing SPIM programsEditing

SPIM programs

•^

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

Assembly language basicsAssembly

language basics

-^

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

  • Execution begins here; SPIM

calls

main

  • main should return when done (

jr

$ra

)

-^

Much, much more in the book and upcoming lectures onfunction calling conventions

8

add sadd

.s

load two numbers from memory into registers, add them,# and store their sum

.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