|
| 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 operation results in more than LEN digits,
| or less than LEN -1 digits, adjust ILOG and repeat from
| A6. This test occurs only on the first pass. If the
| result is exactly 10^LEN, decrement ILOG and divide
| the mantissa by 10.
|
| A14. Convert the mantissa to bcd.
| The binstr routine is used to convert the LEN digit
| mantissa to bcd in memory. The input to binstr is
| to be a fraction; i.e. (mantissa)/10^LEN and adjusted
| such that the decimal point is to the left of bit 63.
| The bcd digits are stored in the correct position in
| the final string area in memory.
|
| A15. Convert the exponent to bcd.
| As in A14 above, the exp is converted to bcd and the
| digits are stored in the final string.
| Test the length of the final exponent string. If the
| length is 4, set operr.
|
| A16. Write sign bits to final string.
|
| Implementation Notes:
|
| The registers are used as follows:
|
| d0: scratch; LEN input to binstr
| d1: scratch
| d2: upper 32-bits of mantissa for binstr
| d3: scratch;lower 32-bits of mantissa for binstr
| d4: LEN
| d5: LAMBDA/ICTR
| d6: ILOG
| d7: k-factor
| a0: ptr for original operand/final result
| a1: scratch pointer
| a2: pointer to FP_X; abs(original value) in ext
| fp0: scratch
| fp1: scratch
| fp2: scratch
| F_SCR1:
| F_SCR2:
| L_SCR1:
| L_SCR2:
| Copyright (C) Motorola, Inc. 1990
| All Rights Reserved
|
| For details on the license for this file, please see the
| file, README, in this same directory.
|BINDEC idnt 2,1 | Motorola 040