Presentation is loading. Please wait.

Presentation is loading. Please wait.

ECE 0142 Recitation #5.

Similar presentations


Presentation on theme: "ECE 0142 Recitation #5."— Presentation transcript:

1 ECE 0142 Recitation #5

2 SPIM Simulator Official website: Versions
Versions Unix, Linux, Mac: spim, xspim Windows: PCSpim

3 Register Pane Program Pane Memory & stack Program input/output
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 How to use?
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) la $a0, newline # print value2 li $v0, 4 la $a0, msg_v2 syscall li $v0, 1 la $t0, value2 lw $a0, 0($t0) la $a0, newline # exit li $v0, 10


Download ppt "ECE 0142 Recitation #5."

Similar presentations


Ads by Google