please dont rip this site

Division of 16 bit by 8 bit integers with result in fixed point format Q16.16

;Division of 16bit by 8 bit with a result in Q16.16 form
;
; X_Int.X_Frac = X_Int / Y
;
; RAM - 6 bytes (1 temp):
; X_Int = X_IntH:X_IntL         16 bit input/ output integer part
; X_Frac = X_FracH:X_FracL      16 bit output fractional part
; Y                             divisor / temporary
; Counter                       counter
;
; Size = 39 instructions
; Execution time = 6+16*15-2+3+16*15-2+3+3(return)
; = 491 instruction cycles
;
; 8-July-2000 by Nikolai Golovchenko
; 16-February-2001 fixed, reduced execution time and temporaries

Div16by8to16_16

        clr     X_FracL
        clr     X_FracH
        mov     W, #16
        mov     Counter, W
        mov     W, Y    ;keep Y value in accumulator
        clr     Y       ;and use Y register as temporary

;Find integer part
Div16by8to16_16a

        rl      X_IntL  ;shift next msb into temporary
        rl      X_IntH
        rl      Y
        rl      Counter ;carry has 9th bit of temporary
                        ;copy carry to counter

        sub     Y, W    ;substract Y (in w) from temporary

        snc     ;if no borrow, set Counter.0
        setb    Counter.0

        sb      Counter.0       ;if Counter.0 clear (borrow) restore temporary
        add     Y, W

        clc     ;restore counter
        rr      Counter

;at this point carry is the next bit of result
        decsz   Counter ;repeat 16 times to find integer part
        jmp     Div16by8to16_16a

                        ;shift last integer bit
        rl      X_IntL
        rl      X_IntH

;Find fractional part
        setb    Counter.4       ;Counter = 16
Div16by8to16_16b
                        ;Shift zero bit into temporary
        rl      X_FracL
        rl      X_FracH
        rl      Y
        rl      Counter ;carry has 9th bit of temporary
                        ;copy carry to counter

        sub     Y, W    ;substract Y(in w) from temporary

        snc     ;if no borrow, set Counter.0
        setb    Counter.0

        sb      Counter.0       ;if Counter.0 clear (borrow) restore temporary
        add     Y, W

        clc     ;restore counter
        rr      Counter

        decsz   Counter ;repeat 16 times
        jmp     Div16by8to16_16b
                        ;shift last fractional bit
        rl      X_FracL
        rl      X_FracH

        mov     Y, W    ;restore divisor
        retp


file: /Techref/SCENIX/lib/math/div16by8to16_16.htm, 2KB, , updated: 2001/4/16 20:59, local time: 2024/12/27 00:36, owner: NG--944,
TOP NEW HELP FIND: 
3.137.186.26: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://sxlist.com/TECHREF/SCENIX/lib/math/div16by8to16_16.htm"> Division of 16 bit by 8 bit integers with result in fixed point format Q16.16</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!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .