Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
03/24/04 18:32
Read: times


 
#67376 - RE: hex to decimal assembly
Responding to: ???'s previous message
I am quoting an email that gave me the concept or converting hex to bcd then I convert it to ASCII for serial transmission Please make the change as you require

From: "jr66a" <jonryan@indigo.ie>
Subject: Re: 8051 hex to decimal

The simplest algorithm to understand for converting hex to
decimal is to use subtraction. For example to convert an 8-bit number
to decimal first clear 3 working regs, these will be the hundreds,
tens and digits output registers. Then subtract 100 decimal (64 hex)
from the 8-bit number. For each successful subtraction increment the
hundreds register, Continue until remainder is less than 100 decimal,
then subtract 10s from the remainder and increment the tens register
with each successful subtraction. Once the remainder is less than 10
transfer this to the digits register. Add 30 hex to the three output
registers to convert to ASCII and send them to the PC.

e.g. convert EC hex to decimal (236 decimal)
Sub 64H, result = 88H and increment hundreds reg
Sub 64H, result = 24H and increment hundreds reg
Sub 0AH, result = 1AH and increment tens reg
Sub 0AH, result = 10H and increment tens reg
Sub 0AH, result = 06H and increment tens reg
Copy 06H to digits reg

Now hundreds reg = 02
Tens reg = 03
Digits reg = 06

Send 32, 33, 36, and CR or LF to the PC (I think 11H or 13H)

Converting a 16 bit number uses the same principle except now you
need 5 output digits and subtract 2710H, 03E8H, 0064H, 000Ah, and
copy the remainder.

Hope this helps.


List of 18 messages in thread
TopicAuthorDate
hex to decimal assembly            01/01/70 00:00      
   RE: hex to decimal assembly            01/01/70 00:00      
      RE: hex to decimal assembly            01/01/70 00:00      
         RE: hex to decimal assembly            01/01/70 00:00      
            RE: hex to decimal assembly            01/01/70 00:00      
               RE: hex to decimal assembly            01/01/70 00:00      
                  RE: hex to decimal assembly            01/01/70 00:00      
                     RE: hex to decimal assembly            01/01/70 00:00      
                        RE: hex to decimal assembly            01/01/70 00:00      
                           RE: hex to decimal assembly            01/01/70 00:00      
                              RE: hex to decimal assembly            01/01/70 00:00      
                           Back to basics            01/01/70 00:00      
                        RE: hex to decimal assembly            01/01/70 00:00      
   RE: hex to decimal assembly            01/01/70 00:00      
   RE: hex to decimal assembly            01/01/70 00:00      
      Forgot a few stuff, continuing on...            01/01/70 00:00      
         Number representations            01/01/70 00:00      
      Erm... Another correction to myself            01/01/70 00:00      

Back to Subject List