# `add`

[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/add

**Add with overflow trap**

Category: Arithmetic

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 names](https://asm-editor.specy.app/learn/courses/mips/introduction/the-32-registers.md) (MIPS assembly), [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), [syscall in the Playground](https://asm-editor.specy.app/learn/courses/mips/talking-to-the-outside-world/syscall.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)

## Forms

- `add $t1, $t2, $t3`

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

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

## 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 size your value needs decides which real instructions the assembler uses. Open the row to see them for each size.

## Description

Raises an overflow exception if the true result does not fit in 32 bits. Use 'addu' when overflow should be silently ignored.

## Example

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