Вы находитесь на странице: 1из 9

SPIM simulator

SPIM
• SPIM
– Simulator that runs programs written for MIPS R2000/R3000
processors

• Advantages to using a machine simulator


– MIPS workstation are not generally available.
– Provides better environment for low-level programming than an actual
machine:
» detect more errors
» provide more features
» give convenient edit-assemble-load development cycle, compared
to using a circuit board.
» easy to identify and fix the bugs.
• Disadvantages
– The programs run slower than on a real machine.
OS vs Applications
• An application program asks the kernel to do I/O by making system
calls.
• The kernel implements these system calls by talking directly to the
hardware.

Application
programs
Programs make system calls asking kernel to do I/O

Kernel

Kernel controls I/O devices directly

Hardware
SPIM’s System Calls
• SIMP provides a small set of Service Call Arguments Results
10 OS-like system services code
through the system call
(syscall) instruction. print_int 1 $a0 = integer
• How t get a system service? print_float 2 $f12 = float
– $v0 : system call code print_double 3 $f12 = double
– $a0...$a3 : arguments print_string 4 $a0 = string
($f12 <- floating point
values) read_int 5 integer (in
– syscall (initiate system $v0)
service) read_float 6 float (in
– $v0 :results ($f0: for the $f0)
floating point) read_double 7 double (in
– exit: stop running a $f0)
program.
read_string 8 $a0 = buffer,
$a1 = length
sbrk 9 $a0 = amount address
(in $v0)
exit 10
1 ## hello.a -prints out "hello world"
2 ##
3 ##
4 ## a0 - points to the string
5 ##
6
7
############################################################
8 # #
9 # text segment #
10 # #
11
############################################################
12
13 .text
14 .globl __start
15 __ start : # execution starts here
16 la $a0,str # put string address into a0
17 li $v0,4 # system call to print
18 syscall # out a string
19
20 li $v0,10
21 syscall # au revoir ...
22
23
24
############################################################
25 # #
26 # data segment #
27 # #
28
############################################################
29
30 .data
31 str .asciiz "hello world"
32
3 kinds of SPIM
• spim for UNIX(installed in adam & cain)
– runs on any type of terminal
– type command on terminal
• xspim for UNIX(installed in adam & cain)
– runs on X-window system
– commands & results are always displayed
– much easier to run
• PCSpim for MS Windows
– runs on MS Windows system
– similar to xspim
– must be installed in your PC to use
PCSpim(starting)

• Registers window

• Text segment

• Data Segment

• Messages window
PCSpim(4 Windows)
• Registers window
– shows the values of all registers in the MIPS CPU and FPU
• Text segment

[0x00400000] 0x8fa40000 lw $4, 0($29) ; 89 : lw $a0, 0($sp)

– address of instruction (hexadecimal)


– instruction’s numerical encoding (hexadecimal)
– instruction’s mnemonic description
– line number in assembly file
– actual line of assembly file
• Data Segment
– data loaded into program’s memory
– data on the program’s stack
• Messages window
– messages for SPIM(including error messages)
PCSpim(Loading, Running, Debugging)
• Loading
– File -> Open
– select assembly file
• Running
– Simulator -> Go
– results are displayed in console
• Single step
– Simulator -> Single Step(F10)
– run an instruction at a time
• Multiple steps
– Simulator -> Multiple Step…(F11)
– run given number of instructions at a time
• Breakpoint
– Simulator -> Breakpoints(Ctrl + B)
– stop program immediately before it executes a particular instruction

Вам также может понравиться