# PICMicrocontollerMathMethod

## Multiply 16x8 bit unsigned from Martin Sturm

Code:

• Martin Sturm shares this 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:

• dmcewa15TakeThisOuT at KILLspamcaledonian.ac.uk asks:
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/2/27 04:41, owner: MDS-gmail-IE8, TOP NEW HELP FIND:  3.236.145.153: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?Please DO link to this page! Digg it! / MAKE! PIC Microcontoller Math Method Multiply 16x8 bit from Martin Sturm

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.

Link? Put it here:
if you want a response, please enter your email address:
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
 Did you find what you needed? "No. I'm looking for: " "No. Take me to the search page." "No. Take me to the top so I can drill down by catagory" "No. I'm willing to pay for help, please refer me to a qualified consultant"

 PICList 2024 contributors: o List host: MIT, Site host massmind.org, Top posters @none found - Page Editors: James Newton, David Cary, and YOU! * Roman Black of Black Robotics donates from sales of Linistep stepper controller kits. * Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters. * Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated! * Contributors: Richard Seriani, Sr.

.