PICMicrocontollerMathMethod

Multiply 16x16 bit signed from -Remove-malinSPAM at @spam@onspec.co.uk

```;malin@onspec.co.uk
;signed multiply of a2:a1 with b2:b1 leaving result in res4:res3:res2:res1
;	These 8 variables need to be defined, as does neg_flag
;
;	Program length	64 lines
;	time 134 to 248 cycles
;	This program looks at the lsb of a1 to decide whether to add b1 to res2
;
;   and b2 to res3, with appropriate carrys
;	It then looks at the lsb of a2 to decide whether to add b1 to res3 and
;	b2 to res4, again with appropriate carrys.
;	The rotates then only have to be done 8 times
;
;	This is uses slightly more program but takes a little less time than
;	a routine that performs one 16 bit addition per rotate and 16 rotates
;
;	Multiple byte addition routine from Microchip AN617
;	Result registers used as loop counter from Bob Fehrenbach & Scott Dattalo
;

clrf    res4
clrf	res3
clrf    res2
movlw	0x80
movwf	res1

clrf	neg_flag

btfss   a2,7
goto    a_pos
comf    a2,f
comf	a1,f
incf	a1,f
btfsc	status, zero
incf    a2,f
incf	neg_flag, f
a_pos
btfss   b2,7
goto    nextbit
comf    b2,f
comf    b1,f
incf    b1,f
btfsc   status, zero
incf    b2,f
incf	neg_flag, f

nextbit
rrf		a2,f
rrf		a1,f

btfss	status, carry
goto	nobit_l
movf	b1,w

movf	b2, w
btfsc	status, carry
incfsz	b2, w
btfsc	status, carry
incf	res4, f
bcf		status, carry

nobit_l
btfss	a1, 7
goto	nobit_h
movf	b1,w
btfsc	status, carry
incf	res4,f
movf	b2,w
nobit_h
rrf		res4,f
rrf		res3,f
rrf		res2,f
rrf		res1,f

btfss   status, carry
goto	nextbit
btfss   neg_flag, 0
goto 	no_invert

comf    res4,f
comf    res3,f
comf    res2,f
comf	res1,f

incf    res1,f
btfsc   status,zero
incf	res2,f
btfsc   status,zero
incf    res3,f
btfsc   status,zero
incf    res4,f
no_invert

```

 file: /Techref/microchip/math/mul/16x16malin.htm, 2KB, , updated: 2002/10/28 10:08, local time: 2024/2/26 16:14, TOP NEW HELP FIND:  3.237.34.21: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 16x16 bit Signed from malin

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"

 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.

.