ON 20100403@11:15:34 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/index.htm#40271.9691319444 Martin Sturm[MDS-gmail-IE8] Code:
; Multiply 10bit by 10bit unsigned ; by Martin Sturm ; 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 b has non-zero bits above the 10th ; unless optional ANDLW 0x03 is used ; ; with MULT_8x8 ; 74 instructions, 58-74 cycles, 66 avg ; ; r = a*b ; r = 2^16*(aH*bH) + 2^8*(aH*bL + bH*aL) + aH*bL ; 2x2 2x8 2x8 8x8 ; r = rH : rM : rL ; MULT_10x10 MACRO aH,aL, bH,bL, rH,rM,rL LOCAL g1, g2, g3, g4 MULT_8x8 aL, bL, rM,rL ; rM:rL <-- aL*bL ; 36 instr/cycles ; rH = aH*bH (2x2 bit multiply) CLRF rH MOVFW bH ; multiplicand in W ; ANDLW 0x03 ; prevent errors if bH non-zero above 10th bit CLRC BTFSC aH,1 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 ; rH <= 9 by here so this always clear carry 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 ENDMON 20100405@3:04:51 PM at page: On a web page you were interested in at: http://techref.massmind.org/techref/microchip/math/mul/10x10ms.htm# Martin Sturm[MDS-gmail-IE8] edited the page. Difference: http://techref.massmind.org/techref/diff.asp?url=H:\techref\microchip\math\mul\10x10ms.htm&version=0 ON 20100405@3:06:04 PM at page: On a web page you were interested in at: http://techref.massmind.org/techref/microchip/math/mul/10x10ms.htm# Martin Sturm[MDS-gmail-IE8] edited the page. Difference: http://techref.massmind.org/techref/diff.asp?url=H:\techref\microchip\math\mul\10x10ms.htm&version=1 ON 20100405@3:08:02 PM at page: On a web page you were interested in at: http://techref.massmind.org/techref/microchip/math/mul/10x10ms.htm# Martin Sturm[MDS-gmail-IE8] edited the page. Difference: http://techref.massmind.org/techref/diff.asp?url=H:\techref\microchip\math\mul\10x10ms.htm&version=2 ON 20100405@3:09:14 PM at page: On a web page you were interested in at: http://techref.massmind.org/techref/microchip/math/mul/10x10ms.htm# Martin Sturm[MDS-gmail-IE8] edited the page. Difference: http://techref.massmind.org/techref/diff.asp?url=H:\techref\microchip\math\mul\10x10ms.htm&version=3 ON 20100405@3:09:49 PM at page: On a web page you were interested in at: http://techref.massmind.org/techref/microchip/math/mul/10x10ms.htm# Martin Sturm[MDS-gmail-IE8] edited the page. Difference: http://techref.massmind.org/techref/diff.asp?url=H:\techref\microchip\math\mul\10x10ms.htm&version=4 ON 20100405@3:10:44 PM at page: On a web page you were interested in at: http://techref.massmind.org/techref/microchip/math/mul/10x10ms.htm# Martin Sturm[MDS-gmail-IE8] edited the page. Difference: http://techref.massmind.org/techref/diff.asp?url=H:\techref\microchip\math\mul\10x10ms.htm&version=5 ON 20100405@10:51:50 PM at page: On a web page you were interested in at: http://techref.massmind.org/techref/microchip/math/mul/10x10ms.htm# Martin Sturm[MDS-gmail-IE8] edited the page. Difference: http://techref.massmind.org/techref/diff.asp?url=H:\techref\microchip\math\mul\10x10ms.htm&version=6 ON 20100406@4:55:39 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/index.htm# Martin Sturm[MDS-gmail-IE8] I have agreed to maintain this page. ON 20100406@5:02:26 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/index.htm# Martin Sturm[MDS-gmail-IE8] change |Replace: '' with: '' ON 20100406@11:24:32 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/index.htm#40274.9753703704 Martin Sturm[MDS-gmail-IE8] Code:
; 16bit by 16bit unsigned multiply ; by Martin Sturm 2010 ; UNTESTED ; ; aH:aL * bH:bL --> r4:r3:r2:r1 ; ; t1 is a temporary variable, if b getting modified is ok, ; bL or bH can be used for t1 ; ; 140 instructions, 140 cycles ; ; helper macro mmac MACRO A,bit, r2,r1 BTFSS A,bit ADDWF r2,F RRF r2,F RRF r1,F ENDM MULT_16x16_FASTEST MACRO aH,aL, bH,bL, r4,r3,r2,r1, t1 ; 16x8 multiply aH:aL * bL -> r3:r4:r1 CLRF r3 CLRF r1 CLRC MOVFW bL mmac aL,0, r3,r1 mmac aL,1, r3,r1 mmac aL,2, r3,r1 mmac aL,3, r3,r1 mmac aL,4, r3,r1 mmac aL,5, r3,r1 mmac aL,6, r3,r1 mmac aL,7, r3,r1 CLRF r4 ; carry already clear from last RRF of mmac above ; bL still in W mmac aH,0, r3,r4 mmac aH,1, r3,r4 mmac aH,2, r3,r4 mmac aH,3, r3,r4 mmac aH,4, r3,r4 mmac aH,5, r3,r4 mmac aH,6, r3,r4 mmac aH,7, r3,r4 ; 16x8 multiply aH:aL * bH -> r4:t1:r2 ; middle byte from previous 16x8 multiplication starts in r4 ; but ends in r2 CLRF r2 MOVFW bH ; carry already clear from last RRF of mmac above CLRF t1 ; below MOVFW bH in case bH is used for t1 mmac aL,0, r4,r2 mmac aL,1, r4,r2 mmac aL,2, r4,r2 mmac aL,3, r4,r2 mmac aL,4, r4,r2 mmac aL,5, r4,r2 mmac aL,6, r4,r2 mmac aL,7, r4,r2 ; W still holds bH ; carry already clear from last RRF of mmac above mmac aH,0, r4,t1 mmac aH,1, r4,t1 mmac aH,2, r4,t1 mmac aH,3, r4,t1 mmac aH,4, r4,t1 mmac aH,5, r4,t1 mmac aH,6, r4,t1 mmac aH,7, r4,t1 ; add middle byte aH:aL * bH to upper byte of aH:aL * bL MOVFW t1 ADDWF r3 SKPNC INCF r4,F ENDMON 20100406@11:26:16 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/index.htm#40274.9765740741 Martin Sturm[MDS-gmail-IE8] Code:
; 16bit by 8bit unsigned multiply ; by Martin Sturm 2010 ; UNTESTED ; ; aH:aL * b --> r3:r2:r1 ; ; 69 instructions, 69 cycles ; ; helper macro mmac MACRO A,bit, r2,r1 BTFSS A,bit ADDWF r2,F RRF r2,F RRF r1,F ENDM MULT_16x8_FASTEST MACRO aH,aL, b, r3,r2,r1 CLRF r3 CLRF r1 CLRC MOVFW b mmac aL,0, r3,r1 mmac aL,1, r3,r1 mmac aL,2, r3,r1 mmac aL,3, r3,r1 mmac aL,4, r3,r1 mmac aL,5, r3,r1 mmac aL,6, r3,r1 mmac aL,7, r3,r1 CLRF r2 ; carry already clear from last RRF of mmac above ; b still in W mmac aH,0, r3,r2 mmac aH,1, r3,r2 mmac aH,2, r3,r2 mmac aH,3, r3,r2 mmac aH,4, r3,r2 mmac aH,5, r3,r2 mmac aH,6, r3,r2 mmac aH,7, r3,r2 ENDMON 20100407@6:41:36 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/index.htm#40275.7788888889 Martin Sturm[MDS-gmail-IE8] Says /techref/microchip/math/mul/m16x16mds.htm 16x16 bit from Martin Sturm (140 instructions, 140 cycles) ON 20100407@6:42:13 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/index.htm#40275.7793171296 Martin Sturm[MDS-gmail-IE8] Says /techref/microchip/math/mul/m16x8mds.htm 16x8 bit from Martin Sturm (69 instructions, 69 cycles) ON 20100407@6:42:17 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/index.htm# Martin Sturm[MDS-gmail-IE8] I have agreed to maintain this page. ON 20100407@6:44:13 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/m16x16mds.htm# Martin Sturm[MDS-gmail-IE8] edited the page. Difference: http://www.piclist.com/techref/diff.asp?url=H:\techref\microchip\math\mul\m16x16mds.htm&version=0 ON 20100407@6:45:15 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/m16x8mds.htm# Martin Sturm[MDS-gmail-IE8] edited the page. Difference: http://www.piclist.com/techref/diff.asp?url=H:\techref\microchip\math\mul\m16x8mds.htm&version=0 ON 20100407@6:45:36 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/m16x16mds.htm# Martin Sturm[MDS-gmail-IE8] edited the page. Difference: http://www.piclist.com/techref/diff.asp?url=H:\techref\microchip\math\mul\m16x16mds.htm&version=1 ON 20100407@6:47:14 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/m16x16mds.htm# Martin Sturm[MDS-gmail-IE8] edited the page. Difference: http://www.piclist.com/techref/diff.asp?url=H:\techref\microchip\math\mul\m16x16mds.htm&version=2 ON 20100407@6:49:24 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/m16x16mds.htm# Martin Sturm[MDS-gmail-IE8] edited the page. Difference: http://www.piclist.com/techref/diff.asp?url=H:\techref\microchip\math\mul\m16x16mds.htm&version=3 ON 20100407@6:49:59 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/m16x8mds.htm# Martin Sturm[MDS-gmail-IE8] I have agreed to maintain this page. ON 20100407@6:50:33 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/m16x8mds.htm# Martin Sturm[MDS-gmail-IE8] edited the page. Difference: http://www.piclist.com/techref/diff.asp?url=H:\techref\microchip\math\mul\m16x8mds.htm&version=2 ON 20100407@6:51:46 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/m16x8mds.htm# Martin Sturm[MDS-gmail-IE8] change |Replace: '' with: '' ON 20100407@6:52:01 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/m16x16mds.htm# Martin Sturm[MDS-gmail-IE8] change |Replace: '' with: '' ON 20100407@6:52:05 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/m16x16mds.htm# Martin Sturm[MDS-gmail-IE8] I have agreed to maintain this page. ON 20100407@6:52:21 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/m16x16mds.htm# Martin Sturm[MDS-gmail-IE8] edited the page. Difference: http://www.piclist.com/techref/diff.asp?url=H:\techref\microchip\math\mul\m16x16mds.htm&version=6 ON 20100407@6:52:23 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/m16x16mds.htm# Martin Sturm[MDS-gmail-IE8] change |Replace: '' with: '' ON 20100407@6:52:33 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/m16x8mds.htm# Martin Sturm[MDS-gmail-IE8] I have agreed to maintain this page. ON 20100407@6:52:52 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/m16x8mds.htm# Martin Sturm[MDS-gmail-IE8] edited the page. Difference: http://www.piclist.com/techref/diff.asp?url=H:\techref\microchip\math\mul\m16x8mds.htm&version=5 ON 20100407@6:54:47 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/index.htm# Martin Sturm[MDS-gmail-IE8] edited the page. Difference: http://www.piclist.com/techref/diff.asp?url=H:\techref\microchip\math\mul\index.htm&version=8 ON 20100407@6:58:21 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/index.htm# Martin Sturm[MDS-gmail-IE8] edited the page. Difference: http://www.piclist.com/techref/diff.asp?url=H:\techref\microchip\math\mul\index.htm&version=9 ON 20100407@6:58:58 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/index.htm# Martin Sturm[MDS-gmail-IE8] edited the page. Difference: http://www.piclist.com/techref/diff.asp?url=H:\techref\microchip\math\mul\index.htm&version=10 ON 20100407@7:25:18 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/10x10ms.htm# Martin Sturm[MDS-gmail-IE8] change |Replace: '' with: '' ON 20100407@7:25:27 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/10x10ms.htm# Martin Sturm[MDS-gmail-IE8] I have agreed to maintain this page. ON 20100407@7:25:50 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/m16x8mds.htm# Martin Sturm[MDS-gmail-IE8] edited the page. Difference: http://www.piclist.com/techref/diff.asp?url=H:\techref\microchip\math\mul\m16x8mds.htm&version=6 ON 20100407@7:26:05 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/m16x16mds.htm# Martin Sturm[MDS-gmail-IE8] I have agreed to maintain this page. ON 20100407@7:26:23 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/m16x16mds.htm# Martin Sturm[MDS-gmail-IE8] edited the page. Difference: http://www.piclist.com/techref/diff.asp?url=H:\techref\microchip\math\mul\m16x16mds.htm&version=9 ON 20100407@7:29:23 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/index.htm# Martin Sturm[MDS-gmail-IE8] edited the page. Difference: http://www.piclist.com/techref/diff.asp?url=H:\techref\microchip\math\mul\index.htm&version=11 ON 20100407@7:30:04 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/index.htm# Martin Sturm[MDS-gmail-IE8] edited the page. Difference: http://www.piclist.com/techref/diff.asp?url=H:\techref\microchip\math\mul\index.htm&version=12 ON 20100407@7:34:47 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/index.htm# Martin Sturm[MDS-gmail-IE8] change |Replace: '' with: '' ON 20100407@8:24:26 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/10x10ms.htm# Martin Sturm[MDS-gmail-IE8] edited the page. Difference: http://www.piclist.com/techref/diff.asp?url=H:\techref\microchip\math\mul\10x10ms.htm&version=9 ON 20100407@8:27:26 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/10x10ms.htm# Martin Sturm[MDS-gmail-IE8] edited the page. Difference: http://www.piclist.com/techref/diff.asp?url=H:\techref\microchip\math\mul\10x10ms.htm&version=10 ON 20100407@10:05:18 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/index.htm#40275.9203472222 Martin Sturm[MDS-gmail-IE8] Says /techref/microchip/math/mul/m14x10mds.htm 14x10 bit ON 20100407@10:05:27 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/index.htm# Martin Sturm[MDS-gmail-IE8] I have agreed to maintain this page. ON 20100407@10:07:33 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/index.htm# Martin Sturm[MDS-gmail-IE8] edited the page. Difference: http://www.piclist.com/techref/diff.asp?url=H:\techref\microchip\math\mul\index.htm&version=16 ON 20100407@10:09:18 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/m14x10mds.htm# Martin Sturm[MDS-gmail-IE8] edited the page. Difference: http://www.piclist.com/techref/diff.asp?url=H:\techref\microchip\math\mul\m14x10mds.htm&version=0 ON 20100407@10:09:47 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/m14x10mds.htm# Martin Sturm[MDS-gmail-IE8] edited the page. Difference: http://www.piclist.com/techref/diff.asp?url=H:\techref\microchip\math\mul\m14x10mds.htm&version=1 ON 20100407@10:10:02 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/m14x10mds.htm# Martin Sturm[MDS-gmail-IE8] edited the page. Difference: http://www.piclist.com/techref/diff.asp?url=H:\techref\microchip\math\mul\m14x10mds.htm&version=2 ON 20100407@10:10:34 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/m14x10mds.htm# Martin Sturm[MDS-gmail-IE8] edited the page. Difference: http://www.piclist.com/techref/diff.asp?url=H:\techref\microchip\math\mul\m14x10mds.htm&version=3 ON 20100407@10:11:09 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/index.htm# Martin Sturm[MDS-gmail-IE8] change |Replace: '' with: '' ON 20100408@11:11:22 AM at page: On a web page you were interested in at: http://www.piclist.com/microchip/math/mul/m16x8mds.htm#40276.3755439815 Martin Sturm[MDS-gmail-IE8] Published and replied to post 40276.3755439815 by dmcewa15 |Insert 'Thanks, I haven't though it through in great detail but my first thoughts are no, it won't work for either signed a or b.' at: '' dmcewa15@caledonian.ac.uk asks:
That looks like pretty nice code!|Delete 'P-' before: '' but after: '' with: '' ON 20100412@9:48:12 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/index.htm#40280.9084722222 Martin Sturm[MDS-gmail-IE8] Says /techref/microchip/math/mul/m16x8mds2.htm 16x8 bit ON 20100412@9:50:40 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/m16x8mds2.htm# Martin Sturm[MDS-gmail-IE8] edited the page. Difference: http://www.piclist.com/techref/diff.asp?url=H:\techref\microchip\math\mul\m16x8mds2.htm&version=0 ON 20100412@9:50:49 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/index.htm# Martin Sturm[MDS-gmail-IE8] I have agreed to maintain this page. ON 20100412@9:51:59 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/index.htm# Martin Sturm[MDS-gmail-IE8] edited the page. Difference: http://www.piclist.com/techref/diff.asp?url=H:\techref\microchip\math\mul\index.htm&version=24 ON 20100412@9:52:18 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/index.htm# Martin Sturm[MDS-gmail-IE8] change |Replace: '' with: '' ON 20100412@9:53:17 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/m16x8mds2.htm# Martin Sturm[MDS-gmail-IE8] edited the page. Difference: http://www.piclist.com/techref/diff.asp?url=H:\techref\microchip\math\mul\m16x8mds2.htm&version=1 ON 20100414@8:57:04 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/10x10ms.htm# Martin Sturm[MDS-gmail-IE8] edited the page. Difference: http://www.piclist.com/techref/diff.asp?url=H:\techref\microchip\math\mul\10x10ms.htm&version=13 ON 20100414@8:57:17 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/index.htm# Martin Sturm[MDS-gmail-IE8] I have agreed to maintain this page. ON 20100414@8:57:36 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/index.htm# Martin Sturm[MDS-gmail-IE8] edited the page. Difference: http://www.piclist.com/techref/diff.asp?url=H:\techref\microchip\math\mul\index.htm&version=27 ON 20100414@8:57:41 PM at page: On a web page you were interested in at: http://www.piclist.com/techref/microchip/math/mul/index.htm# Martin Sturm[MDS-gmail-IE8] change |Replace: '' with: ''
Surely it is a signed-unsigned multiply though? Where the a is signed and b is unsigned. It can be thought of as doing a 16*16 where the high byte of b is always 0.
Is this correct or am I not thinking properly?
Dave