please dont rip this site

SX Microcontroller Radix Math Method

Binary to ASCII, 16 bit to 5 digits (1 at a time) no temp register (!)

; by Rich Leggitt with tweaks by Scott Dattalo and bugfix by Dmitry Kiryashov and Nikolai Golovchenko and Ted Inoue.
; given 16 bit data in HI and LO, extract decimal digits
; requires one Output register called temp, HI and LO are destroyed.
; 42 instructions and less than 290 instructions executed
        clr     temp
        skip
sub10k  inc     temp
        mov     W, #10000 & 255
        sub     LO, W

;Scott Dattalo says:
;If you have a ram location that's known to be zero, then
;the following [the IF] can be replaced with [the ELSE]

IFNDEF known_zero
        mov     W, #10000 >> 8
        sb      C
        mov     W, #(10000 >> 8)+1
ELSE
	mov	W, << known_zero
        add     W, #(1000 >> 8) + 1
ENDIF
        sub     HI, W
        jc sub10k               ;11*7=77 inst in loop for 60900 (worst)
        output(temp);

        mov     W, #10
        mov     temp, W
add1K   dec     temp
        mov     W, #1000 & 255
        add     LO, W

;Scott Dattalo says:
;If you have a ram location that's known to be zero, then
;the following [the IF] can be replaced with [the ELSE]

IFNDEF known_zero
        mov     W, #1000 >> 8
        snb      C
        mov     W, #(1000 >> 8)+1
ELSE
	mov	W, << known_zero
        add     W, #1000 > > 8
ENDIF
        add     HI, W
        jnc add1k               ;10*10=100 inst in loop for 60900
        output(temp);

;Scott takes over here
        clr     temp
        mov     W, #100
        skip
sub100
        inc     temp
        sub     LO, W
        snb      C
        jmp     sub100

        dec     HI
        sb      HI.7    ;Check msb instead of carry for underflow.
        jmp     sub100  ;4 inst per loop to 200 then 7 per loop to 900.
                        ;Total 64(?) in loop for worst case

;at this point, HI = 0xff, and  0 <= LO <= 99

        output(temp)

        mov     W, #10
        mov     temp, W
add10   dec     temp
        add     LO, W
        jnc add10               ;40 inst in loop for worst case.
        output(temp);
        output(LO);
        ret


Comments:

Questions:


file: /Techref/scenix/lib/math/radix/b2a-16b5a-rl_sx.htm, 3KB, , updated: 2008/10/14 15:22, local time: 2024/10/31 17:07,
TOP NEW HELP FIND: 
52.15.91.44: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/radix/b2a-16b5a-rl_sx.htm"> SX Microcontroller Radix Math Method - Binary to ASCII, 16 bit to 5 digits (1 at a time) no temp register</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!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .