# `div`

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

Web page: https://asm-editor.specy.app/documentation/x86/instruction/div

**Unsigned divide**

Category: Arithmetic

Divides the implicit unsigned dividend selected by the operand width, producing a quotient and remainder.

8086 and later

[Intel's reference: DIV](https://intel.github.io/SDM/instruction/DIV.html)

Used in: [Arithmetic, logic and bits](https://asm-editor.specy.app/learn/courses/x86/think-in-assembly/arithmetic-logic-and-bits.md) (x86-64 assembly), [Interrupts, exceptions and signals](https://asm-editor.specy.app/learn/courses/x86/talking-to-the-outside-world/interrupts-exceptions-and-signals.md) (x86-64 assembly), [Multiply and divide, with the remainder](https://asm-editor.specy.app/learn/courses/x86/examples/multiply-and-divide.md) (x86-64 assembly), [Print an unsigned number in bases 2 through 36](https://asm-editor.specy.app/learn/courses/x86/examples/number-to-string.md) (x86-64 assembly), [Paint with the mouse](https://asm-editor.specy.app/learn/courses/x86/examples/mouse-paint.md) (x86-64 assembly), [Beep a tune on the PC speaker](https://asm-editor.specy.app/learn/courses/x86/examples/pc-speaker.md) (x86-64 assembly), [Sampled sound](https://asm-editor.specy.app/learn/courses/x86/examples/sampled-sound.md) (x86-64 assembly)

## Flags

| Flag | Effect |
| --- | --- |
| CF | undefined (do not rely on it) |
| PF | undefined (do not rely on it) |
| AF | undefined (do not rely on it) |
| ZF | undefined (do not rely on it) |
| SF | undefined (do not rely on it) |
| DF | not changed |
| OF | undefined (do not rely on it) |

## Forms

- `div r/m` (8, 16, 32, 64)
  - `div r/m8`
  - `div r/m16`
  - `div r/m32`: 386 and later
  - `div r/m64`

## Operands

- `r/m`: A general-purpose register or memory location matching the operation’s size, for example `rax` or `qword [rbp-8]`.

## Description

The divisor width selects the implicit dividend, quotient and remainder:

| Divisor width | Dividend | Quotient | Remainder |
| --- | --- | --- | --- |
| 8 bits | `ax` | `al` | `ah` |
| 16 bits | `dx:ax` | `ax` | `dx` |
| 32 bits | `edx:eax` | `eax` | `edx` |
| 64 bits | `rdx:rax` | `rax` | `rdx` |

The register before the colon is the high half. For a dividend that fits in the low half, clear the high half first; for example, `xor edx, edx` before `div rcx`. A zero divisor or a quotient too large for its destination causes a divide error. Flags are undefined. Use `idiv` for signed division.

## Example

```x86
global _start

section .text
_start:
        mov rax, 100        ; the dividend is rdx:rax
        xor rdx, rdx        ; so the high half has to be cleared
        mov rbx, 7
        div rbx             ; quotient in rax, remainder in rdx

        mov rax, 60         ; syscall 60: exit
        xor rdi, rdi
        syscall
```
