please dont rip this site

PIC Microcontoller Math Method

Divide 24 bits by the constant value 6

From: Hughe

Divide a 24 bit number by 6 and round up if the remainder is 3 or more - can be used for any 8 bit constant divisor with 2 values changed.

	CBLOCK
		iA:3
		iB
		iC
	ENDC

DivBySix24:
		movlw	.24		; loop for 24 shifts
		movwf	iC		; iC is loop counter

		clrf	iB		; clear remainder reg

		bcf	STATUS,C	; clear result bit
DivBySixLoop:
		rlf	iA+0		; roll result bit onto iA
		rlf	iA+1
		rlf	iA+2
		rlf	iB		; and top bit of iA onto iB

		movlw	D'6'		; check if remainder (iB) >= 6
		subwf	iB,w		; w = iB-6
		btfss	STATUS,C	; carry set if iB >= 6
		  goto	DivBySixNogo

		movwf	iB		; iB-6 (w) into iB
					; the carry gets rolled onto iA as a result
DivBySixNogo:
		decfsz	iC,f		; loop until all bits checked
		  goto	DivBySixLoop
		rlf	iA+0		; roll last result bit onto A
		rlf	iA+1
		rlf	iA+2

	; the folowing could be left off if no rounding is required

		movlw	D'3'		; if remainder is 3 or more round up
		subwf	iB,w		; w = iB-3
		btfss	STATUS,C	; carry set if iB >= 3
		  return
		incf	iA+0,f		; increment Result
		btfsc	STATUS,Z
		  incf	iA+1,f
		btfsc	STATUS,Z
		  incf	iA+2,f

		return


file: /Techref/microchip/math/div/24byconst6-h.htm, 1KB, , updated: 2006/8/4 12:48, local time: 2024/11/5 17:11,
TOP NEW HELP FIND: 
3.231.219.178:LOG IN
©2024 PLEASE DON'T RIP! THIS SITE CLOSES OCT 28, 2024 SO LONG AND THANKS FOR ALL THE FISH!

 ©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!

<A HREF="http://www.piclist.com/techref/microchip/math/div/24byconst6-h.htm"> PIC Microcontoller Math Method Divide 24 bits by the constant value 6</A>

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?

  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.
 

Welcome to www.piclist.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .