please dont rip this site

PIC Microcontoller Math Method


Multiply 16x8 bit from Dingbat

;--------------------------------------------------------------------+
;   Function: Math : Multiply 16bits by 8bits                        |
;--------------------------------------------------------------------|
;   Filename: M_MUL16x8.inc       |   Environment    : MPLAB         |
;   Version : 1                   |   Microcontroller: PIC16F8x*     |
;   Date    : 21/07/2003          |   OSC MHz/MIPS   : xx / xxx      |
;--------------------------------------------------------------------|
;   Author         : Dingbat                                         |
;   Company        : -                                               |
;   Files required : none                                            |
;--------------------------------------------------------------------|

; Unsigned 16*8 bit Multiply AA(16) * BB(8), Result (CC) is 24bit
; adapted from code found on www.piclist.com
;
; params 	
;	AA 0:1 (MSB:LSB) 	= number to multiply (16bit)
;	BB					= multiplier (8bit)
;   CC 0:3 (MSB:LSB)	= Product (24bit)
;
; Taking out the loops and inlining the code would save about 
; another 20-30 instructions

MUL16x8
	clrf	CC+0		;clear result
	clrf	CC+1		;
	clrf	CC+2		;
	movlw	.8		
	movwf	bitCount	;bit counter set @ number of bits in multiplier

mul_L1					;main loop here
	rlf		CC+2,f			;rotate result left (*2)
	rlf		CC+1,f			;
	rlf		CC+0,f			;
	bcf		CC+2,0			;clear LSB of result after rotation
	btfss	BB,7			;test msb of multipier
	goto	dontAdd			;if bit is clear then dont add
	movfw   AA+1      		;Add the 16 bits of AA to product
	addwf   CC+2,f      	;
	skpnc					;
	incf	CC+1,f			;
	movfw   AA				;
	addwf   CC+1,f      	;
	skpnc					;
	incf	CC+0,f			;
dontAdd
	rlf		BB,f			;rotate multiplier left
	decfsz	bitCount,f		;chk if finished all bits in multiplier
	goto	mul_L1

	return


+

Comments:


file: /techref/microchip/math/mul/16x8-d.htm, 3KB, , updated: 2007/6/26 09:47, local time: 2008/11/22 01:39,
TOP NEW HELP FIND: 
38.103.63.59:LOG IN
©2008 PLEASE DON'T RIP! DO: LINK / DIGG! / MAKE!

 ©2008 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!
<A HREF="http://piclist.org/techref/microchip/math/mul/16x8-d.htm"> PIC Microcontoller Math Method</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be reviewed) Just type in the box and press the Post button. (HTML welcomed!): 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: 
Did you find what you needed?

  PICList 2008 contributors:
o List host: MIT, Site host massmind.org, Top posters @20081122 Apptech, Jinx, Xiaofan Chen, olin piclist, Vitaliy, William \Chops\ Westfield, Tamas Rudnai, JonnyMac, Alan B. Pearce, Gerhard Fiedler,
* 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: Shultz Electronics, Timothy Weber, on-going support is MOST appreciated!
* Contributors: Richard Seriani, Sr.
  'What can I do?' - SiCKO

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .