# `andi`

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

**Bitwise AND immediate**

Category: Logic

Sets the first register to the bitwise AND of the second and an immediate, with the immediate zero-extended instead of sign-extended.

Used in: [Arithmetic, logic and bits](https://asm-editor.specy.app/learn/courses/mips/think-in-assembly/arithmetic-logic-and-bits.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), [Exceptions and coprocessor 0](https://asm-editor.specy.app/learn/courses/mips/talking-to-the-outside-world/exceptions-and-coprocessor-0.md) (MIPS assembly), [Masks, shifts, popcount, and leading zeroes](https://asm-editor.specy.app/learn/courses/mips/examples/bit-tricks.md) (MIPS assembly), [Move a square with the keyboard](https://asm-editor.specy.app/learn/courses/mips/examples/keyboard-control.md) (MIPS assembly), [The snake game](https://asm-editor.specy.app/learn/courses/mips/examples/snake.md) (MIPS assembly), [Flappy ASM](https://asm-editor.specy.app/learn/courses/mips/examples/flappy-asm.md) (MIPS assembly), [Sampled sound](https://asm-editor.specy.app/learn/courses/mips/examples/sampled-sound.md) (MIPS assembly)

## Forms

- `andi $t1, $t2, uimm16`

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

- `andi $t1, $t2, imm32` · Set $t1 to ($t2 bitwise-AND 32-bit immediate)
  - `andi $t1,$t2,100000` → `lui $at, hi(imm32)`; `ori $at, $at, lo(imm32)`; `and $t1, $t2, $at`

- `andi $t1, imm`
  - `andi $t1,100`: Set $t1 to ($t1 bitwise-AND 16-bit unsigned immediate) → `andi $t1, $t1, imm`
  - `andi $t1,100000`: Set $t1 to ($t1 bitwise-AND 32-bit immediate) → `lui $at, hi(imm)`; `ori $at, $at, lo(imm)`; `and $t1, $t1, $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`.
- `uimm16`: An unsigned 16-bit immediate, `0` to `65535`.
- `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.
- `imm`: An immediate value: an unsigned 16-bit value (`0` to `65535`) 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

The 16-bit immediate is zero-extended (upper 16 bits become 0, not sign-extended) before the AND. Commonly used to mask off the lower 16 bits of a register or to test individual bits.

## Example

```mips
# Keep only the low nibble. Inspect $t2: 5.
li $t0, 0x35
andi $t2, $t0, 0xF
```
