MIPS Instruction Reference: ADD - Add (With Overflow)
MIPS Instruction Reference: ADD - Add (With Overflow)
This is a description of the MIPS instruction set, their meanings, syntax, semantics, and bit
encodings. The syntax given for each instruction refers to the assembly language syntax supported
by the MIPS assembler. Hyphens in the encoding indicate "don't care" bits which are not considered
when an instruction is being decoded.
General purpose registers (GPRs) are indicated with a dollar sign ($). The words SWORD and
UWORD refer to 32-bit signed and 32-bit unsigned data types, respectively.
The manner in which the processor executes an instruction and advances its program counters is as
follows:
1. execute the instruction at PC
2. copy nPC to PC
3. add 4 or the branch offset to nPC
This behavior is indicated in the instruction specifications below. For brevity, the function
advance_pc (int) is used in many of the instruction descriptions. This function is defined as follows:
PC = nPC;
nPC += offset;
}
Note: ALL arithmetic immediate values are sign-extended. After that, they are handled as signed or
unsigned 32 bit numbers, depending upon the instruction. The only difference between signed and
unsigned instructions is that signed instructions can generate an overflow exception and unsigned
instructions can not.
The instruction descriptions are given below:
Operation: if $s >= 0 $31 = PC + 8 (or nPC + 4); advance_pc (offset << 2)); else advance_pc (4);
Operation: if $s < 0 $31 = PC + 8 (or nPC + 4); advance_pc (offset << 2)); else advance_pc (4);
DIV -- Divide
Description: Divides $s by $t and stores the quotient in $LO and the remainder in $HI
J -- Jump
Description: Jumps to the calculated address
Syntax: j target
Operation: $31 = PC + 8 (or nPC + 4); PC = nPC; nPC = (PC & 0xf0000000) | (target << 2);
JR -- Jump register
Description: Jump to the address contained in register $s
Syntax: jr $s
LB -- Load byte
Description: A byte is loaded into a register from the specified address.
LW -- Load word
Description: A word is loaded into a register from the specified address.
Syntax: mfhi $d
Syntax: mflo $d
MULT -- Multiply
Description: Multiplies $s by $t and stores the result in $LO.
NOOP -- no operation
Description: Performs no operation.
Syntax: noop
Note: The encoding for a NOOP represents the instruction SLL $0, $0, 0 which has no side effects.
In fact, nearly every instruction that has $0 as its destination register will have no side effect and
can thus be considered a NOOP instruction.
OR -- Bitwise or
Description: Bitwise logical ors two registers and stores the result in a register
SB -- Store byte
Description: The least significant byte of $t is stored at the specified address.
SUB -- Subtract
Description: Subtracts two registers and stores the result in a register
Syntax: syscall
The syscall instruction is described in more detail on the System Calls page.