please dont rip this site

SX Microcontroller Math Method

12 Bit Square Root

by Nikolai Golovchenko

;**********************************************************************
;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+18*6-2+7= 124 cycles all cases
;**********************************************************************
Sqrt12  clr     TEMPB0          ;clear all used
        clr     TEMPB1          ;temporary registers
        mov     W, #6           ;and setup counter
        mov     LOOPCNT, W      ;

        swap    ACCB0           ;Left justify
        mov     W, <>ACCB1      ;12bit value
        and     W, #$0f         ;in two byte
        or      ACCB0, W        ;accumulator
        mov     W, <>ACCB1      ;
        and     W, #$f0         ;
        mov     ACCB1, W        ;
Sqrt12a
        rl      ACCB1           ;shift next
        rl      ACCB0           ;two higher bits
        rl      TEMPB1          ;of input
        rl      ACCB1           ;to
        rl      ACCB0           ;TEMPB1
        rl      TEMPB1          ;

        mov     W, #$01         ;take current result (shifted 2 bits left)
        add     W, TEMPB0       ;and OR with 01 (test bit) - add clears C
        rl      TEMPB0          ;and reserve place for the next bit

        mov     W, TEMPB1-w     ;test substraction for borrow
        snb     C
        setb    TEMPB0.2        ;set next result bit if no borrow
        snb     C
        mov     TEMPB1, W       ;store substraction result if no borrow

        decsz   LOOPCNT         ;repeat untill all 6 bits will be found
        jmp     Sqrt12a

        clrb    C
        rr      TEMPB0          ;right
        mov     W, >>TEMPB0     ;justify the result
        mov     ACCB0, W        ;and copy to result register
        ret
;**********************************************************************
;Last updated 16Nov99

file: /Techref/scenix/lib/math/sqrt/sqrt12_sx.htm, 2KB, , updated: 2004/6/10 13:40, local time: 2024/11/5 13:37, owner: NG--944,
TOP NEW HELP FIND: 
18.220.6.168: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://sxlist.com/techref/scenix/lib/math/sqrt/sqrt12_sx.htm"> SX Microcontroller 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 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 sxlist.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .