ID Number: Q68599
6.00 6.00a 6.00ax 7.00
MS-DOS
Summary:
SYMPTOMS
The code below produces an error on computers with Intel 8088/86
processors, but runs correctly on later versions of the Intel
processors, such as the 80286. When the program is run on an
8088/8086 machine, the following error occurs:
run-time error R6003
- integer divide by 0
CAUSE
The problem is caused by the difference between the IDIV
instruction on the processors. The Intel programmer's reference
manual for the 8088/86 processor states the following:
For word integer division, the maximum positive quotient is
+32767 and the minimum negative quotient is -32767. If the
quotient is positive and exceeds the maximum, or is negative and
is less than the minimum, the quotient and remainder are
undefined, and a type 0 interrupt is generated.
A type 0 (zero) interrupt is an "Integer Divide By 0" error, which
means that the lowest negative number that can be used on an
8088/86 CPU machine for integer division is -32767. The developer
should not allow an integer to become -32768. This limitation has
changed with later versions of the Intel processors, which allow
integer division with a quotient of -32768.
RESOLUTION
This is not a problem with the code generated by the compiler.
Because the problem is exhibited at execution time, the programmer
must ensure that an integer will not take on a value of -32768
before it is used as a quotient.
More Information:
Sample Code
-----------
#include <stdio.h>
void main(void)
{
int numerator=-32768;
int denominator=1;
int result;
result=numerator/denominator;
}
Additional reference words: 5.10 6.00 6.00a 6.00ax 7.00