1
/* -*- Mode: Asm -*- */
3
addsf3x.S is part of FPlib V 0.3.0 ported to avr-as
4
for copyright and details see readme.fplib
6
*----------------------------------------------------------------------------------------
8
*--- addition kernel : used by other high level functions
9
* add two extended numbers RX = AX + BX
10
* AX rA3 : rA2:rA1:rA0:rAE sign stored in rT1c.7, rAE cleared by fp_split1
11
* BX rB3 : rB2:rB1:rB0:rBE sign(A) ^ sign(B) stored in T
12
* RX rA3 : rA2:rA1:rA0:rAE resulting sign stored in rT1c.7 (rT1c.7 complemented, if B > A)
18
TEXT_SEG(fplib, __addsf3x)
22
CP rAE,rBE ; some high level functions use ___addsf3x
23
CPC rA0,rB0 ; directely with preset rAE,rBE
28
BRCC ___addsf3x_100 ; A >= B
30
BRTC ___addsf3x_01 ; if T clear the A & B of same sign
31
COM rT1c ; else complement sign
50
___addsf3x_100: ; denormalize lower mantissa until exponents are the same
51
CLR rTI0 ; holds mantissa extension beyond rBE
53
BREQ ___addsf3x_130 ; A + 0
55
SUB rB3,rA3 ; get difference, rB3 negative
56
BREQ ___addsf3x_120 ; same : no shift
57
CPI rB3,LOW(-25) ; no significant digits left after shift
63
ROR rBE ; fraction >> 1 ;
64
SBCI rTI0,0 ; mark if any overflow beyond rBE ;
69
BRTS ___addsf3x_200 ; branch if different sign
70
ADD rAE,rBE ; maybe rAE and rBE are preset
73
adc rA2,rB2 ; add both mantissae
74
BRCC ___addsf3x_130 ; no fraction overflow if C = 0
75
ROR rA2 ; correct overflow
78
ROR rAE ; fraction >> 1
79
SBCI rTI0,0 ; mark if any overflow beyond rBE
87
SUB rAE,rTI0 ; extended mantissa : 0 - lost bits
89
SBC rAE,rBE ; subtract the lower from the larger
90
SBC rA0,rB0 ; extended mantissa : if rBE == 0x80 -> rAE = 0x80
97
BRTC ___addsf3x_100 ; same sign, test for zero & add
98
RJMP _U(__fp_zerox) ; different signs