# `divu`

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

Web page: https://asm-editor.specy.app/documentation/m68k/instruction/divu

**Unsigned divide**

Category: Arithmetic

The default word form divides an unsigned 32-bit dividend by an unsigned 16-bit divisor.

Used in: [Arithmetic, logic and bits](https://asm-editor.specy.app/learn/courses/m68k/think-in-assembly/arithmetic-logic-and-bits.md) (M68K assembly), [Exceptions and the vector table](https://asm-editor.specy.app/learn/courses/m68k/talking-to-the-outside-world/exceptions-and-the-vector-table.md) (M68K assembly), [Multiply and divide, with the remainder](https://asm-editor.specy.app/learn/courses/m68k/examples/multiply-and-divide.md) (M68K assembly), [A subroutine with its arguments in registers](https://asm-editor.specy.app/learn/courses/m68k/examples/subroutine-with-register-arguments.md) (M68K assembly), [A jump table](https://asm-editor.specy.app/learn/courses/m68k/examples/jump-table.md) (M68K assembly), [Convert a number to a string in any base](https://asm-editor.specy.app/learn/courses/m68k/examples/number-to-string.md) (M68K assembly), [A bouncing ball](https://asm-editor.specy.app/learn/courses/m68k/examples/bouncing-ball.md) (M68K assembly), [The snake game](https://asm-editor.specy.app/learn/courses/m68k/examples/snake.md) (M68K assembly), [Flappy ASM](https://asm-editor.specy.app/learn/courses/m68k/examples/flappy-asm.md) (M68K assembly), [Arithmetic, logic and bits](https://asm-editor.specy.app/learn/courses/assembly-basics/think-in-assembly/arithmetic-logic-and-bits.md) (Assembly basics)

## Flags

| Flag | Effect |
| --- | --- |
| X | not changed |
| N | undefined (do not rely on it) |
| Z | undefined (do not rely on it) |
| V | depends on the result |
| C | always 0 |

After a division that does not overflow, N and Z describe the quotient.

## Forms

- `divu <ea>, Dn` · Size .w
  - Source: Dn, (An), (An)+, -(An), d(An), d(An,Xn), abs, d(PC), d(PC,Xn), #imm (data)

## 68020 only

These forms require the 68020. Select `opt p=68020` before any code or data.

- `divu <ea>, Dn` · Size .l
  - Source: Dn, (An), (An)+, -(An), d(An), d(An,Xn), abs, d(PC), d(PC,Xn), #imm (data)
- `divu <ea>, Dr:Dq` · Size .l
  - Source: Dn, (An), (An)+, -(An), d(An), d(An,Xn), abs, d(PC), d(PC,Xn), #imm (data)

## Operands

- [`<ea>`](https://asm-editor.specy.app/documentation/m68k/addressing-mode.md): An operand using one of the addressing modes listed for this form. The list determines whether it can be a register, memory or an immediate value. With `opt p=68020`, an allowed `d(An,Xn)` or `d(PC,Xn)` mode also permits the corresponding 68020 indexed and memory indirect forms. See [68020 addressing](https://asm-editor.specy.app/documentation/m68k/addressing-mode/68020.md).
- [`Dn`](https://asm-editor.specy.app/documentation/m68k/addressing-mode/direct.md): A data register, `d0` to `d7`.
- [`Dr:Dq`](https://asm-editor.specy.app/documentation/m68k/addressing-mode/register-pairs.md): A remainder register followed by a quotient register, for example `d2:d1`. For `divs.l` and `divu.l`, both supply the 64-bit dividend, high long first. For `divsl.l` and `divul.l`, only `Dq` supplies the 32-bit dividend. The quotient replaces `Dq` and the remainder replaces `Dr`.
- [`#imm`](https://asm-editor.specy.app/documentation/m68k/addressing-mode/immediate.md): An immediate value written after `#`: a number, character or label, such as `#10`, `#$FF` or `#'a'`. It must fit the operation’s size: byte `-128` to `255`, word `-32768` to `65535`, or long `-2147483648` to `4294967295`; signed and unsigned spellings are accepted.

## Description

The destination data register supplies the dividend. The source supplies the divisor. The quotient replaces the destination’s low word, and the remainder replaces its high word.

A zero divisor raises a division-by-zero exception through vector 5 at `$14`, leaving the destination unchanged. Without a handler, the program ends at `divu`. See [writing a handler](https://asm-editor.specy.app/documentation/m68k/exceptions/handlers.md). A quotient above 65535 sets V and leaves the destination unchanged. Test V with `bvs` before using the result.

On the 68020, `divu.l` uses a 32-bit divisor. `divu.l d0, d1` divides the 32-bit value in `d1` by `d0` and keeps only the quotient. `divu.l d0, d2:d1` divides a 64-bit value, with its high long in `d2` and low long in `d1`, by `d0`. It writes the quotient to `d1` and the remainder to `d2`. A quotient too large for 32 bits sets V and leaves the registers unchanged. After a successful division, N and Z describe the quotient. Use different registers to keep both results. If both names refer to the same register, only the quotient remains.

[divul](https://asm-editor.specy.app/documentation/m68k/instruction/divul.md) divides a 32-bit value and keeps the remainder too.

## Example

```m68k
* --- Result: quotient in low word, remainder in high word ---
move.l #21, d0
divu #4, d0
move.w d0, d1 ; d1 = quotient (5)
swap d0
move.w d0, d2 ; d2 = remainder (1)

* --- Large unsigned value ---
move.l #$FFFE, d3
divu #$FFFF, d3
move.w d3, d4 ; d4 = quotient (0)
swap d3
move.w d3, d5 ; d5 = remainder ($FFFE)
```
