Thirteen-Digit Dividends - HP 9835A Programming Manual

35 series desktop computer assembly development rom
Table of Contents

Advertisement

Arithmetic
95
The FDV instruction returns the number of subtractions without overflowing as a binary
number in the B register {bits 0-3}. The remaining bits in the B register {4-l5} are cleared.! In
effect, then B contains the next digit in the quotient.
This process is repeated for the number of digits to be calculated. After each FDV execution,
the result of the overflow subtraction is left in Ar2. Since Ar2 does not contain the remainder, it
is necessary to patch Ar2 so that it will contain the proper value for the next calculation. To get
the proper value it is necessary to add Arl back into Ar2 to undo the results of the last
subtraction {which caused the overflow}.
2
There is one case, however, where Ar2 does not need to be patched up, and this is when the
remainder {Ar2} is zero. This situation implies not only that no patching up is needed, but also
that the quotient is complete - no further digits need be calculated. It should be noted that the
number of subtractions (which has been stored in the B register) is one count too small, thus B
has to be incremented in this case so that it can be used as the last digit in the quotient.
Thirteen-Digit Dividends
The largest difficulty in the algorithm is attempting to deal with those instances where the
dividend has thirteen digits. This situation arises when you shift the remainder left a place. The
most significant digit must be retained when it is non-zero so that the subtractions are sub-
tracted from the proper amount.
This shifting can be accomplished with the ML Y instruction. With the way that the ML Y instruc-
tion operates, the left-most digit
(D1)
ends up being shifted out of Ar2 into register A {in the
lower 4 bits, 0-3}. Thus, the thirteen-digit algorithm must accomodate the most significant digit
residing in the A register and the twelve least significant digits in the Ar2 register. The use of
FDV must now take this modified situation into account.
When the FDV instruction is exec1)ted, Arl is subtracted from Ar2 until an overflow occurs.
When this overflow occurs, it is necessary to decrement A and keep subtracting {without
patching up Ar2}. Each time an overflow occurs, A must be decremented until finally an
overflow occurs when A is O. This can be handled very neatly within a small loop.
1
Since bits 4-15 of the register are cleared during execution of the FDV instruction, you can't accumulate Quotient digits there.
After each digit is calculated, it is necessary that you store the digit as part of a quotient which you keep stored in another
location.
2 This is eqUivalent to complementing Ar2, adding in Arl, then complementing Ar2 again.

Advertisement

Table of Contents
loading

Table of Contents