andi
Bitwise AND immediate
Sets $t1 to $t2 AND an immediate, with the immediate zero-extended instead of sign-extended.
Used in
- Arithmetic, logic and bitsMIPS assembly
- The bitmap display and keyboard registersMIPS assembly
- Exceptions and coprocessor 0MIPS assembly
- Masks, shifts, popcount, and leading zeroesMIPS assembly
- Move a square with the keyboardMIPS assembly
- The snake gameMIPS assembly
- Flappy birdMIPS assembly
- Sampled soundMIPS assembly
Forms
andi , ,
Pseudo-instructions
The assembler turns these into one or more real instructions.
-
Set $t1 to ($t2 bitwise-AND 32-bit immediate)
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. uimm16- An unsigned 16-bit immediate,
0to65535. imm32- A 32-bit immediate,
-2147483648to4294967295. Pseudoinstruction expansion may overwrite$at, losing its previous value. imm- An immediate value: an unsigned 16-bit value (
0to65535) or a 32-bit value (-2147483648to4294967295). The assembler chooses a supported encoding for the value and other operands; a pseudoinstruction may expand into several instructions.
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.
# Keep only the low nibble. Inspect $t2: 5.
li $t0, 0x35
andi $t2, $t0, 0xF