div
Unsigned divide
Divides the implicit unsigned dividend selected by the operand width, producing a quotient and remainder.
8086 and later
Used in
- Arithmetic, logic and bitsx86-64 assembly
- Interrupts, exceptions and signalsx86-64 assembly
- Multiply and divide, with the remainderx86-64 assembly
- Print an unsigned number in bases 2 through 36x86-64 assembly
CFPFAFZFSFDFOF ?????–?
- ? undefined afterwards
- – not changed
Forms
Operands
r/m- A general-purpose register or memory location matching the operation’s size, for example
raxorqword [rbp-8]. The byte registersah,bh,chanddhcannot be used with a REX prefix, including when the memory address usesr8–r15.
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.
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