Prev: 2D4F Up: Map Next: 2D8C
2D7F: 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 2D7F INC HL Point to the sign byte of the number.
2D80 LD C,(HL) Copy the sign byte to C.
The following mechanism will two's complement the number if it is negative (C is +FF) but leave it unaltered if it is positive (C is +00).
2D81 INC HL Point to the less significant byte.
2D82 LD A,(HL) Collect the byte in A.
2D83 XOR C One's complement it if negative.
2D84 SUB C This adds 1 for negative numbers; it sets the carry unless the byte was 0.
2D85 LD E,A Less significant byte to E now.
2D86 INC HL Point to the more significant byte.
2D87 LD A,(HL) Collect it in A.
2D88 ADC A,C Finish two's complementing in the case of a negative number; note that the carry is always left reset.
2D89 XOR C
2D8A LD D,A More significant byte to D now.
2D8B RET Finished.
Prev: 2D4F Up: Map Next: 2D8C