add

Add with overflow trap

Adds $t2 and $t3, or $t2 and an immediate, into $t1 and traps if the signed result overflows.

Forms

  • add , ,

Pseudo-instructions

The assembler turns these into one or more real instructions.

Operands

$t1
Any general-purpose register, $0 to $31, using its numeric or named spelling, such as $8 or $t0 ($zero is $0; $ra is $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 (-32768 to 32767) or a 32-bit value (-2147483648 to 4294967295). The assembler chooses a supported encoding for the value and other operands; a pseudoinstruction may expand into several instructions.

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.