Routines
 Prev: 2D8C Up: Map Next: 2DA2
2D8E: 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 2D8E PUSH HL The pointer to the first location is saved.
2D8F LD (HL),\$00 The first byte is set to zero.
2D91 INC HL Point to the second location.
2D92 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.
2D93 INC HL Point to the third location.
2D94 LD A,E Collect the less significant byte.
2D95 XOR C Two's complement it if the number is negative.
2D96 SUB C
2D97 LD (HL),A Store the byte.
2D98 INC HL Point to the fourth location.
2D99 LD A,D Collect the more significant byte.
2D9A ADC A,C Two's complement it if the number is negative.
2D9B XOR C
2D9C LD (HL),A Store the byte.
2D9D INC HL Point to the fifth location.
2D9E LD (HL),\$00 The fifth byte is set to zero.
2DA0 POP HL Return with HL pointing to the first byte of n on the stack.
2DA1 RET
 Prev: 2D8C Up: Map Next: 2DA2