The following page contains supplemental information pertaining the MIPS Instruction Set Architecture for the use of the SPIM simulator.
Exception and Trap Instructions
| Register Name | Number | Usage |
|---|---|---|
| zero | 0 | Constant 0 |
| at | 1 | Reserved for assembler |
| v0 | 2 | Expression evaluation and results of a function |
| v1 | 3 | Expression evaluation and results of a function |
| a0 | 4 | Argument 1 |
| a1 | 5 | Argument 2 |
| a2 | 6 | Argument 3 |
| a3 | 7 | Argument 4 |
| t0 | 8 | Temporary (not preserved across call) |
| t1 | 9 | Temporary (not preserved across call) |
| t2 | 10 | Temporary (not preserved across call) |
| t3 | 11 | Temporary (not preserved across call) |
| t4 | 12 | Temporary (not preserved across call) |
| t5 | 13 | Temporary (not preserved across call) |
| t6 | 14 | Temporary (not preserved across call) |
| t7 | 15 | Temporary (not preserved across call) |
| s0 | 16 | Saved temporary (preserved across call) |
| s1 | 17 | Saved temporary (preserved across call) |
| s2 | 18 | Saved temporary (preserved across call) |
| s3 | 19 | Saved temporary (preserved across call) |
| s4 | 20 | Saved temporary (preserved across call) |
| s5 | 21 | Saved temporary (preserved across call) |
| s6 | 22 | Saved temporary (preserved across call) |
| s7 | 23 | Saved temporary (preserved across call) |
| t8 | 24 | Temporary (not preserved across call) |
| t9 | 25 | Temporary (not preserved across call) |
| k0 | 26 | Reserved for OS kernel |
| k1 | 27 | Reserved for OS kernel |
| gp | 28 | Pointer to global area |
| sp | 29 | Stack pointer |
| fp | 30 | Frame pointer |
| ra | 31 | Return address (used by function call) |
| Service | System Call Code | Arguments | Result |
|---|---|---|---|
| print_int | 1
| $a0 = integer | |
| print_float | 2
| $f12 = float | |
| print_double | 3
| $f12 = double | |
| print_string | 4
| $a0 = string | |
| read_int | 5
| integer (in $v0) | |
| read_float | 6
| float (in $f0) | |
| read_double | 7
| double (in $f0) | |
| read_string | 8
| $a0 = buffer, $a1 = length | |
| sbrk | 9
| $a0 = amount | address (in $v0) |
| exit | 10
|
.align n
Align the next datum on a 2^n byte boundary. For example, .align
2 aligns the next value on a word boundary. .align 0 turns off
automatic alignment of .half, .word, .float, and .double directives
until the next .data or .kdata directive.
.ascii str
Store the string in memory, but do not null-terminate it.
.asciiz str
Store the string in memory and null-terminate it.
.byte b1, ..., bn
Store the n values in successive bytes of memory.
.data
The following data items should be stored in the data segment. If the optional argument addr is present, the items are stored beginning at address addr.
.double d1, ..., dn
Store the n floating point double precision numbers in successive memory locations.
.extern sym size
Declare that the datum stored at sym is size bytes large and is a global symbol. This directive enables the assembler to store the datum in a portion of the data segment that is efficiently accessed via register $gp.
.float f1, ..., fn
Store the n floating point single precision numbers in successive memory locations.
.globl sym
Declare that symbol sym is global and can be referenced from other files.
.half h1, ..., hn
Store the n 16-bit quantities in successive memory halfwords.
.kdata
The following data items should be stored in the kernel data segment. If the optional argument addr is present, the items are stored beginning at address addr.
.ktext
The next items are put in the kernel text segment. In SPIM, these items may only be instructions or words (see the .word directive below). If the optional argument addr is present, the items are stored beginning at address addr.
.space n
Allocate n bytes of space in the current segment (which must be the data segment in SPIM).
.text
The next items are put in the user text segment. In SPIM, these items may only be instructions or words (see the .word directive below). If the optional argument addr is present, the items are stored beginning at address addr.
.word w1, ..., wn
Store the n 32-bit quantities in successive memory words.
rfe - Return From Exception
Restore the Status register.
syscall - System Call
Register v0 contains the number of the system call provided by SPIM. (see System Services above)
break n - Break
Cause exception n. Exception 1 is reserved for the debugger.
nop - No operation
Do nothing.