
Instruction Set
4-51
DIV
DIV
Flag Settings After Instruction
Examples
This example divides an 8-bit unsigned number by another 8-bit unsigned number.
This example divides a 32-bit unsigned number by a 16-bit unsigned number. Before
dividing, the example checks the divisor to make sure it is not 0. This practice avoids division
by 0, thereby preventing DIV from generating Interrupt 0.
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0
Processor Status
Flags Register
reserved
OF DF
IF TF SF ZF
AF
PF
CF
? = undefined; – = unchanged
?
–
–
–
?
? res ? res ? res ?
UDIVIDEND
DB
97
; 61h
UDIVISOR
DB
6
; 06h
; divide byte by byte
MOV
AL,UDIVIDEND
; AL = 61h = 97
MOV
AH,0
; AX = 0061h = 97
DIV
UDIVISOR
; AL = 10h = 16, the quotient
; AH = 01h = 1, the remainder
UDIVIDEND
DD
875600
; 000D5C50h
UDIVISOR
DW
57344
; E000h
; divide doubleword by word
; test for 0 divisor
CMP
UDIVISOR,0
; is divisor 0?
JE
DIV_ZERO
; if so, then jump
; copy dividend to registers
; (bytes in memory are store in reverse order)
MOV
DX,WORD PTR UD2
MOV
AX,WORD PTR UDIVIDEND
; DX::AX = 000D5C50h
DIV
UDIVISOR
; AX = 000Fh = 15,
; the quotient
; DX = 3C50h = 15440,
; the remainder
...
DIV_ZERO:
...
Содержание Am186 Series
Страница 1: ...Am186 and Am188 Family Instruction Set Manual February 1997...
Страница 10: ...Table of Contents x...
Страница 18: ...Programming 1 8...
Страница 40: ...Instruction Set Listing 3 14...