SPIM : A MIPS Simulator - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

SPIM : A MIPS Simulator

Description:

What's SPIM? A simulator that runs programs for the MIPS R2000/R3000 RISC computers. What does SPIM do? Reads and executes MIPS assembly language file immediately ... – PowerPoint PPT presentation

Number of Views:251
Avg rating:3.0/5.0
Slides: 14
Provided by: yongs3
Category:
Tags: mips | spim | simulator | spim

less

Transcript and Presenter's Notes

Title: SPIM : A MIPS Simulator


1
SPIM A MIPS Simulator
  • Archi Net Lab
  • ???
  • (yslee_at_archi.snu.ac.kr)

2
Contents
  • Introduction
  • SPIM Interface
  • Simulator Usage
  • MIPS R2000 Assembler Language
  • Program Example

3
Introduction (1/2)
  • Whats SPIM?
  • A simulator that runs programs for the MIPS
    R2000/R3000 RISC computers
  • What does SPIM do?
  • Reads and executes MIPS assembly language file
    immediately
  • Works as a debugger
  • Provides some OS like services

4
Introduction (2/2)
  • Where can we get SPIM?
  • FTP ftp.cs.wisc.edu
  • /pub/spim/spimwin.exe
  • Installing SPIM
  • Just run spimwin.exe and follow the installation
    procedure

5
Windows Interface
  • Registers window
  • shows the values of all registers in the MIPS CPU
    and FPU
  • Text segment window
  • shows instructions
  • Data segment window
  • shows the data loaded into the programs memory
    and the data of the programs stack
  • Messages window
  • shows PCSpim messages (include error messages)

6
Simulator Usage
  • Opening source file
  • Use File menu or toolbar button
  • Simulation
  • Go Run loaded program
  • Break Stop the execution of the program
  • Single / Multiple Step Stepping for debugging
  • Breakpoint Stop program before it executes a
    particular instruction
  • Reload Reload source file after change it with
    editor program

7
MIPS Assembly Layout
  • Program Layout

.text code section .globl main starting
point must be global main user program
code .data data section label .data_type
list_of_data data loc data type
data .text code section label function
label user functions
8
MIPS Assembler Directives (1/2)
  • Data Types
  • .word, .half - 32/16 bit integer
  • .byte - 8 bit integer (similar to char type in
    C)
  • .ascii, .asciiz - string (asciiz is null
    terminated)
  • Strings are enclosed in double-quotas()
  • Special characters in strings follow the C
    convention
  • newline(\n), tab(\t), quote(\)
  • .double, .float - floating point

9
MIPS Assembler Directives (2/2)
  • Other Directives
  • .text - Indicates that following items are stored
    in the user text segment
  • .data - Indicates that following data items are
    stored in the data segment
  • .globl sym - Declare that symbol sym is global
    and can be referenced from other files

10
SPIM System Calls
  • System Calls (syscall)
  • OS-like services
  • Method
  • Load system call code into register v0
  • Load arguments into registers a0a3
  • After call, return value is in register v0
  • Frequently used system calls

11
SPIM Program Example (1/3)
  • A Simple Program

sample example 'add two numbers .text
text section .globl main call main by
SPIM main la t0, value load address value
into t0 lw t1, 0(t0) load word 0(value)
into t1 lw t2, 4(t0) load word 4(value)
into t2 add t3, t1, t2 add two numbers
into t3 sw t3, 8(t0) store word t3 into
8(t0) .data data section value .word 10,
20, 0 data for addition
12
SPIM Program Example (2/3)
  • A Program with System Call

sample example 'system call' .text .globl
main main la t0, value li v0, 5
syscall sw v0, 0(t0) li v0, 5
syscall sw v0, 4(t0)
lw t1, 0(t0) lw t2, 4(t0) add t3, t1,
t2 sw t3, 8(t0) li v0, 4 la a0,
msg1 syscall li v0, 1 move a0, t3
syscall .data value .word 0, 0, 0 msg1
.asciiz "Result "
13
SPIM Program Example (3/3)
  • A Program with Procedure Call

swap(int v, int k) int temp temp
vk vk vk1 vk1
temp swap add t1, a1, a1 add t1, t1,
t1 add t1, a0, t1 lw t0, 0(t1) lw t2,
4(t1) sw t2, 0(t1) sw t0, 4(t1) jr ra
sample example swap two numbers .text .globl m
ain main la a0, array addi a1, 0,
0 addi sp, sp, -4 sw ra,
0(sp) jal swap lw ra, 0(sp) addi sp,
sp, 4 jr ra .data array .word 5, 4, 3, 2, 1
Write a Comment
User Comments (0)
About PowerShow.com