x86 Assembly Language Reference Manual

Signed Divide (idiv)

idiv{bwl}		r/m[8|16|32]
Operation

AX r/m8 -> AL

DX:AX r/m16 -> AX

EDX:EAX r/m32 -> EAX

Description

idiv executes signed division. idiv divides a 16-, 32-, or 64-bit register value (dividend) by a register or memory byte, word, or long (divisor). The size of the divisor (8-, 16- or 32-bit operand) determines the particular register used as the dividend, quotient, and remainder.

Table 2-7 idiv Register Assignment

Divisor Operand Size 

Dividend 

Quotient 

Remainder 

byte 

AX 

AL 

AH 

word 

DX:AX 

AX 

DX 

long 

EDX:EAX 

EAX 

EDX 

If the resulting quotient is too large to fit in the destination, or if the divisor is 0, an Interrupt 0 is generated. Non-integral quotients are truncated toward 0. The remainder has the same sign as the dividend; the absolute value of the remainder is always less than the absolute value of the divisor.

Example

Perform a 16-bit signed divide of the DX:AX register by the contents of the effective address (addressed by the EDI register plus an offset of 4) and store the quotient in the AX register

divw 4(%edi)