Prev: 11660 Up: Map Next: 11682
11662: THE 'INT-STORE' SUBROUTINE
Used by the routines at multiply, truncate, negate and sgn.
This subroutine stores a small integer n (-65535<=n<=65535) in the location addressed by HL and the four following locations, i.e. n replaces the first (or second) number at the top of the calculator stack. The subroutine returns HL pointing to the first byte of n on the stack.
Input
C Sign byte
DE Value to store
HL Address of the first byte of the slot on the calculator stack
INT_STORE 11662 PUSH HL The pointer to the first location is saved.
11663 LD (HL),0 The first byte is set to zero.
11665 INC HL Point to the second location.
11666 LD (HL),C Enter the second byte.
The same mechanism is now used as in INT_FETCH to two's complement negative numbers. This is needed e.g. before and after the multiplication of small integers. Addition is however performed without any further two's complementing before or afterwards.
11667 INC HL Point to the third location.
11668 LD A,E Collect the less significant byte.
11669 XOR C Two's complement it if the number is negative.
11670 SUB C
11671 LD (HL),A Store the byte.
11672 INC HL Point to the fourth location.
11673 LD A,D Collect the more significant byte.
11674 ADC A,C Two's complement it if the number is negative.
11675 XOR C
11676 LD (HL),A Store the byte.
11677 INC HL Point to the fifth location.
11678 LD (HL),0 The fifth byte is set to zero.
11680 POP HL Return with HL pointing to the first byte of n on the stack.
11681 RET
Prev: 11660 Up: Map Next: 11682