MIPS Dictionary
Your friendly guide to all MIPS assembly keywords! Explore and learn.
add
ArithmeticSigned add: rd = rs + rt; traps on overflow.
add $t0, $t1, $t2 # $t0 = $t1 + $t2 (overflow traps)Use addu if you donβt want overflow exceptions.
addu
ArithmeticUnsigned add: rd = rs + rt; no overflow trap.
addu $t0, $t1, $t2 # $t0 = $t1 + $t2 (no trap)βUnsignedβ here means βno trap,β not βmodular only for unsigned data.β
sub
ArithmeticSigned subtract: rd = rs - rt; traps on overflow.
sub $t0, $t1, $t2 # $t0 = $t1 - $t2 (overflow traps)sub is add with twoβs-complement negate of rt under the hood.
subu
ArithmeticUnsigned subtract: rd = rs - rt; no overflow trap.
subu $t0, $t1, $t2 # $t0 = $t1 - $t2 (no trap)Matches adduβs βno trapβ behavior.
addi
ArithmeticSigned add immediate: rt = rs + imm; traps on overflow.
addi $t0, $t1, 5 # $t0 = $t1 + 5 (overflow traps)Use addiu to avoid overflow traps.
addiu
ArithmeticAdd immediate (no trap): rt = rs + imm.
addiu $t0, $t1, -1 # $t0 = $t1 - 1 (no trap)Despite the βuβ, itβs commonly used for signed offsets safely.
slt
ComparisonSet on less than (signed): rd = (rs < rt) ? 1 : 0.
slt $t0, $t1, $t2 # $t0 = 1 if $t1 < $t2 (signed)Backbone for implementing comparisons in MIPS.
sltu
ComparisonSet on less than (unsigned): rd = (rs < rt) ? 1 : 0.
sltu $t0, $t1, $t2 # unsigned comparisonUse for pointers and size_t-like logic.
slti
ComparisonSet on less than immediate (signed).
slti $t0, $t1, 10 # $t0 = 1 if $t1 < 10 (signed)Pairs with branch-on-true to emulate <=, >=, etc.
sltiu
ComparisonSet on less than immediate (unsigned).
sltiu $t0, $t1, 10 # unsigned compare with 10Great for bounds checks on indices.
and
LogicBitwise AND: rd = rs & rt.
and $t0, $t1, $t2 # mask bitsClassic for clearing bits with a mask.
or
LogicBitwise OR: rd = rs | rt.
or $t0, $t1, $t2 # set bitsCombine masks to assemble values.
xor
LogicBitwise XOR: rd = rs ^ rt.
xor $t0, $t1, $t2 # toggle bitsSwap trick uses XOR, but be careful with aliasing.
nor
LogicBitwise NOR: rd = ~(rs | rt).
nor $t0, $t1, $t2 # bitwise NOT of ORUsed to synthesize NOT: nor $t0, $t1, $zero.
andi
LogicBitwise AND immediate: rt = rs & imm (zero-extended).
andi $t0, $t1, 0xFF # keep low byteImmediate is zero-extended, not sign-extended.
ori
LogicBitwise OR immediate: rt = rs | imm (zero-extended).
ori $t0, $t1, 0x20 # set bit 5Common with LUI to build 32-bit constants.
xori
LogicBitwise XOR immediate: rt = rs ^ imm (zero-extended).
xori $t0, $t1, 1 # toggle LSBXOR with same value twice gets you back the original.
lui
Data MovementLoad upper immediate: rt = imm << 16.
lui $t0, 0x1234 # $t0 = 0x12340000Usually followed by ORI to form a full 32-bit constant.
sll
ShiftLogical left shift: rd = rt << shamt.
sll $t0, $t1, 2 # multiply by 4nop is sll $zero, $zero, 0.
srl
ShiftLogical right shift: rd = rt >>> shamt (zeros in).
srl $t0, $t1, 1 # divide by 2 (unsigned)Use sra for signed arithmetic right shift.
sra
ShiftArithmetic right shift: rd = rt >> shamt (sign-ext).
sra $t0, $t1, 1 # divide by 2 (signed)Maintains sign for negative numbers.
sllv
ShiftVariable logical left shift: rd = rt << rs[4:0].
sllv $t0, $t1, $t2 # shift by $t2 amountShift amount comes from a register instead of shamt.
srlv
ShiftVariable logical right shift: rd = rt >>> rs[4:0].
srlv $t0, $t1, $t2 # variable shift right (zeros)Great for bitfield extraction.
srav
ShiftVariable arithmetic right shift: rd = rt >> rs[4:0].
srav $t0, $t1, $t2 # variable signed shift rightPreserves sign across variable shifts.
mult
Multiply/DivideSigned multiply: HI|LO = rs * rt (low 32 in LO, high 32 in HI).
mult $t1, $t2
mflo $t0 # $t0 = low 32 bitsUse mfhi/mflo to read the results; operation is 64-bit internally.
multu
Multiply/DivideUnsigned multiply: HI|LO = rs * rt (unsigned).
multu $t1, $t2
mfhi $t3 # $t3 = high 32 bitsUnsigned variant for size_t-like math.
div
Multiply/DivideSigned divide: LO = rs / rt, HI = rs % rt.
div $t1, $t2
mflo $t0 # quotient
mfhi $t3 # remainderDivision by zero is undefinedβdonβt do it.
divu
Multiply/DivideUnsigned divide: LO = rs / rt, HI = rs % rt (unsigned).
divu $t1, $t2
mflo $t0
mfhi $t3Match your data types when choosing div vs divu.
mfhi
HI/LOMove From HI: rd = HI.
mfhi $t0 # get remainder or high productPairs with mult*/div* to harvest high 32 bits.
mflo
HI/LOMove From LO: rd = LO.
mflo $t0 # get quotient or low productYou typically read LO first after mult/div.
mthi
HI/LOMove To HI: HI = rs.
mthi $t0 # set HI explicitlyLess common; can seed HI/LO for custom arithmetic.
mtlo
HI/LOMove To LO: LO = rs.
mtlo $t0 # set LO explicitlyCaution: overwrites results from mult/div.
j
Control FlowJump to absolute target in same 256 MB region.
j main # PC = targetAssembler fills the 26-bit target field.
jal
Control FlowJump and link: $ra = return addr; jump to target.
jal func # call func; $ra = next PCYour automatic βbookmarkβ to get home from a call.
jr
Control FlowJump register: PC = rs (return or indirect jump).
jr $ra # return to callerCommonly used to return from subroutines.
jalr
Control FlowJump and link register: rd=$ra (default), PC=rs.
jalr $t0 # call via pointer in $t0Useful for function pointers / virtual dispatch.
beq
Control FlowBranch if equal: if (rs == rt) PC += offset.
beq $t0, $t1, loop # if equal, branchOffset is word-aligned relative to the delay slot.
bne
Control FlowBranch if not equal: if (rs != rt) PC += offset.
bne $t0, $t1, loop # if not equal, branchClassic for while/for loops.
blez
Control FlowBranch if less than or equal to zero (signed).
blez $t0, done # if $t0 <= 0One-source-operand branch; compares to zero.
bgtz
Control FlowBranch if greater than zero (signed).
bgtz $t0, loop # if $t0 > 0Complements blez/bltz/bgez.
bltz
Control FlowBranch if less than zero (signed).
bltz $t0, neg # if $t0 < 0Implemented via the REGIMM encoding group.
bgez
Control FlowBranch if greater than or equal to zero (signed).
bgez $t0, nonneg # if $t0 >= 0Pairs with bltz for signed zero tests.
bltzal
Control FlowBranch if < 0 and link (like call-if-negative).
bltzal $t0, handler # if negative, $ra=ret; jumpUseful for conditional calls / trampolines.
bgezal
Control FlowBranch if >= 0 and link.
bgezal $t0, handler # if nonnegative, call handlerDual of bltzal for nonnegative case.
lb
MemoryLoad byte (signed): rt = sign_extend(M8[rs + imm]).
lb $t0, 0($t1) # signed 8-bit loadSign-extends bit 7 into upper bits.
lbu
MemoryLoad byte (unsigned): rt = zero_extend(M8[rs + imm]).
lbu $t0, 0($t1) # unsigned 8-bitGreat for ASCII/bytes processing.
lh
MemoryLoad halfword (signed): rt = sign_extend(M16[rs + imm]).
lh $t0, 0($t1) # signed 16-bit load (aligned)Requires halfword alignment on MIPS I.
lhu
MemoryLoad halfword (unsigned): rt = zero_extend(M16[rs + imm]).
lhu $t0, 0($t1) # unsigned 16-bit loadKeeps upper bits zero.
lw
MemoryLoad word: rt = M32[rs + imm].
lw $t0, 4($sp) # load 32-bit wordRequires word alignment on MIPS I.
sb
MemoryStore byte: M8[rs + imm] = rt[7:0].
sb $t0, 0($t1) # store low byteUpper 24 bits of rt are ignored.
sh
MemoryStore halfword: M16[rs + imm] = rt[15:0].
sh $t0, 2($t1) # store 16 bits (aligned)Requires halfword alignment.
sw
MemoryStore word: M32[rs + imm] = rt.
sw $t0, 8($sp) # store 32-bit wordWorkhorse for saving registers on stack.
lui (as const-build)
Data MovementFirst half of building 32-bit constants (upper 16 bits).
lui $t0, 0x1234
ori $t0, $t0, 0x5678MIPS lacks a single βload 32-bit immediateβ real instruction.
syscall
SystemEnter operating system / simulator service routine.
li $v0, 1
li $a0, 42
syscall # print_int in SPIM/MARSMeaning depends on $v0 in simulators like MARS/QtSPIM.
break
SystemBreakpoint exception for debuggers.
break 0 # trigger BREAK exceptionHandy for trapping illegal states while debugging.
move
PseudoinstructionCopy register (pseudo): rd = rs.
move $t0, $t1 # expands to addu $t0,$t1,$zeroJust OR/ADDU with $zero under the hood.
li
PseudoinstructionLoad immediate (pseudo): rt = imm (32-bit).
li $t0, 0x12345678 # expands to LUI/ORI pairShort immediates may expand to a single addiu/ori.
la
PseudoinstructionLoad address (pseudo): rt = address(label).
la $t0, array # builds absolute addressAssembles using LUI/ORI (and possibly relocation).
neg
PseudoinstructionNegate (pseudo): rd = -rs.
neg $t0, $t1 # expands to subu $t0,$zero,$t1Also exists as βneguβ pseudo for no-trap form.
not
PseudoinstructionBitwise NOT (pseudo): rd = ~rs.
not $t0, $t1 # expands to nor $t0,$t1,$zeroUses NOR trick to invert bits.
nop
PseudoinstructionNo operation (pseudo): does nothing.
nop # sll $zero,$zero,0Often used to fill delay slots in older pipelines.
b
PseudoinstructionUnconditional branch (pseudo).
b loop # expands to beq $zero,$zero,loopNice for simple gotos/loops.
bal
PseudoinstructionBranch and link (pseudo): like jal with PC-relative target.
bal func # expands via bgezal $zero, func (tool-dependent)Assembler tricks vary; effect is set $ra and branch.
beqz
PseudoinstructionBranch if equal to zero (pseudo).
beqz $t0, done # beq $t0,$zero,doneSaves you a $zero in the mnemonic.
bnez
PseudoinstructionBranch if not equal to zero (pseudo).
bnez $t0, loop # bne $t0,$zero,loopCommon in while loops.
ble
PseudoinstructionBranch if β€ (pseudo, signed).
ble $t0, $t1, L # expands via slt/bne patternsAssembler synthesizes using slt/beq/bne sequences.
bge
PseudoinstructionBranch if β₯ (pseudo, signed).
bge $t0, $t1, L # expands via slt/bne patternsNo native βbgeβ in MIPS I.
blt
PseudoinstructionBranch if < (pseudo, signed).
blt $t0, $t1, L # expands via slt/bneAssembled with slt/beq combos.
bgt
PseudoinstructionBranch if > (pseudo, signed).
bgt $t0, $t1, L # expands via slt/bneAssembler sugar only.
seq
PseudoinstructionSet if equal (pseudo): rd = (rs == rt).
seq $t0, $t1, $t2 # expands via xor/sltiu/xoriA convenient booleanizer in MARS/QtSPIM.
sne
PseudoinstructionSet if not equal (pseudo): rd = (rs != rt).
sne $t0, $t1, $t2 # expands via seq/xoriPairs with seq to build conditionals.
sle
PseudoinstructionSet if β€ (pseudo, signed).
sle $t0, $t1, $t2 # pseudo via slt/seq/orNot a real opcode; assembler composes it.
sge
PseudoinstructionSet if β₯ (pseudo, signed).
sge $t0, $t1, $t2 # pseudo via slt/xoriAssembler sugar for comparisons.
rol
PseudoinstructionRotate left (pseudo).
rol $t0, $t1, 8 # pseudo via sll/srl/orNo real rotate in MIPS Iβbuilt from shifts.
ror
PseudoinstructionRotate right (pseudo).
ror $t0, $t1, 8 # pseudo via srl/sll/orAssembler expands with opposite shifts and OR.