MIPS Instructions for the Tiger Compiler
Here is a collection of MIPS Instructions that should suffice
for implementing the Tiger intermediate codes. Most of these instructions
are pseudo-ops that are expanded by the MIPS assembler (and SPIM) into
appropriate machine instructions.
If you are interested in some fancier instructions, or want to optimize your
code at a more detailed level, please refer to the MIPS instruction
reference in the SPIM manual (Section 2).
Notation:
Source registers or values are designated by the prefix Src,
while destination registers are designated by the prefix Dest.
The modifiers are
Gpr | General purpose register
|
Imm | Immediate value or constant, 32 bit signed
|
Imm2 | Immediate value or constant, power of 2
|
Imm16 | Immediate value or constant, 16 bit signed
|
Label | Label in code (.text) or data (.data) section
|
Thus "Src{Gpr | Imm}" indicates a source value that can be the
contents of a general purpose register ("Gpr") or a constant
"Imm". In our case, the destination (e.g. of a load, move,
or arithmetic operation) is always going to be a register. Sources
of the form "Imm(Gpr)" designate an address offset by Imm from the
contents of Gpr (i.e. Gpr + Imm).
1. Arithmetic Instructions
ADD -- Addition
Syntax: | add DestGpr, Src1Gpr, Src2{Gpr | Imm}
|
Description: | Dest = Src1 + Src2
|
SUB -- Substract
Syntax: | sub DestGpr, Src1Gpr, Src2{Gpr | Imm}
|
Description: | Dest = Src1 - Src2
|
MULT -- Multiplication
Syntax: | mult DestGpr, Src1Gpr, Src2{Gpr | Imm}
|
Description: | Dest = Src1 * Src2
|
DIV -- Division
Syntax: | div DestGpr, Src1Gpr, Src2{Gpr | Imm}
|
Description: | Dest = Src1 / Src2
|
2. Logical Instructions
AND-- Logical AND
Syntax: | and DestGpr, Src1Gpr, Src2{Gpr | Imm}
|
Description: | Dest = Src1 AND Src2
|
OR -- Logical OR
Syntax: | or DestGpr, Src1Gpr, Src2{Gpr | Imm}
|
Description: | Dest = Src1 OR Src2
|
XOR -- Bitwise Exclusive OR
Syntax: | xor DestGpr, Src1Gpr, Src2{Gpr | Imm}
|
Description: | Dest = Src1 XOR Src2
|
3. Shift Instructions
SLL -- Shift Left Logical
Syntax: | sll DestGpr, Src1Gpr, Src2{Gpr | Imm}
|
Description: | Dest = Src1 << Scr2
|
SRL -- Shift Right Logical
Syntax: | srl DestGpr, Src1Gpr, Src2{Gpr | Imm}
|
Description: | Dest = Src1 >> Src2 (zero fill)
|
SRA -- Shift Right Arithmetic
Syntax: | sra DestGpr, Src1Gpr, Src2{Gpr | Imm}
|
Description: | Dest = Src1 >> Src2 (sign bit fill)
|
4. Branch Instructions
BEQ -- Branch on Equal
Syntax: | beq Src1Gpr, Src2{Gpr | Imm}, Label
|
Description: | Branch if Src1 = Src2
|
BNE -- Branch on Not equal
Syntax: | bne Src1Gpr, Src2{Gpr | Imm}, Label
|
Description: | Branches if Src1 != Src2
|
BGT -- Branch on Greater Than
Syntax: | bgt Src1Gpr, Src2{Gpr | Imm}, Label
|
Description: | Branches if Src1 > Src2
|
BGTU -- Branch on Greater Than (Unsigned)
Syntax: | bgtu Src1Gpr, Src2{Gpr | Imm}, Label
|
Description: | Branches if Src1 > Src2 (unsigned)
|
BGE -- Branch on Greater Than or Equal
Syntax: | bge Src1Gpr, Src2{Gpr | Imm}, Label
|
Description: | Branches if Src1 >= Src2
|
BGEU -- Branch on Greater Than or Equal (Unsigned)
Syntax: | bgeu Src1Gpr, Src2{Gpr | Imm}, Label
|
Description: | Branches if Src1 >= Src2 (unsigned)
|
BLT -- Branch on Less Than
Syntax: | blt Src1Gpr, Src2{Gpr | Imm}, Label
|
Description: | Branches if Src1 < Src2
|
BLTU -- Branch on Less Than (Unsigned)
Syntax: | bltu Src1Gpr, Src2{Gpr | Imm}, Label
|
Description: | Branches if Src1 < Src2 (unsigned)
|
BLE -- Branch on Less Than or Equal
Syntax: | ble Src1Gpr, Src2{Gpr | Imm}, Label
|
Description: | Branches if Src1 <= Src2
|
BLEU -- Branch on Less Than or Equal (Unsigned)
Syntax: | bleu Src1Gpr, Src2{Gpr | Imm}, Label
|
Description: | Branches if Src1 <= Src2 (unsigned)
|
5. Jump Instructions
J -- Jump
Syntax: | j Src{Gpr | Imm2 | Imm16 | Label}
|
Description: | Unconditionally jump to Src
|
JAL -- Jump and Link
Syntax: | jal Src{Gpr | Imm2 | Imm16 | Label}
|
Description: | Unconditionally jump to Src. Save the
addressof the next instruction in register $ra. Used for function calls.
|
6. Load/Store Instructions
LW -- Load Word
Syntax: | lw DestGpr, Src{Imm | Imm(Gpr) | Label}
|
Description: | Load word at address Src into Dest
|
LI -- Load Immediate
Syntax: | li DestGpr, SrcImm
|
Description: | Load constant Src into Dest
|
LA -- Load Address
Syntax: | la DestGpr, Src{Imm | Imm(Gpr) | Label}
|
Description: | Load address Src into Dest
|
SW -- Store Word
Syntax: | sw SrcGpr, Dest{Imm | Imm(Gpr) | Label}
|
Description: | Store word in Src at address Dest
|
7. Constant and Data Moving
MOVE -- Move Register
Syntax: | move DestGpr, SrcGpr
|
Description: | Move contents of register Src to Dest
|
MIPS Register Convention
$zero | constant zero
|
$at | compiler temporary register
|
$v0 ~ $v1 | used to return values
|
$a0 ~ $a3 | used to pass parameters
|
$t0 ~ $t7 | volatile registers (caller saves)
|
$s0 ~ $s6 | non-volatile registers (callee saves)
|
$t8 ~ $t9 | more volatile registers
|
$gp | global pointer
|
$sp | stack pointer
|
$fp | frame pointer
|
$ra | used to store return address
|
Hi, Lo | used to store results of Multiplication and Division
|