IDIV-DIV

By Vesper Vei
1 minute read

Table of Contents

  1. IDIV-DIV (idiv / div)
    1. Basic purpose
    2. DIV instruction format (unsigned)
    3. Behavioral characteristics
    4. Examples

IDIV-DIV (idiv / div)

Basic purpose

IDIV → signed division DIV → unsigned division
Result layout:

(or rax / rdx)

IDIV (signed) format
idiv r/m32
; edx:eax ÷ r/m32
; 有符号除法

Before execution:

DIV instruction format (unsigned)

div r/m8
; ax ÷ r/m8
; al = 商
; ah = 余数
div r/m32
; edx:eax ÷ r/m32
; eax = 商
; edx = 余数

Note: before execution, edx must be cleared to zero (if the dividend is an unsigned dword).

Behavioral characteristics

Examples

mov eax, 100
mov ecx, 7
xor edx, edx
div ecx
; eax = 14, edx = 2

Signed:

mov eax, -30
mov ecx, 4
cdq
idiv ecx
; eax = -7, edx = -2

Relationship Graph

Loading graph...