please dont rip this site

Atmel AVR Microcontroller
Basic Math Code Library
for Square Roots

; Smallest code AVR Sqrt
; Target: All AVRs including AT90S1200
; June 1999, by Jack Tidwell
; Calculates the sqrt by subtracting an ODD number that self increments (by 2)
;	for each iteration. If the new ODD 'subber' is LESS than the previous
;	results, increment our root by 1, and loop again.
; Worst case is about 200us at 8mhz and less than 15us for 8 bit.
; Example sqrt(100)
;num     'odd_suber'     sqrt
;100     1               1
;99      3               2
;96      5               3
;91      7               4
;84      9               5
;75      11              6
;64      13              7
;51      15              8
;36      17              9
;19      19              10

so the sqrt(100) = 10

.def numlo = r16
.def numhi = r17
.def sqrt  = r18
.def suber = r24
.def suberh= r25

; enter with the 16 bit Number in r16,r17

Sqrt:
        clr     sqrt
        ldi     suber,1	; initialize the seed to be subtracted
        clr     suberh	;	for each iteration
loop:   sub     numlo,suber
        sbc     numhi,suberh
	brlo	exit
        inc     sqrt
        adiw    suber,2	; keep the number to subtract ODD.
        rjmp    loop
exit:   ret             ; the sqrt(num) on exit is stored in r18
;



file: /Techref/atmel/avr/sqrt16b-jt.htm, 1KB, , updated: 2007/9/14 18:15, local time: 2024/4/25 15:03,
TOP NEW HELP FIND: 
3.12.108.236: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://massmind.org/techref/atmel/avr/sqrt16b-jt.htm"> Atmel AVR, atmega, Microcontroller, embedded controller, math, 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 massmind.org!

 

Welcome to massmind.org!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .