annotate src/math.asm @ 641:1212d39c9f6f

3.14 beta work
author heinrichsweikamp
date Sat, 21 Nov 2020 17:46:29 +0100
parents 4050675965ea
children 7d8a4c60ec1a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
heinrichsweikamp
parents:
diff changeset
1 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
2 ;
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
3 ; File math.asm * combined next generation V3.09.4k
0
heinrichsweikamp
parents:
diff changeset
4 ;
heinrichsweikamp
parents:
diff changeset
5 ; Math subroutines
heinrichsweikamp
parents:
diff changeset
6 ;
heinrichsweikamp
parents:
diff changeset
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
heinrichsweikamp
parents:
diff changeset
8 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
9 ; HISTORY
heinrichsweikamp
parents:
diff changeset
10 ; 2011-08-03 : [mH] moving from OSTC code
heinrichsweikamp
parents:
diff changeset
11
heinrichsweikamp
parents:
diff changeset
12
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
13 #include "hwos.inc" ; mandatory header
0
heinrichsweikamp
parents:
diff changeset
14
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
15
0
heinrichsweikamp
parents:
diff changeset
16 ;=============================================================================
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
17 math1 CODE
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
18 ;=============================================================================
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
19
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
20 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
21 ; Divide a 16 Bit Integer by a Power of 2: divA:2 = divA:2 / 2^WREG
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
22 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
23 ; trashes WREG
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
24 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
25 global div16
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
26 div16:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
27 bcf STATUS,C ; clear carry
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
28 rrcf divA+1 ; rotate right high byte, carry into MSB, LSB into carry
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
29 rrcf divA+0 ; rotate right low byte, carry into MSB, LSB into carry
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
30 decfsz WREG ; decrement counter, done?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
31 bra div16 ; NO - loop
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
32 return ; YES - done
0
heinrichsweikamp
parents:
diff changeset
33
heinrichsweikamp
parents:
diff changeset
34
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
35 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
36 math2 CODE
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
37 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
38
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
39 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
40 ; Multiply a 16 bit Integer by a Power of 2: xA:2 = xA:2 * 2^WREG
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
41 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
42 ; trashes WREG
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
43 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
44 global mult16
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
45 mult16:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
46 bcf STATUS,C ; clear carry
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
47 rlcf divA+0,F ; rotate left low byte, carry into LSB, MSB into carry
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
48 rlcf divA+1,F ; rotate left high byte, carry into LSB, MSB into carry
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
49 decfsz WREG ; decrement counter, done?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
50 bra mult16 ; NO - loop
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
51 return ; YES - done
0
heinrichsweikamp
parents:
diff changeset
52
heinrichsweikamp
parents:
diff changeset
53
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
54 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
55 math3 CODE
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
56 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
57
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
58 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
59 ; Add two UNSIGNED 16 bit Integers: sub_c:2 = sub_a:2 + sub_b:2
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
60 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
61 ; trashes WREG
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
62 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
63 global addU16
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
64 addU16:
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
65 movf sub_a+0,W ; get 1st summand (low byte) to WREG
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
66 addwf sub_b+0,W ; add 2nd summand (low byte) and store result in WREG
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
67 movwf sub_c+0 ; copy result (low byte) to sub_c
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
68 movf sub_a+1,W ; get 1st summand (high byte) to WREG
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
69 addwfc sub_b+1,W ; add 2nd summand (high byte) and store result in WREG
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
70 movwf sub_c+1 ; copy result (high byte) to sub_c
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
71 return ; done
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
72
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
73
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
74 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
75 math4 CODE
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
76 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
77
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
78 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
79 ; Subtract two SIGNED 16 Bit Integers: sub_c:2 = sub_a:2 - sub_b:2
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
80 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
81 ; sets neg_flag if result is < 0, trashes WREG
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
82 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
83 global sub16
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
84 sub16:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
85 bcf neg_flag ; clear flag which will indicate if result is negative
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
86 movf sub_b+0,W ; get value to be subtracted, low byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
87 subwf sub_a+0,W ; execute subtraction on low byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
88 movwf sub_c+0 ; copy result to output variable, low byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
89 movf sub_b+1,W ; get value to be subtracted, high byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
90 subwfb sub_a+1,W ; execute subtraction on high byte, considering borrow flag
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
91 movwf sub_c+1 ; copy result to output variable, high byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
92 btfss STATUS,N ; result negative ?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
93 return ; NO - result positive, done
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
94 bsf neg_flag ; YES - set flag
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
95 comf sub_c+1 ; - do a 16 bit sign change
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
96 negf sub_c+0 ;
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
97 btfsc STATUS,C ; - carry to be propagated ?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
98 incf sub_c+1,F ; YES - do it
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
99 return ; - done
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
100
0
heinrichsweikamp
parents:
diff changeset
101
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
102 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
103 math5 CODE
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
104 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
105
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
106 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
107 ; Subtract two UNSIGNED 16 Bit Integers: sub_c:2 = sub_a:2 - sub_b:2
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
108 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
109 ; sets neg_flag if result is < 0, trashes WREG
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
110 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
111 global subU16
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
112 subU16:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
113 bcf neg_flag ; clear flag which will indicate if result is negative
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
114 movf sub_b+0,W ; get value to be subtracted, low byte
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
115 subwf sub_a+0,W ; execute subtraction on low byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
116 movwf sub_c+0 ; copy result to output variable, low byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
117 movf sub_b+1,W ; get value to be subtracted, high byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
118 subwfb sub_a+1,W ; execute subtraction on high byte, considering borrow flag
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
119 movwf sub_c+1 ; copy result to output variable, high byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
120 btfsc STATUS,C ; borrow to propagate (B == /CARRY) ?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
121 return ; NO - result positive, done
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
122 bsf neg_flag ; YES - set flag
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
123 comf sub_c+1 ; - do a 16 bit sign change
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
124 negf sub_c+0 ; - ...
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
125 btfsc STATUS,C ; - carry to be propagated ?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
126 incf sub_c+1,F ; YES - do it
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
127 return ; - done
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
128
0
heinrichsweikamp
parents:
diff changeset
129
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
130 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
131 math6 CODE
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
132 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
133
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
134 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
135 ; Compare two UNSIGNED 16 Bit Integers: sub_a:2 - sub_b:2
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
136 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
137 ; sets neg_flag if result is < 0, trashes WREG
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
138 ; the subtraction result is not stored
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
139 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
140 global cmpU16
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
141 cmpU16:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
142 bcf neg_flag ; clear flag which will indicate if result is negative
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
143 movf sub_b+0,W ; get value to be subtracted, low byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
144 subwf sub_a+0,W ; execute subtraction on low byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
145 movf sub_b+1,W ; get value to be subtracted, high byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
146 subwfb sub_a+1,W ; execute subtraction on high byte, considering borrow flag
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
147 btfss STATUS,C ; borrow to propagate (B == /CARRY) ?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
148 bsf neg_flag ; YES - result is negative, set flag
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
149 return ; done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
150
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
151
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
152 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
153 math7 CODE
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
154 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
155
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
156 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
157 ; Multiply two UNSIGNED 16 bit Integers: xC:4 = xA:2 * xB:2
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
158 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
159 ; trashes PRODL, PRODH, WREG
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
160 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
161 global mult16x16
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
162 mult16x16:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
163 clrf xC+2 ; clear the high-order bits
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
164 clrf xC+3 ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
165
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
166 movf xA+0,W ; do the "L" multiplication
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
167 mulwf xB+0
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
168 movff PRODL,xC+0 ; copy result to xC
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
169 movff PRODH,xC+1
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
170
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
171 movf xA+0,W ; do the "I" multiplication
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
172 mulwf xB+1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
173 movf PRODL,W ; get the product's low byte...
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
174 addwf xC+1,F ; ... and add it to xC+1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
175 movf PRODH,W ; get the product's high byte...
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
176 addwfc xC+2,F ; ... and add it to xC+2 obeying carry bit from xC+1
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
177
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
178 movf xA+1,W ; do the "O" multiplication
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
179 mulwf xB+0
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
180 movf PRODL,W ; get the product's low byte...
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
181 addwf xC+1,F ; ... and add it to xC+1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
182 movf PRODH,W ; get the product's high byte...
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
183 addwfc xC+2,F ; ... and add it to xC+2 obeying carry bit from xC+1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
184 clrf WREG ; clear WREG...
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
185 addwfc xC+3,F ; ... add add it to xC+3 obeying carry bit from xC+2 (can only happen in "O" multiplication)
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
186
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
187 movf xA+1,W ; do the "F" multiplication
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
188 mulwf xB+1
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
189 movf PRODL,W ; get the product's low byte...
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
190 addwf xC+2,F ; ... and add it to xC+2
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
191 movf PRODH,W ; get the product's high byte...
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
192 addwfc xC+3,F ; ... and add it to xC+3 obeying carry bit from xC+2
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
193
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
194 return ; done
0
heinrichsweikamp
parents:
diff changeset
195
heinrichsweikamp
parents:
diff changeset
196
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
197 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
198 math8 CODE
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
199 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
200
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
201 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
202 ; Divide two UNSIGNED 16 Bit Integers: xC:2 = xA:2 / xB:2 with xA as remainder
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
203 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
204 ; trashes WREG
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
205 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
206 global div16x16
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
207 div16x16:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
208 movlw .16 ; process 16 bits ...
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
209 movwf math_loop ; ... initialize loop counter
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
210 movff xA+0,xC+0 ; copy xA to xC
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
211 movff xA+1,xC+1 ; ...
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
212 clrf xA+0 ; clear xA, will now be used to hold the remainder
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
213 clrf xA+1 ; ...
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
214 div16x16_1:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
215 bcf STATUS,C ; clear carry flag to shift in a zero bit
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
216 rlcf xC+0,F ; shift left xC
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
217 rlcf xC+1,F ; ... shifting MSB out of xC...
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
218 rlcf xA+0,F ; ... and into LSB of xA
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
219 rlcf xA+1,F ; ...
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
220 btfsc STATUS,C ; did the remainder overflow (carry set)?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
221 bra div16x16_2 ; YES - directly generate a result bit = 1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
222 movf xB+0,W ; NO - compute remainder - divisor = xA - xB, trash result to WREG
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
223 subwf xA+0,W ; - ...
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
224 movf xB+1,W ; - ...
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
225 subwfb xA+1,W ; - ...
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
226 btfss STATUS,C ; - remainder < divisor (-> borrow flag set, equals carry flag cleared) ?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
227 bra div16x16_3 ; YES - result bit = 0, keep LSB of xC+0 being 0
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
228 div16x16_2:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
229 bsf xC+0,0 ; NO - result bit = 1, set LSB of xC+0 to 1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
230 movf xB+0,W ; - subtract divisor from remainder "for real": xA = xA - xB
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
231 subwf xA+0,F ; - ...
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
232 movf xB+1,W ; - ...
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
233 subwfb xA+1,F ; - ...
0
heinrichsweikamp
parents:
diff changeset
234 div16x16_3:
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
235 decfsz math_loop,F ; decrement loop counter, all bits done?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
236 bra div16x16_1 ; NO - loop
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
237 return ; YES - done
0
heinrichsweikamp
parents:
diff changeset
238
heinrichsweikamp
parents:
diff changeset
239
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
240 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
241 math9 CODE
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
242 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
243
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
244 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
245 ; Divide a 32 Bit Integer by a 16 Bit Integer: xC:4 = xC:4 / xB:2 with xA as remainder
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
246 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
247 ; trashes WREG
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
248 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
249 global div32x16
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
250 div32x16:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
251 movlw .32 ; process 32 bits ...
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
252 movwf math_loop ; ... initialize loop counter
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
253 clrf xA+0 ; clear xA, will be used to hold the remainder
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
254 clrf xA+1 ; ...
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
255 div32x16_1:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
256 bcf STATUS,C ; clear carry flag to shift in a zero bit
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
257 rlcf xC+0,F ; shift left xC
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
258 rlcf xC+1,F ; ...
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
259 rlcf xC+2,F ; ...
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
260 rlcf xC+3,F ; ... shifting MSB out of xC...
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
261 rlcf xA+0,F ; ... and into LSB of xA
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
262 rlcf xA+1,F ; ...
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
263 btfsc STATUS,C ; did the remainder overflow (carry set)?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
264 bra div32x16_2 ; YES - directly generate a result bit = 1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
265 movf xB+0,W ; NO - compute remainder - divisor = xA - xB, trash result to WREG
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
266 subwf xA+0,W ; - ...
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
267 movf xB+1,W ; - ...
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
268 subwfb xA+1,W ; - ...
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
269 btfss STATUS,C ; - remainder < divisor (-> borrow flag set, equals carry flag cleared) ?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
270 bra div32x16_3 ; YES - result bit = 0, keep LSB of xC+0 being 0
0
heinrichsweikamp
parents:
diff changeset
271 div32x16_2:
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
272 bsf xC+0,0 ; NO - result bit = 1, set LSB of xC+0 to 1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
273 movf xB+0,W ; - subtract divisor from remainder "for real": xA = xA - xB
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
274 subwf xA+0,F ; - ...
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
275 movf xB+1,W ; - ...
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
276 subwfb xA+1,F ; - ...
0
heinrichsweikamp
parents:
diff changeset
277 div32x16_3:
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
278 decfsz math_loop,F ; decrement loop counter, all bits done?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
279 bra div32x16_1 ; NO - loop
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
280 return ; YES - done
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
281
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
282
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
283 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
284 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
285 ; ISR math functions
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
286 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
287 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
288
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
289 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
290 math10 CODE
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
291 ;=============================================================================
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
292
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
293 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
294 ; 24 Bit Shift, repeated WREG Times, dedicated to a specific Usage
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
295 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
296 ; Because less than 8 bits are shifted and only C[2:1] is needed,
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
297 ; we don't care what bit is inserted.
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
298 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
299 global isr_shift_C31
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
300 isr_shift_C31:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
301 rrcf isr_xC+3,F ; shift three bytes
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
302 rrcf isr_xC+2,F ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
303 rrcf isr_xC+1,F ; ...
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
304 decfsz WREG ; decrement loop counter, done?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
305 bra isr_shift_C31 ; NO - loop
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
306 return ; YES - done
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
307
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
308
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
309 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
310 math11 CODE
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
311 ;=============================================================================
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
312
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
313 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
314 ; Multiply two UNSIGNED 16 Bit Integers: isr_xC = isr_xA * isr_xB
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
315 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
316 ; trashes PRODL, PRODH, WREG
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
317 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
318 global isr_unsigned_mult16x16
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
319 isr_unsigned_mult16x16:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
320 movf isr_xA+0,W ; multiply a[0] * b[0]
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
321 mulwf isr_xB+0 ; ...
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
322 movff PRODL,isr_xC+0 ; store product to c[1]:c[0]
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
323 movff PRODH,isr_xC+1 ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
324
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
325 movf isr_xA+1,W ; multiply a[1] * b[1]
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
326 mulwf isr_xB+1 ; ...
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
327 movff PRODL, isr_xC+2 ; store product to c[3]:c[2]
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
328 movff PRODH, isr_xC+3 ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
329
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
330 movf isr_xA+0,W ; multiply a[0] * b[1]
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
331 mulwf isr_xB+1 ; ...
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
332 movf PRODL,W ; add cross product to c[3]:c[2]:c[1]
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
333 addwf isr_xC+1,F ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
334 movf PRODH,W ; ...
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
335 addwfc isr_xC+2,F ; propagate carry
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
336 clrf WREG ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
337 addwfc isr_xC+3,F ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
338
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
339 movf isr_xA+1,W ; multiply a[1] * b[0]
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
340 mulwf isr_xB+0 ; ...
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
341 movf PRODL,W ; add cross product
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
342 addwf isr_xC+1,F ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
343 movf PRODH,W ; ...
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
344 addwfc isr_xC+2,F ; propagate carry
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
345 clrf WREG ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
346 addwfc isr_xC+3,F ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
347 return ; done
0
heinrichsweikamp
parents:
diff changeset
348
heinrichsweikamp
parents:
diff changeset
349
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
350 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
351 ; Multiply two SIGNED 16 Bit Integers: isr_xC = isr_xA * isr_xB
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
352 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
353 ; trashes PRODL, PRODH, WREG
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
354 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
355 global isr_signed_mult16x16
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
356 isr_signed_mult16x16:
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
357 ; do an unsigned multiplication first
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
358 rcall isr_unsigned_mult16x16
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
359
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
360 ; manage sign extension of operand B
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
361 btfss isr_xB+1,7 ; is B negative ?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
362 bra isr_signed_mult_checkA ; NO - continue checking operand A
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
363 movf isr_xA+0,W ; YES - add -65536 * A
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
364 subwf isr_xC+2,F ; - ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
365 movf isr_xA+1,W ; - ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
366 subwfb isr_xC+3,F ; - ...
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
367 isr_signed_mult_checkA ; manage sign extension of operand B
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
368 btfss isr_xA+1,7 ; is A negative ?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
369 return ; NO - done
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
370 movf isr_xB+0,W ; YES - add -65536 * B
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
371 subwf isr_xC+2,F ; - ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
372 movf isr_xB+1,W ; - ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
373 subwfb isr_xC+3,F ; - ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
374 return ; - done
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
375
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
376 ;-----------------------------------------------------------------------------
0
heinrichsweikamp
parents:
diff changeset
377
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
378 END