add
Add with overflow trap
Adds the second and third registers, or the second register and an immediate, and stores the sum in the first, trapping if the signed result overflows.
Used in
- The 32 registers and their namesMIPS assembly
- The MIPS instruction setMIPS assembly
- Loads, stores and immediatesMIPS assembly
- LoopsMIPS assembly
- Arithmetic, logic and bitsMIPS assembly
- Arrays and stringsMIPS assembly
- The stack and $spMIPS assembly
- jal, jr, and the course calling conventionMIPS assembly
- syscall in the PlaygroundMIPS assembly
- The bitmap display and keyboard registersMIPS assembly
Forms
add , ,
Pseudo-instructions
The processor does not have these forms. The assembler replaces each of them with one or more real instructions. Open a row to see them.
Operands
$t1- Any general-purpose register,
$0to$31, using its numeric or named spelling, such as$8or$t0($zerois$0;$rais$31). $t2- A general-purpose register. It may be the same register as
$t1. $t3- A general-purpose register. It may be the same register as
$t1. imm- An immediate value: a signed 16-bit value (
-32768to32767) or a 32-bit value (-2147483648to4294967295). The size your value needs decides which real instructions the assembler uses. Open the row to see them for each size.
Raises an overflow exception if the true result does not fit in 32 bits. Use 'addu' when overflow should be silently ignored.
# Add two initialized values. Inspect $t2: it should contain 12.
li $t0, 7
li $t1, 5
add $t2, $t0, $t1
# Optional overflow variation: uncomment these lines before the normal completion point.
# li $t0, 0x7FFFFFFF
# li $t1, 1
# add $t2, $t0, $t1
# Expected: signed integer overflow stops execution.