# `addi`

[MIPS Documentation](https://asm-editor.specy.app/documentation/mips.md) › [Instructions](https://asm-editor.specy.app/documentation/mips/instruction.md)

Web page: https://asm-editor.specy.app/documentation/mips/instruction/addi

**Add immediate with overflow trap**

Category: Arithmetic

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 set](https://asm-editor.specy.app/learn/courses/mips/introduction/the-mips-instruction-set.md) (MIPS assembly), [Loads, stores and immediates](https://asm-editor.specy.app/learn/courses/mips/introduction/loads-stores-and-immediates.md) (MIPS assembly), [Loops](https://asm-editor.specy.app/learn/courses/mips/think-in-assembly/loops.md) (MIPS assembly), [Arithmetic, logic and bits](https://asm-editor.specy.app/learn/courses/mips/think-in-assembly/arithmetic-logic-and-bits.md) (MIPS assembly), [Arrays and strings](https://asm-editor.specy.app/learn/courses/mips/think-in-assembly/arrays-and-strings.md) (MIPS assembly), [The stack and $sp](https://asm-editor.specy.app/learn/courses/mips/think-in-assembly/the-stack-and-sp.md) (MIPS assembly), [jal, jr, and the course calling convention](https://asm-editor.specy.app/learn/courses/mips/think-in-assembly/jal-jr-and-the-calling-convention.md) (MIPS assembly), [The bitmap display and keyboard registers](https://asm-editor.specy.app/learn/courses/mips/talking-to-the-outside-world/the-bitmap-display-and-the-keyboard.md) (MIPS assembly), [Variables in memory and constants](https://asm-editor.specy.app/learn/courses/mips/examples/variables-in-memory.md) (MIPS assembly), [Fill an array with a guarded counting loop](https://asm-editor.specy.app/learn/courses/mips/examples/counting-loop.md) (MIPS assembly)

## Forms

- `addi $t1, $t2, imm16`

## 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.

- `addi $t1, $t2, imm32` · Set $t1 to ($t2 plus 32-bit immediate)
  - `addi $t1,$t2,100000` → `lui $at, hi(imm32)`; `ori $at, $at, lo(imm32)`; `add $t1, $t2, $at`

- `addi $t1, $t2, %lo(label)` · Set $t1 to $t2 plus the lower 16 bits of label's address
  - `addi $t1,$t2,%lo(label)` → `addi $t1, $t2, lo(label)`

## 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`. A pseudo-instruction that takes one uses the register `$at` as a temporary, so `$at` loses the value it held.
- `label`: A named address in the program, such as the start of a loop or a variable in `.data`.

## Description

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

## Example

```mips
# 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.
```
