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: 2008/10/15 15:50,
TOP NEW HELP FIND: 
38.103.63.61: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://www.piclist.com/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 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 @20081015 Apptech, Jinx, Xiaofan Chen, olin piclist, Vitaliy, Alan B. Pearce, William \Chops\ Westfield, JonnyMac, Tamas Rudnai, 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

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .