This document gives an overview of the more common instructions used in the SPIM simulator.
Overview
The SPIM simulator implements the full MIPS instruction set, as well as a large number
of pseudoinstructions that correspond to one or more equivalent MIPS instructions.
There are also a small number of system call commands used to interface with the
console window of the SPIM simulator. Finally, SPIM renames registers according to
commonly used conventions in order to facilitate the readability of programs.
Function
Rd = Rs + Rt (signed)
Rd = Rs + Rt (unsigned)
Rd = Rs + Imm (signed)
Rd = Rs - Rt (signed)
Rd = Rs - Rt (unsigned)
lo = Rs/Rt, hi = Rs mod Rt (integer division, signed)
lo = Rs/Rt, hi = Rs mod Rt (integer division, unsigned)
Rd = Rs/Rt (integer division, signed)
Rd = Rs/Rt (integer division, unsigned)
Rd = Rs mod Rt (signed)
Rd = Rs mod Rt (unsigned)
Rd = Rs * Rt (signed)
hi, lo = Rs * Rt (signed, hi = high 32 bits, lo = low 32 bits)
hi, lo = Rs * Rt (unsigned, hi = high 32 bits, lo = low 32
and
andi
neg
nor
not
or
ori
xor
xori
Rd = Rs Rt
Rd = Rs Imm
Rd = -(Rs)
Rd = (Rs + Rt)
Rd = (Rs)
Rd = Rs + Rt
Rd = Rs + Imm
Rd = Rs Rt
Rd = Rs Imm
Rd, Rs, Rt
Rd, Rs, Imm
Rd, Rs
Rd, Rs, Rt
Rd, Rs
Rd, Rs, Rt
Rd, Rs, Imm
Rd, Rs, Rt
Rd, Rs, Imm
sll
sllv
srl
srlv
Rd, Rt, Sa
Rd, Rs, Rt
Rd, Rs, Sa
Rd, Rs, Rt
move
mfhi
mflo
li
lui
Rd, Rs
Rd
Rd
Rd, Imm
Rt, Imm
Rd = Rs
Rd = hi
Rd = lo
Rd = Imm
Rt[31:16] = Imm, Rt[15:0] = 0
Rt, Address(Rs)
Rt, Address(Rs)
Rt, Address(Rs)
Rt, Address(Rs)
slt
slti
sltu
Rd, Rs, Rt
Rd, Rs, Imm
Rd, Rs, Rt
beq
beqz
bge
bgez
bgezal
bgt
bgtu
bgtz
ble
bleu
blez
bgezal
bltzal
blt
bltu
bltz
bne
bnez
Branch to Label if Rs == Rt
Branch to Label if Rs == 0
Branch to Label if Rs Rt (signed)
Branch to Label if Rs 0 (signed)
Branch to Label and Link if Rs Rt (signed)
Branch to Label if Rs > Rt (signed)
Branch to Label if Rs > Rt (unsigned)
Branch to Label if Rs > 0 (signed)
Branch to Label if Rs Rt (signed)
Branch to Label if Rs Rt (unsigned)
Branch to Label if Rs 0 (signed)
Branch to Label and Link if Rs 0 (signed)
Branch to Label and Link if Rs < 0 (signed)
Branch to Label if Rs < Rt (signed)
Branch to Label if Rs < Rt (unsigned)
Branch to Label if Rs < 0 (signed)
Branch to Label if Rs Rt
Branch to Label if Rs 0
Label
Label
Rs
Label
lb
sb
lw
sw
j
jal
jr
jalr
Registers
By convention, many MIPS registers have special purpose uses. To help clarify this,
SPIM defines aliases for each register that represent its purpose. The following table lists
these aliases and the commonly accepted uses for the registers.
Register
zero
at
v0
v1
a0
a1
a2
a3
t0
t1
t2
t3
t4
t5
t6
t7
s0
Number
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
s1
s2
s3
s4
s5
s6
s7
t8
t9
k0
k1
gp
sp
fp
ra
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Usage
Constant 0
Reserved for assembler
Used for return values from function calls.
Used to pass arguments to procedures and functions.
System Calls
In order to perform I/O with the console, SPIM provides a small library of system calls.
In general, system calls are set up by placing a system call in register $v0, and any
arguments in register $a0 and $a1. Returned values are placed in register $v0. See the
table and the example program below for usage.
Example Program
# This program takes input from the user and echoes it back
Service
Print_int
Print_float
Print_double
Print_string
Read_int
Read_float
Read_double
Read_string
Sbrk
exit
Arguments
$a0 = integer
$f12 = float
$f12 = double
$a0 = string
Result
.data
# Constant strings to be output to the terminal
promptInt:
.asciiz "Please input an integer: "
resultInt:
.asciiz "Next integer is: "
linefeed: .asciiz
"\n"
enterkey: .asciiz "Press any key to end program."
.text
main:
# prompt for an integer
li
$v0,4
la
$a0,promptInt
syscall
# t0 <-- t0 + 1