microprocessor-based systems - 48/32-bit division algorithm

3
Microprocessor-based systems Prof. Paolo Montuschi 48/32-bit division algorithm Vittorio Giovara, Alberto Grand

Upload: project-symphony-collection

Post on 12-Nov-2014

500 views

Category:

Documents


0 download

DESCRIPTION

This was our last homework of the first emisemester: it was about a division algorithm in the 8086 assembly language. It computes the residual of the operation with opeands over 48 and 32 bits.

TRANSCRIPT

Page 1: Microprocessor-Based Systems - 48/32-bit division algorithm

Microprocessor-based systemsProf. Paolo Montuschi

48/32-bit division algorithm

Vittorio Giovara, Alberto Grand

Page 2: Microprocessor-Based Systems - 48/32-bit division algorithm

Description

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

Variables

The input operands, called A and B, are defined as a triple data word and adouble data word respectively. The little endian convention applies, so thefirst word of each operand corresponds to the 16 LSBs, while the last wordcorresponds to the 16 MSBs.

The residual is stored, at the end of the computation, in the triple dataword variable S, according to the same convention.

Two extra variables are used throughout the computation: the doubledata word TMP, used to store an initial approximation of the quotient, andthe triple data word A star, storing the product between TMP and the divisorB. A star is updated at every iteration, either incremented or decrementedby B, depending on its initial value (smaller or greater than A); its final valueis upper-bounded by A.

Algorithm

The algorithm exploits the division between the 32 MSB of A and the 16MSB of B in order to obtain an approximation of the ”true value” of thequotient of A and B. This approximated result is subsequently multipliedby B, yielding A star. The core of the algorithm lies in comparing A starwith A:

• if the latter is smaller, then A star will be decremented by B until itbecomes smaller than A.

• conversely, if A is greater than A star, the latter will be incrementedby B until the difference between A and A star, stored in S, becomessmaller 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 al-gorithm. Input operands should be expressed according to the module andsign representation. The algorithm retrieves and stores sign information,but works on the operands as if they were both positive. An adjustment ofthe residual is performed at the end, when needed.

1

Page 3: Microprocessor-Based Systems - 48/32-bit division algorithm

A small optimization has been devised in order to reduce the numberof iterations required to obtain the residual. The 16 LSBs of the secondoperand 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 beexpressed using 16 bits). If their value is greater than 8000H, then theinitial division is done using the 16 MSBs of B plus 1 as a divisor. Althoughno mathematical evidence of the validity of doing so is provided in thisdocument, it seems convincing enough that this will result in a better initialapproximation 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 computing33/2 = 16 (R = 1), which is considerably far from 12. However, since theleast significant digit of the divisor is greater than 5 (which can be consideredas the midpoint of the interval [0, 9]), we may use 3, instead of 2, as a divisorin our approximation, thus computing 33/3 = 11 (R = 0), which is muchcloser to 12 than 16.

2