please dont rip this site

SX Microcontroller Radix Math Method


Binary to BCD half-packed 8 bit to 3 digit

From: Scott Dattalo, notes

Translated and optimized for the Scenix SX by Nikolai Golovchenko

;********************************
;binary_to_bcd - 8-bits
;
;Input
;  bin  - 8-bit binary number
;       A1*16+A0
;Outputs
; hundreds - the hundreds digit of the BCD conversion
; tens_and_ones - the tens and ones digits of the BCD conversion
binary_to_bcd:

        clr     hundreds
        mov     W, <>bin                ;w  = A0*16+A1
        add     W, bin                  ;w  = A0+A1
        and     W, #00001111b           ;w  = A0+A1 % 16

        mov     tens_and_ones, W        ;tens_and_ones = A0+A1 % 16
        mov     W, #$16
        snb     DC                      ;if A0+A1 > 16
        add     tens_and_ones, W        ;  tens_and_ones  += 16
        mov     W, #$06
        snb     DC                      ;if tens_and_ones % 16 > 10
        add     tens_and_ones, W        ;  tens_and_ones  += 6

        add     tens_and_ones, W        ;tens_and_ones  += 6
        sb      DC                      ;if tens_and_ones < 10
        sub     tens_and_ones, W        ;  tens_and_ones  -= 6

        mov     W, #$16 - 1 + $6
        snb     bin.4
        add     tens_and_ones, W
        mov     W, #-$06
        sb      DC
        add     tens_and_ones, W
        mov     W, #$30
        snb     bin.5
        add     tens_and_ones, W

        mov     W, #$20
        snb     bin.7
        add     tens_and_ones, W

        mov     W, #$60
        snb     bin.6
        add     tens_and_ones, W

        add     tens_and_ones, W

        rl      hundreds
        sb      hundreds.0
        sub     tens_and_ones, W

        snb     bin.7
        inc     hundreds




file: /techref/scenix/lib/math/radix/b2bhp-8b3d_sx.htm, 2KB, , updated: 2004/6/10 13:40, local time: 2008/12/5 02:26,
TOP NEW HELP FIND: 
38.103.63.58: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/scenix/lib/math/radix/b2bhp-8b3d_sx.htm"> SX Microcontroller Radix Math Method - Binary to BCD half-packed 8 bit to 3 digit</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 @20081205 Apptech, Jinx, Xiaofan Chen, olin piclist, Vitaliy, William \Chops\ Westfield, Tamas Rudnai, JonnyMac, Alan B. Pearce, 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

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .