addi

Add immediate with overflow trap

Adds an immediate to $t2 and puts the sum in $t1, trapping if the signed result overflows.

Forms

  • addi , ,

Pseudo-instructions

The assembler turns these into one or more real instructions.

  • Set $t1 to ($t2 plus 32-bit immediate)

  • Set $t1 to $t2 plus the lower 16 bits of label's address

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.
imm16
A signed 16-bit immediate, -32768 to 32767.
imm32
A 32-bit immediate, -2147483648 to 4294967295. Pseudoinstruction expansion may overwrite $at, losing its previous value.
label
A named address in the program, such as the start of a loop or a variable in .data.

Raises an overflow exception if the result overflows. Use 'addiu' to suppress the overflow check.

# Add immediate 3 to 7. Inspect $t2: 10.
li $t0, 7
addi $t2, $t0, 3
# Optional overflow variation: uncomment these lines before the normal completion point.
# li $t0, 0x7FFFFFFF
# li $t1, 1
# addi $t2, $t0, 1
# Expected: signed integer overflow stops execution.