1 / 13

SPIM : A MIPS Simulator

SPIM : A MIPS Simulator. Archi & Net Lab 이용석 ( yslee@archi.snu.ac.kr). Contents. Introduction SPIM Interface Simulator Usage MIPS R2000 Assembler Language Program Example. Introduction (1/2). What’s SPIM? A simulator that runs programs for the MIPS R2000/R3000 RISC computers

lynton
Télécharger la présentation

SPIM : A MIPS Simulator

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

  3. Introduction (1/2) • 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 • 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 program’s memory and the data of the program’s 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 • .globlsym- 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 $a0…$a3 • 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 = 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 # sample example ‘swap two numbers’ .text .globl main 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

More Related