# `divu`

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

**Divide unsigned**

Category: Arithmetic

Divides unsigned integers: with three operands the quotient goes to the first register, with two it goes to LO and the remainder to HI.

Used in: [Flappy ASM](https://asm-editor.specy.app/learn/courses/mips/examples/flappy-asm.md) (MIPS assembly)

## Forms

- `divu $t1, $t2`

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

- `divu $t1, $t2, $t3` · Set $t1 to ($t2 divided by $t3, unsigned integer division)
  - `divu $t1,$t2,$t3` → `bne $t3, $zero, 1`; `break`; `divu $t2, $t3`; `mflo $t1`

- `divu $t1, $t2, imm`
  - `divu $t1,$t2,-100`: Set $t1 to ($t2 divided by 16-bit immediate, unsigned integer division) → `addi $at, $zero, imm`; `divu $t2, $at`; `mflo $t1`
  - `divu $t1,$t2,100000`: Set $t1 to ($t2 divided by 32-bit immediate, unsigned integer division) → `lui $at, hi(imm)`; `ori $at, $at, lo(imm)`; `divu $t2, $at`; `mflo $t1`

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

Sets LO to the quotient and HI to the remainder. Division by zero produces undefined results with no exception. Use 'mflo' for the quotient; 'mfhi' for the remainder.

## Example

```mips
# Divide 23 by 5. Inspect LO: quotient 4; inspect HI: remainder 3.
li $t0, 23
li $t1, 5
divu $t0, $t1
mflo $t2
mfhi $t3
```
