please dont rip this site

PIC Microcontoller Math Method

12 Bit Square Root

;**********************************************************************
;by Nikolai Golovchenko
;12 bit SQARE ROOT
;Input:
;ACCB0 - high byte
;ACCB1 - low byte
;Result:
;ACCB0 - 6bit
;Used:
;TEMPB0 - temporary for result
;TEMPB1 - temporary for input
;LOOPCNT - counter
;Memory used
;32 instructions
;5 RAM bytes
;11+17*5 + 16 + 6 = 118 cycles all cases
;**********************************************************************
Sqrt12	clrf TEMPB0	;clear all used
	clrf TEMPB1	;temporary registers
	movlw 6		;and setup counter
	movwf LOOPCNT	;
	
	swapf ACCB0, f	;Left justify
	swapf ACCB1, w	;12bit value
	andlw 0x0f	;in two byte
	iorwf ACCB0, f	;accumulator
	swapf ACCB1, w	;
	andlw 0xf0	;
	movwf ACCB1	;
Sqrt12a
	rlf ACCB1, f	;shift next
	rlf ACCB0, f	;two higher bits
	rlf TEMPB1, f	;of input
	rlf ACCB1, f	;to
	rlf ACCB0, f	;TEMPB1
	rlf TEMPB1, f	;

	movf TEMPB0, w	;take current result (shifted 2 bits left)
	addlw 0x01	;and OR with 01 (test bit) - addlw clears C
	rlf TEMPB0, f	;and reserve place for the next bit

	subwf TEMPB1, w	;test substraction for borrow
	btfsc _C
	 bsf TEMPB0, 2	;set next result bit if no borrow
	btfsc _C
	 movwf TEMPB1	;store substraction result if no borrow

	decfsz LOOPCNT	;repeat untill all 6 bits will be found
	 goto Sqrt12a

	bcf _C
	rrf TEMPB0, f	;right
	rrf TEMPB0, w	;justify the result
	movwf ACCB0	;and copy to result register
	return
;**********************************************************************
;Last updated 16Nov99


file: /Techref/microchip/math/sqrt/sqrt12.htm, 1KB, , updated: 2001/11/7 06:27, local time: 2024/11/24 01:15,
TOP NEW HELP FIND: 
3.147.60.62: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!

<A HREF="http://ecomorder.com/techref/microchip/math/sqrt/sqrt12.htm"> PIC Microcontoller Math Method 12 Bit Square Root</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?

 

Welcome to ecomorder.com!

 

Welcome to ecomorder.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .