Prev: 11599 Up: Map Next: 11660
11647: THE 'INT-FETCH' SUBROUTINE
Used by the routines at FP_TO_BC, PRINT_FP, multiply, re_stack and negate.
This subroutine collects in DE a small integer n (-65535<=n<=65535) from the location addressed by HL, i.e. n is normally the first (or second) number at the top of the calculator stack; but HL can also access (by exchange with DE) a number which has been deleted from the stack.
The subroutine does not itself delete the number from the stack or from memory; it returns HL pointing to the fourth byte of the number in its original position.
Input
HL Address of the first byte of the value on the calculator stack
Output
C Sign byte
DE The value
HL Address of the fourth byte of the value
INT_FETCH 11647 INC HL Point to the sign byte of the number.
11648 LD C,(HL) Copy the sign byte to C.
The following mechanism will two's complement the number if it is negative (C is 255) but leave it unaltered if it is positive (C is 0).
11649 INC HL Point to the less significant byte.
11650 LD A,(HL) Collect the byte in A.
11651 XOR C One's complement it if negative.
11652 SUB C This adds 1 for negative numbers; it sets the carry unless the byte was 0.
11653 LD E,A Less significant byte to E now.
11654 INC HL Point to the more significant byte.
11655 LD A,(HL) Collect it in A.
11656 ADC A,C Finish two's complementing in the case of a negative number; note that the carry is always left reset.
11657 XOR C
11658 LD D,A More significant byte to D now.
11659 RET Finished.
 Prev: 11599 Up: Map Next: 11660