[Index] [Previous] [Next]

2.2 Addition & Subtraction

blah

FSub

080A C1 FSub POP B Get lhs in BCDE.
080B D1 POP D
080C CDFA09 CALL FNegate Negate rhs and slimily
080F 21.... LXI H,.... LXI into FAdd + 2.

FAdd

The lhs is on the stack, the rhs is in FACCUM. The steps for adding the two numbers are :

0810 C1 FAdd POP B Get lhs in BCDE.
0811 D1 POP D
Special cases for when lhs or rhs are zero.
0812 78 MOV A,B If lhs==0 then we don't need
0813 B7 ORA A to do anything and can just
0814 C8 RZ exit.
0815 3A7201 LDA FACCUM+3 If rhs==0 then exit via a copy
0818 B7 ORA A of lhs to FACCUM.
0819 CA120A JZ FLoadFromBCDE
Get exponents' difference into A.
081C 90 SUB B A=rhs.exponent-lhs.exponent.
081D D22C08 JNC 082C If rhs' exponent >= lhs'exponent, jump ahead.
Swap lhs and rhs if lhs exponent was more than rhs exponent.
0820 2F CMA Two's complement the exponent
0821 3C INR A difference, so it's correct.
0822 EB XCHG
0823 CD020A CALL FPush Push old rhs
0826 EB XCHG
0827 CD120A CALL FLoadFromBCDE rhs = old lhs
082A C1 POP B lhs = old rhs.
082B D1 POP D
Unpack the mantissas. This loses the signs of both numbers, but we do get back their relationship : the call to FUnpackMantissas leaves A +ve if the signs mismatched, or -ve if the signs were equal.
082C F5 PUSH PSW Preserve exponent diff
082D CD370A CALL FUnpackMantissas
0830 67 MOV H,A H=sign relationship
0831 F1 POP PSW A=exponent diff.
Align lhs with rhs.
0832 CDC908 CALL FMantissaRtMult Shift lhs mantissa right by (exponent diff) places.
Decide whether to add or subtract the mantissas. We subtract if the signs were mismatched.
0835 B4 ORA H A=0 after last call, so this tests
0836 216F01 LXI H,FACCUM the sign relationship.
0839 F24D08 JP FSubMantissas Jump ahead if we need to subtract.
Add the mantissas.
083C CDA908 CALL FAddMantissas
083F D27E08 JNC FRoundUp Jump ahead if that didn't overflow.
0842 23 INX H Flip the sign in FTEMP_SIGN.
0843 34 INR M  
0844 CAA408 JZ Overflow Error out if exponent overflowed.
0847 CDD608 CALL FMantissaRtOnce Shift mantissa one place right
084A C37E08 JMP FRoundUp Jump ahead.
Subtract lhs mantissa from rhs mantissa.
084D AF FSubMantissas XRA A B=0-B
084E 90 SUB B
084F 47 MOV B,A
0850 7E MOV A,M E=(FACCUM)-E
0851 9B SBB E
0852 5F MOV E,A
0853 23 INX H
0854 7E MOV A,M D=(FACCUM+1)-D
0855 9A SBB D
0856 57 MOV D,A
0857 23 INX H
0858 7E MOV A,M C=(FACCUM+2)-C
0859 99 SBB C
085A 4F MOV C,A

Fall into FNormalise

 


[Index] [Previous] [Next]