Prev: 12947 Up: Map Next: 12997
12951: THE 'RE-STACK' SUBROUTINE (offset 61)
Used by the routine at atn.
The routine at RE_ST_TWO continues here.
The address of this routine is found in the table of addresses. It is called via the calculator literal 61 by the routines at CIRCLE, DRAW, exp, ln and get_argt. The routine at RE_ST_TWO also continues here.
This subroutine is called to re-stack one number (which could be a 'small integer') in full five-byte floating-point form.
Input
HL Address of the first byte of the number
Output
re_stack 12951 LD A,(HL) If the first byte is not zero, return - the number cannot be a 'small integer'.
12952 AND A
12953 RET NZ
12954 PUSH DE Save the 'other' pointer in DE.
12955 CALL INT_FETCH Fetch the sign in C and the number in DE.
12958 XOR A Clear the A register.
12959 INC HL Point to the fifth location.
12960 LD (HL),A Set the fifth byte to zero.
12961 DEC HL Point to the fourth location.
12962 LD (HL),A Set the fourth byte to zero; bytes 2 and 3 will hold the mantissa.
12963 LD B,145 Set B to 145 for the exponent, i.e. for up to 16 bits in the integer.
12965 LD A,D Test whether D is zero so that at most 8 bits would be needed.
12966 AND A
12967 JR NZ,RS_NRMLSE Jump if more than 8 bits needed.
12969 OR E Now test E too.
12970 LD B,D Save the zero in B (it will give zero exponent if E too is zero).
12971 JR Z,RS_STORE Jump if E is indeed zero.
12973 LD D,E Move E to D (D was zero, E not).
12974 LD E,B Set E to zero now.
12975 LD B,137 Set B to 137 for the exponent - no more than 8 bits now.
RS_NRMLSE 12977 EX DE,HL Pointer to DE, number to HL.
RSTK_LOOP 12978 DEC B Decrement the exponent on each shift.
12979 ADD HL,HL Shift the number right one position.
12980 JR NC,RSTK_LOOP Until the carry is set.
12982 RRC C Sign bit to carry flag now.
12984 RR H Insert it in place as the number is shifted back one place normal now.
12986 RR L
12988 EX DE,HL Pointer to byte 4 back to HL.
RS_STORE 12989 DEC HL Point to the third location.
12990 LD (HL),E Store the third byte.
12991 DEC HL Point to the second location.
12992 LD (HL),D Store the second byte.
12993 DEC HL Point to the first location.
12994 LD (HL),B Store the exponent byte.
12995 POP DE Restore the 'other' pointer to DE.
12996 RET Finished.
Prev: 12947 Up: Map Next: 12997