Prev: 11579 Up: Map Next: 11647
11599: THE 'E-FORMAT TO FLOATING-POINT' SUBROUTINE (offset 60)
Used by the routines at DEC_TO_FP and PRINT_FP.
The address of this routine is found in the table of addresses.
This subroutine gives a 'last value' on the top of the calculator stack that is the result of converting a number given in the form xEm, where m is a positive or negative integer. The subroutine is entered with x at the top of the calculator stack and m in the A register.
The method used is to find the absolute value of m, say p, and to multiply or divide x by 10↑p according to whether m is positive or negative.
To achieve this, p is shifted right until it is zero, and x is multiplied or divided by 10↑(2↑n) for each set bit b(n) of p. Since p is never much more than 39, bits 6 and 7 of p will not normally be set.
Input
A Exponent (m)
e_to_fp 11599 RLCA Test the sign of m by rotating bit 7 of A into the carry without changing A.
11600 RRCA
11601 JR NC,E_SAVE Jump if m is positive.
11603 CPL Negate m in A without disturbing the carry flag.
11604 INC A
E_SAVE 11605 PUSH AF Save m in A briefly.
11606 LD HL,23698 This is MEMBOT; a sign flag is now stored in the first byte of mem-0, i.e. 0 for '+' and 1 for '-'.
11609 CALL FP_0_1
11612 RST 40 The stack holds x.
11613 DEFB 164 stk_ten: x, 10
11614 DEFB 56 end_calc: x, 10
11615 POP AF Restore m in A.
E_LOOP 11616 SRL A In the loop, shift out the next bit of m, modifying the carry and zero flags appropriately; jump if carry reset.
11618 JR NC,E_TST_END
11620 PUSH AF Save the rest of m and the flags.
11621 RST 40 The stack holds x' and 10↑(2↑n), where x' is an interim stage in the multiplication of x by 10↑m, and n=0, 1, 2, 3, 4 or 5.
11622 DEFB 193 st_mem_1: (10↑(2↑n) is copied to mem-1)
11623 DEFB 224 get_mem_0: x', 10↑(2↑n), (1/0)
11624 DEFB 0 jump_true to E_DIVSN: x', 10↑(2↑n)
11625 DEFB 4
11626 DEFB 4 multiply: x'*10↑(2↑n)=x"
11627 DEFB 51 jump to E_FETCH: x''
11628 DEFB 2
E_DIVSN 11629 DEFB 5 division: x/10↑(2↑n)=x'' (x'' is x'*10↑(2↑n) or x'/10↑(2↑n) according as m is '+' or '-')
E_FETCH 11630 DEFB 225 get_mem_1: x'', 10↑(2↑n)
11631 DEFB 56 end_calc: x'', 10↑(2↑n)
11632 POP AF Restore the rest of m in A, and the flags.
E_TST_END 11633 JR Z,E_END Jump if m has been reduced to zero.
11635 PUSH AF Save the rest of m in A.
11636 RST 40 x'', 10↑(2↑n)
11637 DEFB 49 duplicate: x'', 10↑(2↑n), 10↑(2↑n)
11638 DEFB 4 multiply: x'', 10↑(2↑(n+1))
11639 DEFB 56 end_calc: x'', 10↑(2↑(n+1))
11640 POP AF Restore the rest of m in A.
11641 JR E_LOOP Jump back for all bits of m.
E_END 11643 RST 40 Use the calculator to delete the final power of 10 reached leaving the 'last value' x*10↑m on the stack.
11644 DEFB 2 delete
11645 DEFB 56 end_calc
11646 RET
Prev: 11579 Up: Map Next: 11647