div

Unsigned divide

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

8086 and later

Intel's reference: DIV

CFPFAFZFSFDFOF ?????–?
  • ? undefined afterwards
  • – not changed

Forms

Operands

r/m
A general-purpose register or memory location matching the operation’s size, for example rax or qword [rbp-8]. The byte registers ah, bh, ch and dh cannot be used with a REX prefix, including when the memory address uses r8–r15.

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

Divisor widthDividendQuotientRemainder
8 bitsaxalah
16 bitsdx:axaxdx
32 bitsedx:eaxeaxedx
64 bitsrdx:raxraxrdx

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.

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