Code:
; 16bit by 8bit unsigned multiply ; by Martin Sturm 2010 ; tested ; ; aH:aL * b --> r3:r2:r1 ; ; 69 instructions, 69 cycles ; ; helper macro mmac MACRO A,bit, u2,u1 BTFSC A,bit ADDWF u2,F RRF u2,F RRF u1,F ENDM MULT_16x8_FASTEST MACRO aH,aL, b, r3,r2,r1 CLRF r3 CLRF r1 CLRC MOVFW b ; comment out if 8bit multiplicand already in W ; also, b can be removed from macro arguments 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 ; 8bit multiplicand 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 ENDM
Questions:
That looks like pretty nice code!
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
Martin Sturm replies: 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.+
file: /Techref/microchip/math/mul/m16x8mds.htm, 2KB, , updated: 2013/7/22 11:51, local time: 2024/11/20 04:37,
owner: MDS-gmail-IE8,
18.189.182.233: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/m16x8mds.htm"> PIC Microcontoller Math Method Multiply 16x8 bit from Martin Sturm</A> |
Did you find what you needed? |