|
| bindec.sa 3.4 1/3/91
|
| bindec
|
| Description:
| Converts an input in extended precision format
| to bcd format.
|
| Input:
| a0 points to the input extended precision value
| value in memory; d0 contains the k-factor sign-extended
| to 32-bits. The input may be either normalized,
| unnormalized, or denormalized.
|
| Output: result in the FP_SCR1 space on the stack.
|
| Saves and Modifies: D2-D7,A2,FP2
|
| Algorithm:
|
| A1. Set RM and size ext; Set SIGMA = sign of input.
| The k-factor is saved for use in d7. Clear the
| BINDEC_FLG for separating normalized/denormalized
| input. If input is unnormalized or denormalized,
| normalize it.
|
| A2. Set X = abs(input).
|
| A3. Compute ILOG.
| ILOG is the log base 10 of the input value. It is
| approximated by adding e + 0.f when the original
| value is viewed as 2^^e * 1.f in extended precision.
| This value is stored in d6.
|
| A4. Clr INEX bit.
| The operation in A3 above may have set INEX2.
|
| A5. Set ICTR = 0;
| ICTR is a flag used in A13. It must be set before the
| loop entry A6.
|
| A6. Calculate LEN.
| LEN is the number of digits to be displayed. The
| k-factor can dictate either the total number of digits,
| if it is a positive number, or the number of digits
| after the decimal point which are to be included as
| significant. See the 68882 manual for examples.
| If LEN is computed to be greater than 17, set OPERR in
| USER_FPSR. LEN is stored in d4.
|
| A7. Calculate SCALE.
| SCALE is equal to 10^ISCALE, where ISCALE is the number
| of decimal places needed to insure LEN integer digits
| in the output before conversion to bcd. LAMBDA is the
| sign of ISCALE, used in A9. Fp1 contains
| 10^^(abs(ISCALE)) using a rounding mode which is a
| function of the original rounding mode and the signs
| of ISCALE and X. A table is given in the code.
|
| A8. Clr INEX; Force RZ.
| The operation in A3 above may have set INEX2.
| RZ mode is forced for the scaling operation to insure
| only one rounding error. The grs bits are collected in
| the INEX flag for use in A10.
|
| A9. Scale X -> Y.
| The mantissa is scaled to the desired number of
| significant digits. The excess digits are collected
| in INEX2.
|
| A10. Or in INEX.
| If INEX is set, round error occurred. This is
| compensated for by 'or-ing' in the INEX2 flag to
| the lsb of Y.
|
| A11. Restore original FPCR; set size ext.
| Perform FINT operation in the user's rounding mode.
| Keep the size to extended.
|
| A12. Calculate YINT = FINT(Y) according to user's rounding
| mode. The FPSP routine sintd0 is used. The output
| is in fp0.
|
| A13. Check for LEN digits.
| If the int