The IDIV instruction

Signed division.

The IDIV instruction format

InstructionDescription
IDIV reg/mem8Signed division of AX by a byte. Result: AL = quotient, AH = remainder.
IDIV reg/mem16Signed division of DX:AX by a word. Result: AX = quotient, DX = remainder.

Divides the signed value in the ax register (for a byte divisor) or the dx:ax register (for a word divisor) by the source operand (the divisor) and stores the result: the quotient and the remainder.

Non-integer results are truncated to 0 (truncation toward zero). The remainder is always smaller in magnitude than the divisor and has the same sign as the dividend. Overflow is signaled by exception #DE (divide error).

Usage example

title Author: Evgeny Sergeevich Dovgopolov

.model small
.stack 100h

code segment public        ; Start of the code segment
    assume cs:code

    main proc              ; Start of the main procedure
        mov     ax, 6      ; Copy the value 6 into the ax register
        mov     bx, 2      ; Copy the value 2 into the bx register
        cwd                ; Perform sign extension of ax into dx
        idiv    bx         ; Divide the signed value DX:AX by the value in the bx register

        mov     ax, 4C00h  ; Copy the process termination function number into ah and the value into al
        int     21h        ; Call the interrupt
    main endp              ; End of the main procedure

code ends                  ; End of the code segment
end main                   ; End of file. The main procedure is the entry point

Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".

Processor status flags

CF
?
PF
?
AF
?
ZF
?
SF
?
TF
No
IF
No
DF
No
OF
?