8-bit HEX to BCD convertor
Written by Amol Shah, on Aug-2008
Views 825

This subroutine converts 8 bit Hexadecimal number into its equivalent BCD value. The number to be converted should be in the Accumulator. The output BCD number is stored in R0 & R1. R0 is used to save the MSB i.e. the hundreds place & R1 stores the LSB i.e. the Tens & Units place.

hextobcd:

                mov r0,#00h

                mov r1,#00h

                cjne a,#00h,c1_hextobcd             //If number is not 0 then continue

                ret

 

c1_hextobcd:

                clr c

                mov b,#100                                //First divide by 100

                div ab

                mov r0,a                                     //save MSB in R0

                clr c

                mov a,b

                mov b,#10                                  //Divide by 10   

                div ab

                swap a

                mov r1,a                                     //save the tens place in the Higher nibble of R1

                mov a,b

                orl a,r1

                mov r1,a                                     // save the tens place in the Lower nibble of R1

                ret



Add this page to your favorite Social Bookmarking websites
Reddit! Del.icio.us! JoomlaVote! Google! Live! Facebook! StumbleUpon! Yahoo! Free social bookmarking plugins and extensions for Joomla! websites!
Quote this article in website Favoured Print Send to friend Related articles Save this to del.icio.us

Users' Comments (0) RSS feed comment

No comment posted

Add your comment



mXcomment 1.0.5 © 2007-2009 - visualclinic.fr
License Creative Commons - Some rights reserved
 
< Prev   Next >
Home arrow Code Library arrow 8-bit HEX to BCD convertor