[
Index] [
Previous] [
Next]
2.8 Converting to Integer
blah
FAsInteger
Returns the integer part of FACCUM in CDE.
Return with BCDE=0 if A=0.
0A77
47
FAsInteger
MOV B,A
0A78
4F
MOV C,A
0A79
57
MOV D,A
0A7A
5F
MOV E,A
0A7B
B7
ORA A
0A7C
C8
RZ
Preserve HL and copy FACCUM to BCDE
0A7D
E5
PUSH H
Unpack FACCUM's mantissa to get the hidden most-significant-bit (see top of page) and get the sign back via an XOR to undo what FUnpackMantissas did with it. Preserve the sign in H
0A84
AE
XRA M
Get sign back
0A85
67
MOV H,A
If FACCUM was negative then decrement the mantissa (two's complement?)
Shift mantissa in CDE right by (24-B) places. This gets the integer part of FACCUM into CDE, which is the whole point of the function.
0A89
3E98
MVI A,
98
Shift mantissa right
0A8B
90
SUB B
by (24-exponent) places?
If floating point sign is negative (ie bit 7 of H set) then two's complement CDE to get the signed integer. We do two's complement by first adding 1, then negating.
0A8F
7C
MOV A,H
0A90
17
RAL
0A94
0600
MVI B,00
Needed for FNegateInt.
Restore HL and return with the integer result in CDE.
0A99
E1
POP H
0A9A
C9
RET
FMantissaDec
Decrements the mantissa in CDE.
0A9B
1B
FMantissaDec
DCX D
DE--
0A9C
7A
MOV A,D
If DE!=0xFFFF...
0A9D
A3
ANA E
0A9E
3C
INR A
0A9F
C0
RNZ
... then return
0AA0
0D
DCR C
C--
0AA1
C9
RET
Int
Removes the fractional part of FACCUM.
If FACCUM's exponent is >= 2^24, then it's too big to hold any fractional part - it is already an integer, so we just return.
0AA2
217201
Int
LXI H,
FACCUM+3
0AA5
7E
MOV A,M
0AA6
FE98
CPI 98
0AA8
D0
RNC
Convert FACCUM to an integer in CDE. On returning, HL points to FACCUM's exponent byte (ie FACCUM+3).
Now we need to convert the integer in CDE to a proper floating point value. To do this we first set FACCUM's exponent to 2^24.
0AAC
3698
MVI M,98
0AAE
79
MOV A,C
0AAF
17
RAL
0AB0
C35B08
JMP 085B
[Index] [Previous] [Next]