Prev: 2DA2 Up: Map Next: 2DD5
2DC1: THE 'LOG(2↑A)' SUBROUTINE
Used by the routine at PRINT_FP.
This subroutine calculates the approximate number of digits before the decimal in x, the number to be printed, or, if there are no digits before the decimal, then the approximate number of leading zeros after the decimal. It is entered with the A register containing e', the true exponent of x, or e'-2, and calculates z=log to the base 10 of (2↑A). It then sets A equal to ABS INT (z+0.5), as required, using FP_TO_A for this purpose.
Input
A e' (true exponent) or e'-2
Output
A INT log (2↑A)
LOG_2_A 2DC1 LD D,A The integer A is stacked, either as 00 00 A 00 00 (for positive A) or as 00 FF A FF 00 (for negative A).
2DC2 RLA
2DC3 SBC A,A
2DC4 LD E,A These bytes are first loaded into A, E, D, C, B and then STK_STORE is called to put the number on the calculator stack.
2DC5 LD C,A
2DC6 XOR A
2DC7 LD B,A
2DC8 CALL STK_STORE
2DCB RST $28 The calculator is used.
2DCC DEFB $34 stk_data: log 2 to the base 10 is now stacked
2DCD DEFB $EF,$1A,$20,$9A,$85
2DD2 DEFB $04 multiply: A*log 2 i.e. log (2↑A)
2DD3 DEFB $27 int: INT log (2↑A)
2DD4 DEFB $38 end_calc
The subroutine continues into FP_TO_A to complete the calculation.
Prev: 2DA2 Up: Map Next: 2DD5