CS161: MIPS Instruction Reference

MIPS Instruction Reference

Arithmetic and Logical Instructions

InstructionOpcode/FunctionSyntaxOperation
add 100000f $d, $s, $t $d = $s + $t
addu 100001f $d, $s, $t $d = $s + $t
addi 001000f $d, $s, i$d = $s + SE(i)
addiu 001001f $d, $s, i$d = $s + SE(i)
and 100100f $d, $s, $t $d = $s & $t
andi 001100f $d, $s, i$t = $s & ZE(i)
div 011010f $s, $t lo = $s / $t; hi = $s % $t
divu 011011f $s, $t lo = $s / $t; hi = $s % $t
mult 011000f $s, $t hi:lo = $s * $t
multu 011001f $s, $t hi:lo = $s * $t
nor 100111f $d, $s, $t $d = ~($s | $t)
or 100101f $d, $s, $t $d = $s | $t
ori 001101f $d, $s, i$t = $s | ZE(i)
sll 000000f $d, $t, a $d = $t << a
sllv 000100f $d, $t, $s $d = $t << $s
sra 000011f $d, $t, a $d = $t >> a
srav 000111f $d, $t, $s $d = $t >> $s
srl 000010f $d, $t, a $d = $t >>> a
srlv 000110f $d, $t, $s $d = $t >>> $s
sub 100010f $d, $s, $t $d = $s - $t
subu 100011f $d, $s, $t $d = $s - $t
xor 100110f $d, $s, $t $d = $s ^ $t
xori 001110f $d, $s, i$d = $s ^ ZE(i)

Constant-Manipulating Instructions

InstructionOpcode/FunctionSyntaxOperation
lhi 011001o $t, immed32HH ($t) = i
llo 011000o $t, immed32LH ($t) = i

Comparison Instructions

InstructionOpcode/FunctionSyntaxOperation
slt 101010f $d, $s, $t $d = ($s < $t)
sltu 101001f $d, $s, $t $d = ($s < $t)
slti 001010f $d, $s, i$t = ($s < SE(i))
sltiu 001001f $d, $s, i$t = ($s < SE(i))

Branch Instructions

InstructionOpcode/FunctionSyntaxOperation
beq 000100o $s, $t, label if ($s == $t) pc += i << 2
bgtz 000111o $s, label if ($s > 0) pc += i << 2
blez 000110o $s, label if ($s <= 0) pc += i << 2
bne 000101o $s, $t, label if ($s != $t) pc += i << 2

Jump Instructions

InstructionOpcode/FunctionSyntaxOperation
j 000010o label pc += i << 2
jal 000011o label $31 = pc; pc += i << 2
jalr 001001o labelR $31 = pc; pc = $s
jr 001000o labelR pc = $s

Load Instructions

InstructionOpcode/FunctionSyntaxOperation
lb 100000o $t, i ($s)$t = SE (MEM [$s + i]:1)
lbu 100100o $t, i ($s)$t = ZE (MEM [$s + i]:1)
lh 100001o $t, i ($s)$t = SE (MEM [$s + i]:2)
lhu 100101o $t, i ($s)$t = ZE (MEM [$s + i]:2)
lw 100011o $t, i ($s)$t = MEM [$s + i]:4

Store Instructions

InstructionOpcode/FunctionSyntaxOperation
sb 101000o $t, i ($s)MEM [$s + i]:1 = LB ($t)
sh 101001o $t, i ($s)MEM [$s + i]:2 = LH ($t)
sw 101011o $t, i ($s)MEM [$s + i]:4 = $t

Data Movement Instructions

InstructionOpcode/FunctionSyntaxOperation
mfhi 010000f $d $d = hi
mflo 010010f $d $d = lo
mthi 010001f $s hi = $s
mtlo 010011f $s lo = $s

Exception and Interrupt Instructions

InstructionOpcode/FunctionSyntaxOperation
trap 011010o iDependent on OS; different values for immed26 specify different operations.