[A83] Re: HL to string


[Prev][Next][Index][Thread]

[A83] Re: HL to string




It can be extended to n byte integers. If you do this, you will want to
implement a more strict checking so that you don't keep track of more BCD
digits in the inner loop than you need to (i.e. only keep track of as many
that are not leading zeros). Doing this is where the primary savings comes
from over division (although the inherent operations are also a bit faster).
A thought about checking unpacked BCD digits in this manner: It might be
better to store the unpacked digits as $00, $10, $20, ..., $90. This way,
you add $30 to each in the loop (instead of $03). Something like (this is an
infinite loop just to show the general idea):

 ld a,[hl]
;if the next bit from the binary is set, then increment A here
loop:
 add a,[hl]
 add a,$30
 daa
 ld [hl],a
 sbc a,a
 and $10
 dec hl
 jr loop

Note that just shows adjusting all the BCD digits, not shifting the bit out
of the binary into the units BCD digit.


-----Original Message-----
From: assembly-83-bounce@lists.ticalc.org
[mailto:assembly-83-bounce@lists.ticalc.org]On Behalf Of Dan Weiss
Sent: Saturday, July 07, 2001 8:15 PM
To: assembly-83@lists.ticalc.org
Subject: [A83] Re: HL to string



Can the algorithm be extended to 4 byte integers?


>From: "Kirk Meyer" <kirk.meyer@colorado.edu>
>Reply-To: assembly-83@lists.ticalc.org
>To: <assembly-83@lists.ticalc.org>
>Subject: [A83] Re: HL to string
>Date: Sat, 7 Jul 2001 19:54:18 -0600
>
>
>You could use DivHLBy10 5 times and work from the end of the string back,
>storing the remainder each time to the output pointer and decrementing that
>pointer by 1. Another interesting method, however, is described at this
>link:
>http://conmael.ee.pitt.edu/courses/0142/hoelzeman/ee0142%20-%20ass10.htm
>I think it might be faster. Note that page shows for a byte, but the
>algorithm should be able to be extended to a word pretty easily. To change
>it, COUNT is originally 16, and you would have TENTHOUSANDS, THOUSANDS,
>HUNDREDS, TENS, and ONES slots. These could be stored in OP1, for example.




References: