annotate src/math.asm @ 654:75e90cd0c2c3

hwOS sport 10.77 release
author heinrichsweikamp
date Thu, 14 Mar 2024 16:56:46 +0100
parents 7d8a4c60ec1a
children
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 ;
654
75e90cd0c2c3 hwOS sport 10.77 release
heinrichsweikamp
parents: 643
diff changeset
7 ; Copyright (c) 2011, JD Gascuel, heinrichs weikamp gmbh, all right reserved.
0
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
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
349 ;=============================================================================
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
350 math12 CODE
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
351 ;=============================================================================
0
heinrichsweikamp
parents:
diff changeset
352
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
353 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
354 ; Multiply two SIGNED 16 Bit Integers: isr_xC = isr_xA * isr_xB
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
355 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
356 ; trashes PRODL, PRODH, WREG
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
357 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
358 global isr_signed_mult16x16
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
359 isr_signed_mult16x16:
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
360 ; do an unsigned multiplication first
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
361 call isr_unsigned_mult16x16
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
362
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
363 ; manage sign extension of operand B
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
364 btfss isr_xB+1,7 ; is B negative ?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
365 bra isr_signed_mult_checkA ; NO - continue checking operand A
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
366 movf isr_xA+0,W ; YES - add -65536 * A
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
367 subwf isr_xC+2,F ; - ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
368 movf isr_xA+1,W ; - ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
369 subwfb isr_xC+3,F ; - ...
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
370 isr_signed_mult_checkA: ; manage sign extension of operand B
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
371 btfss isr_xA+1,7 ; is A negative ?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
372 return ; NO - done
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
373 movf isr_xB+0,W ; YES - add -65536 * B
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
374 subwf isr_xC+2,F ; - ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
375 movf isr_xB+1,W ; - ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
376 subwfb isr_xC+3,F ; - ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
377 return ; - done
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
378
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
379 ;=============================================================================
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
380 math13 CODE
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
381 ;=============================================================================
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
382
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
383 ;-----------------------------------------------------------------------------
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
384 ; Multiply two UNSIGNED 24 Bit Integers: isr_xC = isr_xA * isr_xB
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
385 ;
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
386 ; trashes PRODL, PRODH, WREG
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
387 ;
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
388 global isr_unsigned_mult24x24
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
389 isr_unsigned_mult24x24:
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
390 call isr_unsigned_mult16x16 ; Do the 16x16 first
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
391 clrf isr_xC+4
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
392 clrf isr_xC+5 ; clear upper 16 bit
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
393 ; do the remaining three multiplications
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
394 movf isr_xA+0,W ; multiply a[0] * b[2]
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
395 mulwf isr_xB+2 ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
396 movf PRODL,W ; add cross product to c[4]:c[3]:c[2]
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
397 addwf isr_xC+2,F ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
398 movf PRODH,W ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
399 addwfc isr_xC+3,F ; propagate carry
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
400 clrf WREG ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
401 addwfc isr_xC+4,F ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
402 addwfc isr_xC+5,F ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
403
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
404 movf isr_xA+2,W ; multiply a[2] * b[0]
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
405 mulwf isr_xB+0 ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
406 movf PRODL,W ; add cross product to c[4]:c[3]:c[2]
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
407 addwf isr_xC+2,F ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
408 movf PRODH,W ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
409 addwfc isr_xC+3,F ; propagate carry
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
410 clrf WREG ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
411 addwfc isr_xC+4,F ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
412 addwfc isr_xC+5,F ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
413 ; isr_xC[2] done.
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
414
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
415 movf isr_xA+2,W ; multiply a[2] * b[1]
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
416 mulwf isr_xB+1 ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
417 movf PRODL,W ; add cross product to c[5]:c[4]:c[3]
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
418 addwf isr_xC+3,F ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
419 movf PRODH,W ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
420 addwfc isr_xC+4,F ; propagate carry
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
421 clrf WREG ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
422 addwfc isr_xC+5,F ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
423
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
424 movf isr_xA+1,W ; multiply a[1] * b[2]
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
425 mulwf isr_xB+2 ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
426 movf PRODL,W ; add cross product to c[5]:c[4]:c[3]
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
427 addwf isr_xC+3,F ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
428 movf PRODH,W ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
429 addwfc isr_xC+4,F ; propagate carry
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
430 clrf WREG ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
431 addwfc isr_xC+5,F ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
432 ; isr_xC[3] done.
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
433
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
434 movf isr_xA+2,W ; multiply a[2] * b[2]
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
435 mulwf isr_xB+2 ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
436 movf PRODL,W ; add cross product to c[5]:c[4]
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
437 addwf isr_xC+4,F ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
438 movf PRODH,W ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
439 addwfc isr_xC+5,F ; propagate carry
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
440 ; isr_xC[4] done.
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
441 ; isr_xC[5] done.
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
442
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
443 return ; done
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
444
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
445 ;=============================================================================
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
446 math14 CODE
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
447 ;=============================================================================
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
448
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
449 ;-----------------------------------------------------------------------------
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
450 ; Multiply two UNSIGNED Integers (32 and 24 Bit): isr_xC = isr_xA * isr_xB
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
451 ;
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
452 ; trashes PRODL, PRODH, WREG
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
453 ;
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
454 global isr_unsigned_mult32x24
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
455 isr_unsigned_mult32x24:
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
456 call isr_unsigned_mult24x24 ; Do the 24x24 first
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
457 clrf isr_xC+6 ; clear upper 8 bit
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
458 ; do the remaining three multiplications
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
459 movf isr_xA+3,W ; multiply a[3] * b[0]
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
460 mulwf isr_xB+0 ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
461 movf PRODL,W ; add cross product to c[5]:c[4]:c[3]
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
462 addwf isr_xC+3,F ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
463 movf PRODH,W ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
464 addwfc isr_xC+4,F ; propagate carry
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
465 clrf WREG ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
466 addwfc isr_xC+5,F ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
467 addwfc isr_xC+6,F ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
468 ; isr_xC[3] done.
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
469
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
470 movf isr_xA+3,W ; multiply a[3] * b[1]
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
471 mulwf isr_xB+1 ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
472 movf PRODL,W ; add cross product to c[5]:c[4]
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
473 addwf isr_xC+4,F ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
474 movf PRODH,W ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
475 addwfc isr_xC+5,F ; propagate carry
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
476 clrf WREG ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
477 addwfc isr_xC+6,F ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
478 ; isr_xC[4] done.
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
479
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
480 movf isr_xA+3,W ; multiply a[3] * b[2]
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
481 mulwf isr_xB+2 ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
482 movf PRODL,W ; add cross product to c[5]:c[4]
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
483 addwf isr_xC+5,F ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
484 movf PRODH,W ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
485 addwfc isr_xC+6,F ; propagate carry
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
486 ; isr_xC[5] done.
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
487 ; isr_xC[6] done.
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
488 return ; done
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
489
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
490
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
491 ;=============================================================================
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
492 math15 CODE
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
493 ;=============================================================================
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
494
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
495 ;-----------------------------------------------------------------------------
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
496 ; Multiply two SIGNED 24 Bit Integers: isr_xC = isr_xA * isr_xB
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
497 ;
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
498 ; trashes PRODL, PRODH, WREG
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
499 ;
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
500 global isr_signed_mult24x24
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
501 isr_signed_mult24x24:
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
502 ; do an unsigned multiplication first
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
503 call isr_unsigned_mult24x24
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
504
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
505 ; manage sign extension of operand B
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
506 btfss isr_xB+2,7 ; is B negative ?
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
507 bra isr_signed24_mult_checkA ; NO - continue checking operand A
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
508 movf isr_xA+0,W ; YES - add -16777216 * A
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
509 subwf isr_xC+3,F ; - ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
510 movf isr_xA+1,W ; - ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
511 subwfb isr_xC+4,F ; - ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
512 movf isr_xA+2,W ; - ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
513 subwfb isr_xC+5,F ; - ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
514 isr_signed24_mult_checkA: ; manage sign extension of operand B
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
515 btfss isr_xA+2,7 ; is A negative ?
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
516 return ; NO - done
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
517 movf isr_xB+0,W ; YES - add -16777216 * B
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
518 subwf isr_xC+3,F ; - ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
519 movf isr_xB+1,W ; - ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
520 subwfb isr_xC+4,F ; - ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
521 movf isr_xB+2,W ; - ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
522 subwfb isr_xC+5,F ; - ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
523 return
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
524
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
525 ;=============================================================================
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
526 math16 CODE
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
527 ;=============================================================================
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
528
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
529 ;-----------------------------------------------------------------------------
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
530 ; Divide two UNSIGNED 16 Bit Integers: isr_xC:2 = isr_xA:2 / isr_xB:2 with xA as remainder
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
531 ;
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
532 ; trashes WREG
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
533 ;
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
534 global isr_div16x16
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
535 isr_div16x16:
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
536 movlw .16 ; process 16 bits ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
537 movwf isr_math_loop ; ... initialize loop counter
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
538 movff isr_xA+0,isr_xC+0 ; copy isr_xA to isr_xC
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
539 movff isr_xA+1,isr_xC+1 ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
540 clrf isr_xA+0 ; clear isr_xA, will now be used to hold the remainder
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
541 clrf isr_xA+1 ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
542 isr_div16x16_1:
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
543 bcf STATUS,C ; clear carry flag to shift in a zero bit
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
544 rlcf isr_xC+0,F ; shift left isr_xC
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
545 rlcf isr_xC+1,F ; ... shifting MSB out of isr_xC...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
546 rlcf isr_xA+0,F ; ... and into LSB of isr_xA
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
547 rlcf isr_xA+1,F ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
548 btfsc STATUS,C ; did the remainder overflow (carry set)?
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
549 bra isr_div16x16_2 ; YES - directly generate a result bit = 1
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
550 movf isr_xB+0,W ; NO - compute remainder - divisor = isr_xA - isr_xB, trash result to WREG
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
551 subwf isr_xA+0,W ; - ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
552 movf isr_xB+1,W ; - ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
553 subwfb isr_xA+1,W ; - ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
554 btfss STATUS,C ; - remainder < divisor (-> borrow flag set, equals carry flag cleared) ?
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
555 bra isr_div16x16_3 ; YES - result bit = 0, keep LSB of isr_xC+0 being 0
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
556 isr_div16x16_2:
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
557 bsf isr_xC+0,0 ; NO - result bit = 1, set LSB of isr_xC+0 to 1
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
558 movf isr_xB+0,W ; - subtract divisor from remainder "for real": isr_xA = isr_xA - isr_xB
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
559 subwf isr_xA+0,F ; - ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
560 movf isr_xB+1,W ; - ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
561 subwfb isr_xA+1,F ; - ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
562 isr_div16x16_3:
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
563 decfsz isr_math_loop,F ; decrement loop counter, all bits done?
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
564 bra isr_div16x16_1 ; NO - loop
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
565 return ; YES - done
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
566
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
567 ;=============================================================================
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
568 math17 CODE
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
569 ;=============================================================================
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
570
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
571 ;-----------------------------------------------------------------------------
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
572 ; Divide a 32 Bit Integer by a 16 Bit Integer: isr_xC:4 = isr_xC:4 / isr_xB:2 with isr_xA as remainder
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
573 ;
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
574 ; trashes WREG
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
575 ;
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
576 global isr_div32x16
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
577 isr_div32x16:
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
578 movlw .32 ; process 32 bits ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
579 movwf isr_math_loop ; ... initialize loop counter
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
580 clrf isr_xA+0 ; clear isr_xA, will be used to hold the remainder
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
581 clrf isr_xA+1 ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
582 isr_div32x16_1:
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
583 bcf STATUS,C ; clear carry flag to shift in a zero bit
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
584 rlcf isr_xC+0,F ; shift left isr_xC
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
585 rlcf isr_xC+1,F ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
586 rlcf isr_xC+2,F ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
587 rlcf isr_xC+3,F ; ... shifting MSB out of isr_xC...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
588 rlcf isr_xA+0,F ; ... and into LSB of isr_xA
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
589 rlcf isr_xA+1,F ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
590 btfsc STATUS,C ; did the remainder overflow (carry set)?
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
591 bra isr_div32x16_2 ; YES - directly generate a result bit = 1
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
592 movf isr_xB+0,W ; NO - compute remainder - divisor = isr_xA - isr_xB, trash result to WREG
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
593 subwf isr_xA+0,W ; - ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
594 movf isr_xB+1,W ; - ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
595 subwfb isr_xA+1,W ; - ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
596 btfss STATUS,C ; - remainder < divisor (-> borrow flag set, equals carry flag cleared) ?
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
597 bra isr_div32x16_3 ; YES - result bit = 0, keep LSB of isr_xC+0 being 0
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
598 isr_div32x16_2:
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
599 bsf isr_xC+0,0 ; NO - result bit = 1, set LSB of isr_xC+0 to 1
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
600 movf isr_xB+0,W ; - subtract divisor from remainder "for real": isr_xA = isr_xA - isr_xB
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
601 subwf isr_xA+0,F ; - ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
602 movf isr_xB+1,W ; - ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
603 subwfb isr_xA+1,F ; - ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
604 isr_div32x16_3:
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
605 decfsz isr_math_loop,F ; decrement loop counter, all bits done?
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
606 bra isr_div32x16_1 ; NO - loop
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
607 return ; YES - done
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
608
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
609
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 628
diff changeset
610 ;-----------------------------------------------------------------------------
0
heinrichsweikamp
parents:
diff changeset
611
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 275
diff changeset
612 END