Presentation is loading. Please wait.

Presentation is loading. Please wait.

SPIM : A MIPS Simulator Archi & Net Lab 이용석

Similar presentations


Presentation on theme: "SPIM : A MIPS Simulator Archi & Net Lab 이용석"— Presentation transcript:

1 SPIM : A MIPS Simulator Archi & Net Lab 이용석 (yslee@archi.snu.ac.kr)

2 Contents zIntroduction zSPIM Interface zSimulator Usage zMIPS R2000 Assembler Language zProgram Example

3 Introduction (1/2) zWhat’s SPIM? yA simulator that runs programs for the MIPS R2000/R3000 RISC computers zWhat does SPIM do? yReads and executes MIPS assembly language file immediately yWorks as a debugger yProvides some OS like services

4 Introduction (2/2) zWhere can we get SPIM?  FTP: ftp.cs.wisc.edu x/pub/spim/spimwin.exe zInstalling SPIM  Just run spimwin.exe and follow the installation procedure

5 Windows Interface zRegisters window yshows the values of all registers in the MIPS CPU and FPU zText segment window yshows instructions zData segment window yshows the data loaded into the program’s memory and the data of the program’s stack zMessages window yshows PCSpim messages (include error messages)

6 Simulator Usage zOpening source file yUse File menu or toolbar button zSimulation  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 zProgram 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) zData 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( ” ) xSpecial characters in strings follow the C convention newline (\n), tab (\t), quote (\”) .double,.float - floating point

9 MIPS Assembler Directives (2/2) zOther 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 zSystem Calls (syscall) yOS-like services zMethod yLoad system call code into register $v0 yLoad arguments into registers $a0…$a3 yAfter call, return value is in register $v0 zFrequently used system calls

11 SPIM Program Example (1/3) zA 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) zA 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) zA Program with Procedure Call # sample example ‘swap two numbers’.text.globlmain main: la$a0, array addi$a1, $0, 0 addi$sp, $sp, -4 sw$ra, 0($sp) jalswap lw$ra, 0($sp) addi$sp, $sp, 4 jr$ra.data array:.word 5, 4, 3, 2, 1 #swap(int v[], int k) #{ #int temp; #temp = v[k]; #v[k] = v[k+1]; #v[k+1] = 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


Download ppt "SPIM : A MIPS Simulator Archi & Net Lab 이용석"

Similar presentations


Ads by Google