Prev: 2D3B Up: Map Next: 2D7F
2D4F: THE 'E-FORMAT TO FLOATING-POINT' SUBROUTINE (offset +3C)
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 2D4F RLCA Test the sign of m by rotating bit 7 of A into the carry without changing A.
2D50 RRCA
2D51 JR NC,E_SAVE Jump if m is positive.
2D53 CPL Negate m in A without disturbing the carry flag.
2D54 INC A
E_SAVE 2D55 PUSH AF Save m in A briefly.
2D56 LD HL,$5C92 This is MEMBOT; a sign flag is now stored in the first byte of mem-0, i.e. 0 for '+' and 1 for '-'.
2D59 CALL FP_0_1
2D5C RST $28 The stack holds x.
2D5D DEFB $A4 stk_ten: x, 10
2D5E DEFB $38 end_calc: x, 10
2D5F POP AF Restore m in A.
E_LOOP 2D60 SRL A In the loop, shift out the next bit of m, modifying the carry and zero flags appropriately; jump if carry reset.
2D62 JR NC,E_TST_END
2D64 PUSH AF Save the rest of m and the flags.
2D65 RST $28 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.
2D66 DEFB $C1 st_mem_1: (10↑(2↑n) is copied to mem-1)
2D67 DEFB $E0 get_mem_0: x', 10↑(2↑n), (1/0)
2D68 DEFB $00 jump_true to E_DIVSN: x', 10↑(2↑n)
2D69 DEFB $04
2D6A DEFB $04 multiply: x'*10↑(2↑n)=x"
2D6B DEFB $33 jump to E_FETCH: x''
2D6C DEFB $02
E_DIVSN 2D6D DEFB $05 division: x/10↑(2↑n)=x'' (x'' is x'*10↑(2↑n) or x'/10↑(2↑n) according as m is '+' or '-')
E_FETCH 2D6E DEFB $E1 get_mem_1: x'', 10↑(2↑n)
2D6F DEFB $38 end_calc: x'', 10↑(2↑n)
2D70 POP AF Restore the rest of m in A, and the flags.
E_TST_END 2D71 JR Z,E_END Jump if m has been reduced to zero.
2D73 PUSH AF Save the rest of m in A.
2D74 RST $28 x'', 10↑(2↑n)
2D75 DEFB $31 duplicate: x'', 10↑(2↑n), 10↑(2↑n)
2D76 DEFB $04 multiply: x'', 10↑(2↑(n+1))
2D77 DEFB $38 end_calc: x'', 10↑(2↑(n+1))
2D78 POP AF Restore the rest of m in A.
2D79 JR E_LOOP Jump back for all bits of m.
E_END 2D7B RST $28 Use the calculator to delete the final power of 10 reached leaving the 'last value' x*10↑m on the stack.
2D7C DEFB $02 delete
2D7D DEFB $38 end_calc
2D7E RET
Prev: 2D3B Up: Map Next: 2D7F