[A83] Re: Hex to decimal
[Prev][Next][Index][Thread]
[A83] Re: Hex to decimal
@ means local label. In Zilog I think the format may be . for local labels.
RLC rotates left circular (and through the carry).
ADC adds with carry.
DAA decimal adjusts A so that it remains BCD after an add.
Thus, the loop is taking C, and effectively multiplying it by 2. (RLC C)
It is taking the carry from this and putting it into A, while at the same
time multiplying it by 2. (ADC A,A)
It then decimally adjusts this addition to remain BCD.
It does this 8 times (# of bits in a byte), and it's now converted.
The code is pretty efficient. If you use yours at least eliminate the cp 0
(not needed). That first loop looks like it could use a bit of work... not
exactly efficient to use a loop to load a value or partial value like that.
If you only need values <19d, then the code I gave can be optimized more by
unrolling the loop and eliminating some instructions, but that's not really
necessary.
-----Original Message-----
From: assembly-83-bounce@lists.ticalc.org
[mailto:assembly-83-bounce@lists.ticalc.org]On Behalf Of Thomas Lutz
Sent: Monday, July 09, 2001 9:12 PM
To: assembly-83@lists.ticalc.org
Subject: [A83] Re: Hex to decimal
Not to sound stupid, but what exactly do rlc, adc, and daa do? I also assume
the @ sign is a different format than ZiLOG (I label using colon's). My code
seems to work...I just need it for values <19d, but I'd like to understand
this
code. Thanks a lot for your help and suggestions.
-Tom
Kirk Meyer wrote:
> If you actually want to transfer it to a floating point (i.e., OP1), then
> use SetXXOP1. Um, the code you gave doesn't even get to the second half of
> it. To convert into just a register (hex number has to be in the range 0
to
> 99), the following should work:
>
> ;Input: C = hex
> ;Output: A = decimal (0-99)
> ld b,8
> xor a
> @loop rlc c
> adc a,a
> daa
> djnz @loop
> ret
>
> This is if you wanted to convert a strictly hex number to decimal (i.e.
$1F
> to $31). You need a different routine to convert $14 to 14.
>
> -----Original Message-----
> From: assembly-83-bounce@lists.ticalc.org
> [mailto:assembly-83-bounce@lists.ticalc.org]On Behalf Of Thomas Lutz
> Sent: Monday, July 09, 2001 8:53 PM
> To: assembly-83@lists.ticalc.org
> Subject: [A83] Re: Hex to decimal
>
> Nevermind I figured it out...if anyone has any optimization suggestions
> feel free...
> Thanks..
> -Tom
>
> ;******************************
> ; Hex to decimal routine
> ;Inputs: A=1 less than number in hex
> ;C=number in decimal floating points format
> ;******************************
> HexToDecimal:
> ld b,9
> HexLoop:
> inc c
> dec a
> cp 0
> ret z ;Return if a=0
> djnz HexLoop
> ;c=9 now...increase first four bits, reset last four
> push af
> ld a,c
> and 11110000b
> add a,10h
> ld c,a
> ld b,9
> pop af
> jr HexLoop
>
> Thomas Lutz wrote:
>
> > What kind of code could I use for taking a hex value in the accumulator
> > and transfering it to a real variable in floating point format? Thanks.
> > -Tom
References: