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.