
![]()
Like multiplication, division occurs on 8- or 16-bit numbers in the 8086--80486 and also 32-bit numbers in the 80386/80486. These numbers are signed (IDIV) or unsigned (DIV) integers. The dividend is always a double-width dividend that is divided by the operand. This means that an 8-bit division divides a 16-bit number by an 8-bit number, a 16-bit division divides a 32-bit number by a 16-bit number, and a 32-bit division divides a 64-bit number by a 32-bit number. There is no immediate division instruction available to any 8086--80486 microprocessor.
None of the flag bits change predictably for a division. A division can result in two different types of errors. One of these is an attempt to divide by zero and the other is a divide overflow. A divide overflow occurs when a small number divides into a large number. For example, suppose that AX = 3,000 and that we divide it by 2. Because the quotient for an 8-bit division appears in AL, the result of 1,500 causes a divide overflow because the 1,500 does not fit into AL. In both cases the microprocessor generates an interrupt if a divide error occurs. The divide-error-interrupt and all other interrupts for the microprocessor are explained in Chapter 6.
An 8-bit division uses the AX register to store the dividend that is divided by the contents of any 8-bit register or memory location. The quotient moves into AL after the division with AH containing a whole number remainder. For a signed division, the quotient is positive or negative, but the remainder is always a positive integer. For example, if AX = 0010H (+ 16) and BL = FDH (- 3) and the IDIV BL instruction executes, AX= 01FBH. This represents a quotient of - 5 (AL) with a remainder of 1 (AH). Table 5-11 lists some of the 8-bit division instructions.
Table 5-11. 8-Bit Division Instructions
Instruction Comment
DIV CL AX is divided by CL; the unsigned quotient is in AL
and the remainder is in AH
IDIV BL AX is divided by BL; the signed quotient is in AL
and the remainder is in AH
DIV BYTE PTR [BP] AX is divided by the byte contents of the stack
segment memory location addressed by BP; the
unsigned quotient is in AL and the remainder is in
AH
With 8-bit division, the numbers are usually 8-bits wide. This means that one of them, the dividend, must be converted to a 16-bit wide number in AX. This is accomplished differently for signed and unsigned numbers. For the unsigned number, the most significant 8-bits must be cleared to zero (zero-extended). The MOVZX instruction described in Chapter 4 can be used to zero-extend a number in the 80386/80486 microprocessor. For the signed number, the least significant 8-bits are sign-extended into the most significant 8-bits. In the microprocessor a special instruction exists that sign-extends AL into AH, or converts an 8-bit signed number in AL into a 16-bit signed number in AX. The CBW (convert byte to word) instruction performs this conversion. In the 80386/80486 microprocessor a MOVSX instruction (see Chapter 4) can sign-extend a number.
Example 5-14 (not shown in this excerpt) illustrates a short program that divides the unsigned byte contents of memory location NUMB by the unsigned contents of memory location NUMB1. Here we store the quotient in location ANSQ and the remainder in location ANSR. Notice how the contents of location NUMB are retrieved from memory and then zero-extended to form a 16-bit unsigned number for the dividend.
![]()