July 2002
Intermediate to advanced
320 pages
8h 15m
English
Because signed integer division satisfies n ÷ (−d) = −(n ÷ d) it is adequate to generate code for n ÷ |d| and follow it with an instruction to negate the quotient. (This does not give the correct result for d = −2W − 1, but for this and other negative powers of 2, you can use the code in Section 10-1, “Signed Division by a Known Power of 2,” on page 155, followed by a negating instruction.) It will not do to negate the dividend, because of the possibility that it is the maximum negative number.
It is possible, however, to avoid the negating instruction. The scheme is to compute

Adding 1 if n > 0, however, ...
Read now
Unlock full access