# SXMicrocontrollerMathMethod

## 16x16 multiplication from HI-TECH C library

posted to PICList Mon Aug 4 09:29:57 1997

Clyde Smith-Stubbs
HI-TECH Software,
http://www.htsoft.com/

```; Word multiplication for PIC 16C5x

#ifdef _PIC12
psect text,class=ENTRY,delta=2
#else
psect text,class=CODE,delta=2
#endif

global awmul,lwmul

; The main multiply thingo. Called with one operand in btemp and the
; other in btemp+2. It really doesn't matter which one is where.
; The multiplier is copied to plier, and the product built up in
; acca where it belongs

STATUS	equ	3
C	equ	0
Z	equ	2

lwmul
awmul
clr	prod	;initialize product
clr	prod+1
loop
clrb	C	;clear carry again
rr	plier+1	;shift multiplier down
rr	plier
sb	C	;skip if multiplier lsb not set
jmp	lop1
mov	W, btemp	;add multiplicand to product
mov	W, btemp+1
snb	C
mov	W, ++btemp+1
lop1
clrb	C	;clear carry
rl	btemp	;shift multiplicand up
rl	btemp+1
mov	W, plier
or	W, plier+1
sb	Z	;test for early return
jmp	loop
retw	#0	;done, result in prod

psect temp,global,class=BANK0,space=1,ovrld
btemp ds 2
plier ds 2
prod  ds 2

global used_btemp0
global used_btemp1
global used_btemp2
global used_btemp3
global used_btemp4
global used_btemp5

end
```

• OOPS
Looks like I made a mistake; on 16 bits it just generates an overflow. It would cause an error if the code is expanded to 24 bits as the resultant carry is lost in loading ++btemp+1 into w.

Peter (pjv)
+
• The HI-TECH C library 16x16 multiplication will produce an error anytime there is a carry out of btemp while the value in btemp+1 equals \$FF

Peter (pjv)+

 file: /Techref/scenix/lib/math/mul/16x16ht_sx.htm, 2KB, , updated: 2005/4/23 09:33, local time: 2024/9/16 03:08, TOP NEW HELP FIND:  98.82.120.188: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 Microcontroller Math Method 16x16 multiplication from HI-TECH C library

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.

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"

.