1 / 7

ECE 0142

ECE 0142. Recitation #5. SPIM Simulator. Official website: http://pages.cs.wisc.edu/~larus/spim.html Versions Unix, Linux, Mac: spim , xspim Windows: PCSpim. Register Pane. Memory address of instructions. Instructions. Correspondent line in source file. Program Pane.

elma
Télécharger la présentation

ECE 0142

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. ECE 0142 Recitation #5

  2. SPIM Simulator • Official website: • http://pages.cs.wisc.edu/~larus/spim.html • Versions • Unix, Linux, Mac: spim, xspim • Windows: PCSpim

  3. Register Pane Memory address of instructions Instructions Correspondent line in source file Program Pane Encoded instruction Memory & stack Program input/output Message Pane

  4. SPIM Basics • Must have a label “main” – entrance of your program • Data segment • Starts with “.data” directive • Memory locations, constants, string literals • Text segment • Your program

  5. System Calls • Simple I/O functions in your program • Example • print_int: print an integer on console • print_string: print a zero-ended string on console • read_int • ...... • How to use? • Load $v0 with service number (e.g. 1 for print_int) • Load arguments (if any) to $a0, $a1 or $f12 • syscall

  6. Example: Swap Words .data value1: .word 1111 value2: .word 2222 msg_v1: .asciiz "v1=" msg_v2: .asciiz "v2=" newline: .asciiz "\n" .text .globl main main: # Load value1, value2 into $s0, $s1 la $t0, value1 lw $s0, 0($t0) la $t1, value2 lw $s1, 0($t1) # swap $s0, $s1 move $s2, $s0 move $s0, $s1 move $s1, $s2 # Save $s0, $s1 back to value1, value2 sw $s0, 0($t0) sw $s1, 0($t1)

  7. Example (cont.) # print value1 li $v0, 4 la $a0, msg_v1 syscall li $v0, 1 la $t0, value1 lw $a0, 0($t0) syscall li $v0, 4 la $a0, newline syscall # print value2 li $v0, 4 la $a0, msg_v2 syscall li $v0, 1 la $t0, value2 lw $a0, 0($t0) syscall li $v0, 4 la $a0, newline syscall # exit li $v0, 10 syscall

More Related