If you're looking for a 10bit squaring routine it can be done faster than using this multiply, see SQR_10
; Multiply 10bit by 10bit unsigned ; by Martin Sturm 2010 ; Tested over full range of 10bit input combinations ; ; a (10bit) = aH:aL (not modified) ; b (10bit) = bH:bL (not modified) ; aH:aL * bH:bL --> rH:rM:rL ; ; incorrect result if a or b has non-zero bits above the 10th ; unless optional ANDLW 0x03 is used ; ; Algorithm ; r = a*b ; r = 2^16*(aH*bH) + 2^8*(aH*bL + bH*aL) + aL*bL ; 2x2 2x8 2x8 8x8 ; all multiplications are unrolled ; ; 73 instructions, 57-73 cycles, 65 avg ; ; helper macro mmac MACRO A,bit, uH,uL BTFSC A,bit ADDWF uH,F RRF uH,F RRF uL,F ENDM MULT_10x10 MACRO aH,aL, bH,bL, rH,rM,rL LOCAL g1, g2, g3, g4 ; rM:rL = aL*bL [8x8 bit multiply] (36 cycles) CLRF rM CLRF rL CLRC MOVFW bL mmac aL,0, rM,rL mmac aL,1, rM,rL mmac aL,2, rM,rL mmac aL,3, rM,rL mmac aL,4, rM,rL mmac aL,5, rM,rL mmac aL,6, rM,rL mmac aL,7, rM,rL ; rH = aH*bH [2x2 bit multiply] (8 cycles) CLRF rH MOVFW bH ; multiplicand in W ; ANDLW 0x03 ; prevent errors if bH non-zero above 10th bit BTFSC aH,1 ; carry always clear by here ADDWF rH,F ; never sets carry RLF rH,F BTFSC aH,0 ADDWF rH,F ; rH:rM += aH*bL [2-bit x 8-bit] (7-15 cycles, avg 11) MOVFW bL ; multiplicand in W BTFSS aH,0 GOTO g1 ADDWF rM,F ; add bL SKPNC INCF rH,F g1 BTFSS aH,1 GOTO g2 CLRC RLF bL,W ; W now holds (2*bL & 0xFF) ADDWF rM,F ; add W to rM SKPNC INCF rH,F BTFSC bL,7 ; INCF rH,F ; add the upper bit of 2*bL g2 ; rH:rM += bH*aL [2-bit x 8-bit] (7-15 cycles, avg 11) MOVFW aL ; multiplicand in W BTFSS bH,0 GOTO g3 ADDWF rM,F ; add aL SKPNC INCF rH,F g3 BTFSS bH,1 GOTO g4 CLRC RLF aL,W ; W now holds (2*aL & 0xFF) ADDWF rM,F ; add W to rM SKPNC INCF rH,F BTFSC aL,7 ; INCF rH,F ; add the upper bit of 2*aL g4 ENDM
file: /Techref/microchip/math/mul/10x10ms.htm, 3KB, , updated: 2010/4/14 19:57, local time: 2024/11/20 04:25,
owner: MDS-gmail-IE8,
3.14.134.31:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://linistepper.com/techref/microchip/math/mul/10x10ms.htm"> PIC Microcontoller Math Method Multiply 10x10 bit from Martin Sturm</A> |
Did you find what you needed? |