comparison code_part1/OSTC_code_asm_part1/math.asm @ 476:7779bfa89171

Cave bailout prediction.
author JeanDo
date Sun, 09 Oct 2011 23:37:59 +0200
parents 07f5b0baaa57
children 56da3e962e98
comparison
equal deleted inserted replaced
475:472bccc39aeb 476:7779bfa89171
85 negf sub_c+0 85 negf sub_c+0
86 btfsc STATUS,C ; Carry to propagate ? 86 btfsc STATUS,C ; Carry to propagate ?
87 incf sub_c+1,F ; YES: do it. 87 incf sub_c+1,F ; YES: do it.
88 88
89 return 89 return
90
91 ;=============================================================================
90 92
91 mult16x16: ;xA*xB=xC 93 mult16x16: ;xA*xB=xC
92 clrf xC+2 ; Clear the High-Order Bits 94 clrf xC+2 ; Clear the High-Order Bits
93 clrf xC+3 95 clrf xC+3
94 movf xA, w ; Do the "L" Multiplication first 96 movf xA, w ; Do the "L" Multiplication first
117 addwf xC+2, f 119 addwf xC+2, f
118 movf PRODH, w 120 movf PRODH, w
119 addwfc xC+3, f 121 addwfc xC+3, f
120 return 122 return
121 123
124 ;=============================================================================
122 125
123 div16x16: ;xA/xB=xC with xA as remainder 126 div16x16: ;xA/xB=xC with xA as remainder
124 ;uses divB as temp variable 127 ;uses divB as temp variable
125 clrf xC+0 128 clrf xC+0
126 clrf xC+1 129 clrf xC+1
174 bcf STATUS,C 177 bcf STATUS,C
175 rrcf xB+1,F 178 rrcf xB+1,F
176 rrcf xB+0,F 179 rrcf xB+0,F
177 180
178 bra div16x16_2 ; Next bit. 181 bra div16x16_2 ; Next bit.
182
183 ;=============================================================================
179 184
180 div32x16: ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder 185 div32x16: ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
181 ; Setup 186 ; Setup
182 movlw .32 ; setup shift counter 187 movlw .32 ; setup shift counter
183 movwf divB 188 movwf divB
204 rlcf sub_b+0,F 209 rlcf sub_b+0,F
205 rlcf sub_b+1,F 210 rlcf sub_b+1,F
206 movf xB+1,W 211 movf xB+1,W
207 subwf sub_b+1,W ; check if a>d 212 subwf sub_b+1,W ; check if a>d
208 btfss STATUS,Z 213 btfss STATUS,Z
209 goto div32x16_3 214 bra div32x16_3
210 movf xB+0,W 215 movf xB+0,W
211 subwf sub_b+0,W ; if msb equal then check lsb 216 subwf sub_b+0,W ; if msb equal then check lsb
212 div32x16_3 217 div32x16_3
213 btfss STATUS,C ; carry set if d>a 218 btfss STATUS,C ; carry set if d>a
214 goto div32x16_4 219 bra div32x16_4
215 movf xB+0,W ; d-a into d 220 movf xB+0,W ; d-a into d
216 subwf sub_b+0,F 221 subwf sub_b+0,F
217 btfss STATUS,C 222 btfss STATUS,C
218 decf sub_b+1,F 223 decf sub_b+1,F
219 movf xB+1,W 224 movf xB+1,W
223 rlcf xC+0,F 228 rlcf xC+0,F
224 rlcf xC+1,F 229 rlcf xC+1,F
225 rlcf xC+2,F 230 rlcf xC+2,F
226 rlcf xC+3,F 231 rlcf xC+3,F
227 decfsz divB,F ; loop until all bits checked 232 decfsz divB,F ; loop until all bits checked
228 goto div32x16_2 233 bra div32x16_2
229 return 234 return
230 235
231 ;============================================================================= 236 ;=============================================================================
232 ; u16 * u16 --> 32bit multiply (xA * xB --> xC) 237 ; u16 * u16 --> 32bit multiply (xA * xB --> xC)
233 ; Used in interupt service routines, to compute temperature and pressure. 238 ; Used in interupt service routines, to compute temperature and pressure.