[Index] [Previous] [Next]

2.3 Mantissa Magic

A group of functions for manipulating mantissas.

 

FNormalise

Result mantissa in CDEB is normalised, rounded up to CDE, and stored in FACCUM.

If carry set then negate the mantissa. Most users of this function call over this step.
085B DCB508 FNormalise CC FNegateInt  
Normalise the mantissa : We shift it left until bit 23 is set.
085E 2600   MVI H,00
0860 79 MOV A,C Test most-significant bit of mantissa
0861 B7 ORA A and jump ahead if it's 1.
0862 FA7E08 JM FRoundUp
0865 FEE0 NormLoop CPI E0 If we've shifted 32 times,
0867 CABE09 JZ FZero then the number is 0.
086A 25 DCR H
086B 78 MOV A,B Left-shift extra mantissa byte
086C 87 ADD A  
086D 47 MOV B,A  
086E CD9008 CALL FMantissaLeft Left-shift mantissa.
0871 7C MOV A,H
0872 F26508 JP NormLoop Loop
Adjust exponent by however many left-shifts had do be done during normalization.
0875 217201 LXI H,FACCUM+3
0878 86 ADD M
0879 77 MOV M,A Since A was a -ve number, that certainly should
087A D2BE09 JNC FZero have carried, hence the extra check for zero.
087D C8 RZ ?why?
Round up the extra mantissa byte.
087E 78 FRoundUp MOV A,B A=extra mantissa byte
087F 217201 LXI H,FACCUM+3
0882 B7 ORA A If bit 7 of the extra mantissa byte
0883 FC9A08 CM FMantissaInc is set, then round up the mantissa.
Set the sign and exit. The XRA C is interesting : remember that bit 7 of C is the most significant bit of the normalised mantissa, which is invariably 1. Also, we need to use this bit for the sign. Well, in FUnpackMantissas the temporary sign in FTEMP_SIGN was inverted, so an XOR with 1 will get back the correct sign.
0886 46 MOV B,M B=exponent
0887 23 INX H
0888 7E MOV A,M A=FTEMP_SIGN
0889 E680 ANI 80
088B A9 XRA C Bit 7 of C is always 1. Thi
088C 4F MOV C,A
088D C3120A JMP FLoadFromBCDE Exit via copying BCDE to FACCUM.

 

FMantissaLeft

Shift the mantissa in CDE left by one bit.

0890 7B FMantissaLeft MOV A,E
0891 17 RAL
0892 5F MOV E,A
0893 7A MOV A,D
0894 17 RAL
0895 57 MOV D,A
0896 79 MOV A,C
0897 8F ADC A
0898 4F MOV C,A
0899 C9 RET

 

FMantissaInc

Increments the mantissa in CDE and handles overflow.

089A 1C FMantissaInc INR E
089B C0 RNZ
089C 14 INR D
089D C0 RNZ
089E 0C INR C
089F C0 RNZ
08A0 0E80 MVI C,80 Mantissa overflowed to zero, so set it
08A2 34 INR M to 1 and increment the exponent.
08A3 C0 RNZ And if the exponent overflows...

 

Overflow

A convenient place for exiting with the overflow (OV) error.

08A4 1E0A Overflow MVI E,0A
08A6 C3D501 JMP Error

 

FAddMantissas

Adds the mantissa pointed to by HL to the one in CDE.

08A9 7E FAddMantissas MOV A,M
08AA 83 ADD E
08AB 5F MOV E,A
08AC 23 INX H
08AD 7E MOV A,M
08AE 8A ADC D
08AF 57 MOV D,A
08B0 23 INX H
08B1 7E MOV A,M
08B2 89 ADC C
08B3 4F MOV C,A
08B4 C9 RET

 

FNegateInt

Negate the 32-bit integer in CDEB by subtracting it from zero. Also flips the sign in FTEMP. Used by FAsInteger and FAdd.

Flip the sign byte kept in FTEMP.
08B5 217301 FNegateInt LXI H,FTEMP
08B8 7E MOV A,M
08B9 2F CMA
08BA 77 MOV M,A
Negate extended mantissa, ie CDEB = 0 - CDEB.
08BB AF XRA A
08BC 6F MOV L,A
08BD 90 SUB B
08BE 47 MOV B,A
08BF 7D MOV A,L
08C0 9B SBB E
08C1 5F MOV E,A
08C2 7D MOV A,L
08C3 9A SBB D
08C4 57 MOV D,A
08C5 7D MOV A,L
08C6 99 SBB C
08C7 4F MOV C,A
08C8 C9 RET

 

FMantissaRtMult

Shifts the mantissa in CDE right by A places. Note that lost bits end up in B, general practice so we can round up from something later should we need to.

08C9 0600 FMantissaRtMult MVI B,00 Initialise extra mantissa byte
08CB 3C INR A
08CC 6F MOV L,A
08CD AF RtMultLoop XRA A
08CE 2D DCR L
08CF C8 RZ
08D0 CDD608 CALL FMantissaRtOnce
08D3 C3CD08 JMP RtMultLoop

FMantissaRtOnce

Shifts the mantissa in CDE one bit right.

08D6 79 FMantissaRtOnce MOV A,C
08D7 1F RAR
08D8 4F MOV C,A
08D9 7A MOV A,D
08DA 1F RAR
08DB 57 MOV D,A
08DC 7B MOV A,E
08DD 1F RAR
08DE 5F MOV E,A
08DF 78 MOV A,B NB: B is the extra
08E0 1F RAR mantissa byte.
08E1 47 MOV B,A
08E2 C9 RET

 


[Index] [Previous] [Next]