addi
Add immediate with overflow trap
Adds an immediate to the second register and stores the sum in the first, trapping if the signed result overflows.
Used in
- 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
- The bitmap display and keyboard registersMIPS assembly
- Variables in memory and constantsMIPS assembly
- Fill an array with a guarded counting loopMIPS assembly
Forms
addi , ,
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.
-
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,
$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. imm16- A signed 16-bit immediate,
-32768to32767. imm32- A 32-bit immediate,
-2147483648to4294967295. A pseudo-instruction that takes one uses the register$atas a temporary, so$atloses the value it held. 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.