please dont rip this site

SX Microcontroller Math Method

24 bit Square Root binary restoring method

Andy David says:

Here's my 24-bit routine as written for the 17c43 [ed: and converted to Scenix SX] taken from a mail I sent Scott just after I wrote them, hence the comments about the implementations I used.

I did a few pencil-and-paper runs through the algorithm to be sure I understood the steps involved. This 24-bit resembles these 'manual' steps of shifting along the input string 2 bits at a time and subtracting - as the result is 12-bit, the final subtraction isn't awkward as in the 32-bit sqrt. I can't remember the performance figures for this routine, but I've just counted 348 min, 406 max (inc. call & return). A downside of this method is that the loop counter has to be a seperate variable, so it uses the same amount of ram as the 32-bit sqrt. This one is easier to follow and compare to an example on paper than the method I've used for the 32-bit sqrt.

I've added a 16-bit square root routine (again for the 17c43) that uses successive approximation to find the square root, the binary restoring method I'm fairly sure would be quicker. This is the only 16-bit sqrt routine I have specifically for the 17cxx PICs, I've only included it as the original poster requested a 16-bit routine. If you really want speed speed speed, I'd rewrite the 32-bit routine to be 16-bit.

Standard disclaimer applies


;==========================================================================
; brSQRT24
;
; Calculates the square root of a twentyfour bit number using the
; binary restoring method.
;
; Result in ACCaHI:ACCaLO
; Input in ACCcLO:ACCdHI:ACCdLO
; Test ACCbLO:ACCcHI
; Counter in ACCbHI
;
; 44 words long, uses 8 bytes RAM (inc. 3 holding 24-bit input).
;
;--------------------------------------------------------------------------
brSQRT24:
        clr     ACCaHI          ; clear result
        clr     ACCaLO          ;

        clr     ACCcHI          ; clear test bytes
        clr     ACCbLO          ;

        mov     W, #12          ; initialize counter
        mov     ACCbHI, W       ; (6 cycle intro, 9 incl. call)

ShftUp: rl      ACCdLO          ; Shift input up 2 places.
        rl      ACCdHI          ; (39 cycles per loop if bit is 0)
        rl      ACCcLO          ; (33 cycles per loop if bit is 1)
        rl      ACCcHI          ;
        rl      ACCbLO          ;
        rl      ACCdLO          ;
        rl      ACCdHI          ;
        rl      ACCcLO          ;
        rl      ACCcHI          ;
        rl      ACCbLO          ;

        rl      ACCaLO          ; Shift root-so-far up by two and append
        rl      ACCaHI          ; ... '01'.
        rl      ACCaLO          ;
        rl      ACCaHI          ;
        clrb    ACCaLO.1        ;
        setb    ACCaLO.0        ;

SubTest:
        mov     W, ACCaLO       ;
        sub     ACCcHI, W       ;
        mov     W, ACCaHI       ;
        sb      C               ;
        movsz   W, ++ACCaHI     ;
        sub     ACCbLO, W       ;

        snb     C               ;
        jmp     Set1            ;

        mov     W, ACCaLO       ; Restore the remainder.
        add     ACCcHI, W       ; ... (the current bit is 0).
        mov     W, ACCaHI       ;
        snb     C               ;
        movsz   W, ++ACCaHI     ;
        add     ACCbLO, W       ;
        jmp     Set0            ;

Set1:   setb    ACCaLO.1        ;
Set0:   rr      ACCaHI          ;
        rr      ACCaLO          ;
        clrb    ACCaHI.7        ;

BitLoop:
        decsz   ACCbHI          ;
        jmp     ShftUp

        ret


file: /Techref/scenix/lib/math/sqrt/sqrt24_sx.htm, 4KB, , updated: 2004/6/10 14:40, local time: 2024/3/28 09:26,
TOP NEW HELP FIND: 
18.213.110.162: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://www.sxlist.com/techref/scenix/lib/math/sqrt/sqrt24_sx.htm"> SX Microcontroller Math Method - 24 bit Square Root binary restoring method</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 sxlist.com!


Site supported by
sales, advertizing,
& kind contributors
just like you!

Please don't rip/copy
(here's why

Copies of the site on CD
are available at minimal cost.
 

Welcome to www.sxlist.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .