Microprocessor-based systems

Prof. Paolo Montuschi

48/32-bit division algorithm

Vittorio Giovara, Alberto Grand

Description
The provided algorithm computes the residual of the division between a 48bit dividend and a 32-bit divisor. It complies with the 8086 family Assembly language.

Variables
The input operands, called A and B, are defined as a triple data word and a double data word respectively. The little endian convention applies, so the first word of each operand corresponds to the 16 LSBs, while the last word corresponds to the 16 MSBs. The residual is stored, at the end of the computation, in the triple data word variable S, according to the same convention. Two extra variables are used throughout the computation: the double data word TMP, used to store an initial approximation of the quotient, and the triple data word A star, storing the product between TMP and the divisor B. A star is updated at every iteration, either incremented or decremented by B, depending on its initial value (smaller or greater than A); its final value is upper-bounded by A.

Algorithm
The algorithm exploits the division between the 32 MSB of A and the 16 MSB of B in order to obtain an approximation of the ”true value” of the quotient of A and B. This approximated result is subsequently multiplied by B, yielding A star. The core of the algorithm lies in comparing A star with A: • if the latter is smaller, then A star will be decremented by B until it becomes smaller than A. • conversely, if A is greater than A star, the latter will be incremented by B until the difference between A and A star, stored in S, becomes smaller than B. In both cases, S will finally contain the correct residual.

Optimizations
A few words should be spent concerning the operands handled by the algorithm. Input operands should be expressed according to the module and sign representation. The algorithm retrieves and stores sign information, but works on the operands as if they were both positive. An adjustment of the residual is performed at the end, when needed.

1

A small optimization has been devised in order to reduce the number of iterations required to obtain the residual. The 16 LSBs of the second operand B are, as a matter of fact, compared with the number 8000H (i.e. 1 followed by fifteen 0s, in binary; it is the midpoint value that can be expressed using 16 bits). If their value is greater than 8000H, then the initial division is done using the 16 MSBs of B plus 1 as a divisor. Although no mathematical evidence of the validity of doing so is provided in this document, it seems convincing enough that this will result in a better initial approximation of the quotient.

Example
An example might clarify the previous statement. Let’s suppose we want to divide 331 by 27. The correct result is 12, with a residual of 7. We want to use the approximation formerly explained; we will therefore disregard the last digit of both operands, thus computing 33/2 = 16 (R = 1), which is considerably far from 12. However, since the least significant digit of the divisor is greater than 5 (which can be considered as the midpoint of the interval [0, 9]), we may use 3, instead of 2, as a divisor in our approximation, thus computing 33/3 = 11 (R = 0), which is much closer to 12 than 16.

2

Master your semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master your semester with Scribd & The New York Times

Cancel anytime.