
Instruction Set
4-62
IDIV
IDIV
This example divides one 16-bit integer by another.
Tips
IDIV requires the dividend to be twice the size of the divisor. To convert an 8-bit integer
dividend to its 16-bit equivalent, use CBW. To convert a 16-bit dividend to its 32-bit
equivalent, use CWD.
If the integer dividend will fit in a 16-bit register and you don’t need the remainder, use SAR
to divide integers by powers of 2. When dividing an integer by a power of 2, it is faster to
use SAR than IDIV.
When dividing unsigned numbers, use DIV instead of IDIV to make it obvious to someone
who reads your code that you are operating on unsigned numbers.
Related Instructions
If you want to
See
Convert an 8-bit integer dividend to its 16-bit equivalent
CBW
Convert a 16-bit integer dividend to its 32-bit equivalent
CWD
Divide an unsigned number by another unsigned number
DIV
Change the sign of an integer
NEG
Divide an integer by a power of 2
SAR
SDIVIDEND
DW
4800
; 12C0h
SDIVISOR
DW
-321
; FEBFh
; divide word integers
MOV
AX,SDIVIDEND
; AX = 12C0h = 4800
CWD
; DX::AX = 000012C0h = 4800
IDIV
SDIVISOR
; AX = 00F2h = -14, the quotient
; DX = 0132h = -306, the remainder
Содержание 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...