477
|
1 * Add for REAL #'s - 6309 version
|
|
2 L3FB1 pshs x Preserve X
|
|
3 tst 2,y 1st byte of mantissa 0 (means value is 0)?
|
|
4 beq L3FC7 Yes, eat temp var & leave other var alone
|
|
5 tst 8,y Is original # a 0?
|
|
6 bne L3FCB No, go do actual add
|
|
7 L3FBB ldq 1,y Get Exponent & 1st 3 bytes of mantissa
|
|
8 stq 7,y Save in destination var space
|
|
9 lda 5,y Copy last byte of mantissa (sign bit) to orig var
|
|
10 sta $B,y
|
|
11 L3FC7 leay 6,y Eat temp var & return
|
|
12 puls pc,x
|
|
13
|
|
14 * Real add with non-zero values starts here
|
|
15 * NOTE: Exponents are 2^n, with n being the SIGNED exponent byte
|
|
16 L3FCB lda 7,y Get 1st exponent
|
|
17 suba 1,y Calculate difference in exponents
|
|
18 bvc L3FD5 Didn't exceed +127 or -128, skip ahead
|
|
19 bpl L3FBB Went too big on plus side, make temp var the answe
|
|
20 bra L3FC7 Too small, eat temp var & leave answer alone
|
|
21
|
|
22 L3FD5 bmi L3FDD If negative difference in exponents, skip ahead
|
|
23 cmpa #31 Difference of exponents within 0-31?
|
|
24 ble L3FE5 Yes, go deal with it
|
|
25 bra L3FC7 >2^31, out of range so eat temp var & return
|
|
26
|
|
27 L3FDD cmpa #-31 Difference of exponents within -1 to -31?
|
|
28 blt L3FBB <2^-31, out of range so copy temp to answer
|
|
29 ldb 1,y ???Since negative difference, copy temp exponent
|
|
30 stb 7,y overtop destination exponent?
|
|
31 * As of this point, exponent in temp var no longer needed (A=difference in exp
|
|
32 L3FE5 ldb $B,y Get sign of dest. var
|
|
33 andb #$01 Keep sign bit only
|
|
34 stb ,y Save copy over var type
|
|
35 eorb 5,y EOR with sign bit of temp var
|
|
36 andb #$01 Keep only merged sign bit
|
|
37 stb 1,y Save what resulting sign should be
|
|
38 * aim #$fe,$B,y Force sign bit off on dest var
|
|
39 * aim #$fe,5,y Force sign bit off on temp var
|
|
40 fcb $62,$fe,$2b
|
|
41 fcb $62,$fe,$25
|
|
42 tsta Are exponents exactly the same?
|
|
43 beq L4031 Yes, skip ahead
|
|
44 bpl L4029 Exponent difference positive, go process
|
|
45 * Exponent difference is a negative value
|
|
46 nega Force to positive
|
|
47 leax 6,y Point X to dest. var
|
|
48 bsr L4082 Shift mantissa to match other value (into X:D)
|
|
49 tst 1,y Result going to be positive?
|
|
50 beq L4039 Yes, skip ahead
|
|
51 L400B subw 4,y Q=Q-[2,y]
|
|
52 sbcd 2,y
|
|
53 bcc L404D No borrow required, skip ahead
|
|
54 comw Do NEGQ
|
|
55 comd
|
|
56 addw #1
|
|
57 adcd #0
|
|
58 L4025 dec ,y Drop exponent by 1
|
|
59 bra L404D
|
|
60
|
|
61 * >24 bits to shift - Just use B, then clear a, tfr d to w, clrd
|
|
62 Shift24 beq SkpSh24 Even byte, skip ahead
|
|
63 ldb 2,x Get MSB of # to shift
|
|
64 S24Lp lsrb Shift it down
|
|
65 deca Until done
|
|
66 bne S24Lp
|
|
67 tfr d,w Copy to LSW
|
|
68 clrb Clear out MSW
|
|
69 rts
|
|
70
|
|
71 * Exactly 24 bits
|
|
72 SkpSh24 ldf 2,x Get LSB
|
|
73 clre Clear 2nd LSB
|
|
74 clrb Clear MS 24 bits (A=0 to get here)
|
|
75 rts
|
|
76
|
|
77 * Exponent difference is positive value
|
|
78 L4029 leax ,y Point X to temp var
|
|
79 bsr L4082 Shift mantissa to match other value
|
|
80 stq 2,y Save shifted result
|
|
81 * Equal exponents come here
|
|
82 L4031 ldq 8,y Get mantissa of dest var into Q
|
|
83 tst 1,y Check exponent of temp var
|
|
84 bne L400B <>0, go do Subtract again
|
|
85 L4039 addw 4,y 32 bit add of Q+[2,y]
|
|
86 adcd 2,y
|
|
87 bcc L404D No overflow carry after add, skip ahead
|
|
88 rord Overflow, divide 32 bit mantissa by 2
|
|
89 rorw
|
|
90 inc 7,y Bump up exponent of dest var by 1
|
|
91 L404D tsta Check sign of MSb of Q
|
|
92 bmi L4060 Set, skip ahead
|
|
93 andcc #^Carry Force carry bit off (for ROLW since no LSLW)
|
|
94 L4050 dec 7,y Drop exponent of dest var by 1
|
|
95 bvc L4054 Not underflowed, continue
|
|
96 puls x Pull X back before zeroing out answer
|
|
97 bra L40DD Underflow; answer=0
|
|
98
|
|
99 L4054 rolw 32 bit multiply by 2
|
|
100 rold
|
|
101 bpl L4050 Keep doing until a set bit comes out
|
|
102 L4060 addw #1 Add 1 to Q
|
|
103 adcd #0
|
|
104 bcc L4071 No carry, skip ahead
|
|
105 rora
|
|
106 inc 7,y
|
|
107 L4071 std 8,y Save MSW of answer
|
|
108 tfr w,d Move LSW to D
|
|
109 lsrb Eat sign bit
|
|
110 lslb
|
|
111 orb ,y Put in sign of result
|
|
112 L407C std $A,y Save LSW with sign bit
|
|
113 leay 6,y Eat temp var
|
|
114 puls pc,x Restore X & return
|
|
115
|
|
116 * Tested:WORKS
|
|
117 * ENTRY: A=ABS(difference between exponents) - will never be 0?
|
|
118 * Y=Ptr to var packet 1
|
|
119 * X=Ptr to var packet 2
|
|
120 * During: Q=32 bit mantissa
|
|
121 * <u0014 = ABS difference of exponents
|
|
122 * Exit: Q:32 bit shifted mantissa
|
|
123 L4082 suba #24 24-31 bit shift?
|
|
124 bge Shift24 Yes, go process
|
|
125 adda #8 16-23 bit shift?
|
|
126 bge Shift16 Yes, go process
|
|
127 adda #8 8-15 bit shift?
|
|
128 bge Shift8 Yes, go process
|
|
129 adda #8 Restore 1-7 bit shift count
|
|
130 sta <u0014 Save # of shifts required (1-7)
|
|
131 ldq 2,x Get # to shift
|
|
132 L40BD lsrd Shift 32 bit # (worst case is 180 cycles)
|
|
133 rorw
|
|
134 dec <u0014 Dec # shifts left to do
|
|
135 bne L40BD Keep doing until done
|
|
136 rts
|
|
137
|
|
138 * >15 bits to shift
|
|
139 Shift16 beq SkpSh16 Even 2 bytes, go do
|
|
140 ldw 2,x Get MSW of # to shift
|
|
141 S16Lp lsrw Shift it down (worst case is 90 cycles)
|
|
142 deca Until done
|
|
143 bne S16Lp
|
|
144 clrb Clear MSW of Q (A=0 from dec loop)
|
|
145 rts
|
|
146
|
|
147 * Exactly 16 bits
|
|
148 SkpSh16 ldw 2,x Get LSW of Q
|
|
149 clrb
|
|
150 rts
|
|
151
|
|
152 * >7 bits to shift - Use B:W
|
|
153 Shift8 beq SkpSh8 Exactly 8, use faster method
|
|
154 ldb 2,x Get LS 24 bits
|
|
155 ldw 3,x
|
|
156 S8Lp lsrb Shift it down
|
|
157 rorw
|
|
158 deca
|
|
159 bne S8Lp
|
|
160 rts
|
|
161
|
|
162 * Exactly 8 bits (A=0 to get here)
|
|
163 SkpSh8 ldb 2,x Get MSW of Q
|
|
164 ldw 3,x Get LSW of Q
|
|
165 rts
|