annotate code_part1/OSTC_code_asm_part1/math.asm @ 120:5c7f98fad01a

aa_wordprocessor too fast ?
author JeanDo
date Sat, 11 Dec 2010 16:23:43 +0100
parents eff0da5cb975
children 64109f6fb3d1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
1 ; OSTC - diving computer code
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
2 ; Copyright (C) 2008 HeinrichsWeikamp GbR
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
3
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
4 ; This program is free software: you can redistribute it and/or modify
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
5 ; it under the terms of the GNU General Public License as published by
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
6 ; the Free Software Foundation, either version 3 of the License, or
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
7 ; (at your option) any later version.
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
8
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
9 ; This program is distributed in the hope that it will be useful,
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
10 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
11 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
12 ; GNU General Public License for more details.
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
13
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
14 ; You should have received a copy of the GNU General Public License
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
15 ; along with this program. If not, see <http://www.gnu.org/licenses/>.
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
16
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
17
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
18 ; Math routines
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
19 ; written by: Matthias Heinrichs, info@heinrichsweikamp.com
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
20 ; written: 10/30/05
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
21 ; last updated: 06/21/07
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
22 ; known bugs:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
23 ; ToDo: clean up!
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
24
88
heinrichsweikamp
parents: 74
diff changeset
25
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
26 convert_time: ; converts hi:lo in minutes to hours (hi) and minutes (lo)
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
27 movff lo,xA+0 ; divide by 60...
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
28 movff hi,xA+1 ;
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
29 movlw d'60' ;
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
30 movwf xB+0 ;
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
31 clrf xB+1 ;
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
32 rcall div16x16 ; xA/xB=xC with xA as remainder
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
33 movff xC+0,hi ; Hours
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
34 movff xA+0,lo ; =remaining minutes (0.....59)
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
35 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
36
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
37 div16:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
38 ; divA=divA/2^divB (divB: 8Bit only!)
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
39 bcf STATUS,C
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
40 rrcf divA+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
41 rrcf divA
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
42 decfsz divB
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
43 bra div16
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
44 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
45
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
46 div32:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
47 ; xC=xC(32Bit)/2^divB (divB: 8Bit only!)
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
48 bcf STATUS,C
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
49 rrcf xC+3
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
50 rrcf xC+2
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
51 rrcf xC+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
52 rrcf xC+0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
53 decfsz divB
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
54 bra div32
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
55 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
56
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
57 invert_xC:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
58 movf xC+1, w ; inverses xC+0:xC+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
59 sublw 0xFF
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
60 movwf xC+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
61 movf xC+0, w
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
62 bcf STATUS,C
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
63 sublw 0xFF
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
64 movwf xC+0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
65 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
66
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
67
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
68 sub16:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
69 ; sub_c = sub_a - sub_b
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
70 bcf neg_flag
74
a1ccb92b59cd 1.72beta release
heinrichsweikamp
parents: 0
diff changeset
71 movf sub_b+0, W ; Get Value to be subtracted
a1ccb92b59cd 1.72beta release
heinrichsweikamp
parents: 0
diff changeset
72 subwf sub_a+0, W ; Do the High Byte
a1ccb92b59cd 1.72beta release
heinrichsweikamp
parents: 0
diff changeset
73 movwf sub_c+0
a1ccb92b59cd 1.72beta release
heinrichsweikamp
parents: 0
diff changeset
74 movf sub_b+1, W ; Get the Value to be Subbed
a1ccb92b59cd 1.72beta release
heinrichsweikamp
parents: 0
diff changeset
75 subwfb sub_a+1, W
a1ccb92b59cd 1.72beta release
heinrichsweikamp
parents: 0
diff changeset
76 movwf sub_c+1
a1ccb92b59cd 1.72beta release
heinrichsweikamp
parents: 0
diff changeset
77 btfsc STATUS,C
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
78 return ; result positve
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
79 ; sub_c = sub_a - sub_b
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
80 bsf neg_flag ; result negative
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
81 movff sub_c+0,sub_b+0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
82 movff sub_c+1,sub_b+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
83 setf sub_a
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
84 setf sub_a+1
74
a1ccb92b59cd 1.72beta release
heinrichsweikamp
parents: 0
diff changeset
85 movf sub_b+0, W ; Get Value to be subtracted
a1ccb92b59cd 1.72beta release
heinrichsweikamp
parents: 0
diff changeset
86 subwf sub_a+0, W ; Do the High Byte
a1ccb92b59cd 1.72beta release
heinrichsweikamp
parents: 0
diff changeset
87 movwf sub_c+0
a1ccb92b59cd 1.72beta release
heinrichsweikamp
parents: 0
diff changeset
88 movf sub_b+1, W ; Get the Value to be Subbed
a1ccb92b59cd 1.72beta release
heinrichsweikamp
parents: 0
diff changeset
89 subwfb sub_a+1, W
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
90 movwf sub_c+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
91 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
92
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
93
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
94 mult16x16:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
95 ;xA*xB=xC
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
96 clrf xC+2 ; Clear the High-Order Bits
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
97 clrf xC+3
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
98 movf xA, w ; Do the "L" Multiplication first
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
99 mulwf xB
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
100 movf PRODL, w ; Save result
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
101 movwf xC
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
102 movf PRODH, w
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
103 movwf xC+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
104 movf xA, w ; Do the "I" Multiplication
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
105 mulwf xB+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
106 movf PRODL, w ; Save the Most Significant Byte First
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
107 addwf xC+1, f
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
108 movf PRODH, w
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
109 addwfc xC+2, f ; Add to the Last Result
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
110 movf xA+1, w ; Do the "O" Multiplication
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
111 mulwf xB
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
112 movf PRODL, w ; Add the Lower Byte Next
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
113 addwf xC+1, f
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
114 movf PRODH, w ; Add the High Byte First
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
115 addwfc xC+2, f
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
116 btfsc STATUS, C ; Add the Carry
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
117 incf xC+3, f
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
118 movf xA+1, w ; Do the "F" Multiplication
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
119 mulwf xB+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
120 movf PRODL, w
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
121 addwf xC+2, f
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
122 movf PRODH, w
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
123 addwfc xC+3, f
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
124 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
125
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
126
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
127 div16x16: ;xA/xB=xC with xA as remainder
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
128 ;uses divB as temp variable
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
129 clrf xC+0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
130 clrf xC+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
131 MOVF xB+0,W ; Check for zero
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
132 IORWF xB+1,W ;
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
133 BTFSC STATUS,Z ; Check for zero
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
134 RETLW H'FF' ; return 0xFF if illegal
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
135 MOVLW 1 ; Start count at 1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
136 MOVWF divB ; Clear Count
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
137 div16x16_1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
138 BTFSC xB+1,7 ; High bit set ?
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
139 bra div16x16_2 ; Yes then continue
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
140 INCF divB,F ; Increment count
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
141
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
142 bcf STATUS,C
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
143 rlcf xB+0,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
144 rlcf xB+1,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
145 bra div16x16_1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
146 div16x16_2:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
147 ; Shift result left
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
148 bcf STATUS,C
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
149 rlcf xC+0,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
150 rlcf xC+1,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
151
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
152 ; Reduce Divisor
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
153
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
154 MOVF xB,W ; Get low byte of subtrahend
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
155 SUBWF xA,F ; Subtract DST(low) - SRC(low)
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
156 MOVF xB+1,W ; Now get high byte of subtrahend
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
157 BTFSS STATUS,C ; If there was a borrow, rather than
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
158 INCF xB+1,W ; decrement high byte of dst we inc src
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
159 SUBWF xA+1,F ; Subtract the high byte and we're done
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
160
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
161
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
162 BTFSC STATUS, C ; Did it reduce?
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
163 bra div16x16_3 ; No, so it was less than
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
164
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
165 movf xB+0,W ; Reverse subtraction
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
166 addwf xA+0,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
167 movf xB+1,W
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
168 addwfc xA+1,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
169
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
170 bra div16x16_4 ; Continue the process
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
171 div16x16_3:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
172 BSF xC+0,0 ; Yes it did, this gets a 1 bit
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
173 div16x16_4:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
174 DECF divB,F ; Decrement N_COUNT
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
175 BTFSC STATUS,Z ; If its not zero then continue
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
176 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
177
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
178 bcf STATUS,C
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
179 rrcf xB+1,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
180 rrcf xB+0,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
181
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
182 bra div16x16_2 ; Next bit.
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
183
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
184 div32x16: ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
185 ; Setup
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
186 movlw .32 ; setup shift counter
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
187 movwf divB
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
188 movf xC+3,W ; move ACCb to ACCf
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
189 movwf xA+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
190 movf xC+2,W
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
191 movwf xA+0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
192 movf xC+1,W ; move ACCc to ACCe
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
193 movwf sub_a+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
194 movf xC+0,W
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
195 movwf sub_a+0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
196 clrf xC+3
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
197 clrf xC+2
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
198 clrf xC+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
199 clrf xC+0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
200 clrf sub_b+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
201 clrf sub_b+0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
202 div32x16_2
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
203 bcf STATUS,C
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
204 rlcf sub_a+0,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
205 rlcf sub_a+1,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
206 rlcf xA+0,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
207 rlcf xA+1,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
208 rlcf sub_b+0,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
209 rlcf sub_b+1,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
210 movf xB+1,W
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
211 subwf sub_b+1,W ; check if a>d
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
212 btfss STATUS,Z
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
213 goto div32x16_3
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
214 movf xB+0,W
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
215 subwf sub_b+0,W ; if msb equal then check lsb
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
216 div32x16_3
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
217 btfss STATUS,C ; carry set if d>a
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
218 goto div32x16_4
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
219 movf xB+0,W ; d-a into d
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
220 subwf sub_b+0,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
221 btfss STATUS,C
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
222 decf sub_b+1,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
223 movf xB+1,W
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
224 subwf sub_b+1,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
225 bsf STATUS,C ; shift a 1 into b (result)
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
226 div32x16_4
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
227 rlcf xC+0,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
228 rlcf xC+1,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
229 rlcf xC+2,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
230 rlcf xC+3,F
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
231 decfsz divB,F ; loop until all bits checked
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
232 goto div32x16_2
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
233 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
234
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
235
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
236 isr_div16:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
237 ; divA=divA/2^divB (divB: 8Bit only!)
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
238 bcf STATUS,C
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
239 rrcf isr_divA+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
240 rrcf isr_divA
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
241 decfsz isr_divB
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
242 bra isr_div16
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
243 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
244
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
245 isr_div32:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
246 ; xC=xC(32Bit)/2^divB (divB: 8Bit only!)
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
247 bcf STATUS,C
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
248 rrcf isr_xC+3
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
249 rrcf isr_xC+2
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
250 rrcf isr_xC+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
251 rrcf isr_xC+0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
252 decfsz isr_divB
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
253 bra isr_div32
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
254 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
255
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
256 isr_invert_xC:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
257 movf isr_xC+1, w ; inverses xC+0:xC+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
258 sublw 0xFF
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
259 movwf isr_xC+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
260 movf isr_xC+0, w
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
261 bcf STATUS,C
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
262 sublw 0xFF
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
263 movwf isr_xC+0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
264 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
265
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
266
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
267 isr_sub16:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
268 ; sub_c = sub_a - sub_b
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
269 bcf neg_flag_isr
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
270 movf isr_sub_b+0, w ; Get Value to be subtracted
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
271 subwf isr_sub_a+0, w ; Do the High Byte
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
272 movwf isr_sub_c+0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
273 movf isr_sub_b+1, w ; Get the Value to be Subbed
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
274 subwfb isr_sub_a+1, w
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
275 movwf isr_sub_c+1
74
a1ccb92b59cd 1.72beta release
heinrichsweikamp
parents: 0
diff changeset
276 btfsc STATUS,C
0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
277 return ; result positve
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
278 ; sub_c = sub_a - sub_b
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
279 bsf neg_flag_isr ; result negative
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
280 movff isr_sub_c+0,isr_sub_b+0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
281 movff isr_sub_c+1,isr_sub_b+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
282 setf isr_sub_a
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
283 setf isr_sub_a+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
284 movf isr_sub_b+0, w ; Get Value to be subtracted
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
285 subwf isr_sub_a+0, w ; Do the High Byte
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
286 movwf isr_sub_c+0
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
287 movf isr_sub_b+1, w ; Get the Value to be Subbed
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
288 subwfb isr_sub_a+1, w
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
289 movwf isr_sub_c+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
290 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
291
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
292
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
293 isr_mult16x16:
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
294 ;xA*xB=xC
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
295 clrf isr_xC+2 ; Clear the High-Order Bits
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
296 clrf isr_xC+3
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
297 movf isr_xA, w ; Do the "L" Multiplication first
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
298 mulwf isr_xB
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
299 movf PRODL, w ; Save result
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
300 movwf isr_xC
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
301 movf PRODH, w
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
302 movwf isr_xC+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
303 movf isr_xA, w ; Do the "I" Multiplication
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
304 mulwf isr_xB+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
305 movf PRODL, w ; Save the Most Significant Byte First
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
306 addwf isr_xC+1, f
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
307 movf PRODH, w
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
308 addwfc isr_xC+2, f ; Add to the Last Result
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
309 movf isr_xA+1, w ; Do the "O" Multiplication
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
310 mulwf isr_xB
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
311 movf PRODL, w ; Add the Lower Byte Next
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
312 addwf isr_xC+1, f
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
313 movf PRODH, w ; Add the High Byte First
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
314 addwfc isr_xC+2, f
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
315 btfsc STATUS, C ; Add the Carry
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
316 incf isr_xC+3, f
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
317 movf isr_xA+1, w ; Do the "F" Multiplication
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
318 mulwf isr_xB+1
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
319 movf PRODL, w
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
320 addwf isr_xC+2, f
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
321 movf PRODH, w
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
322 addwfc isr_xC+3, f
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
323 return
96a35aeda5f2 Initial setup
heinrichsweikamp
parents:
diff changeset
324