Megalextoria
Retro computing and gaming, sci-fi books, tv and movies and other geeky stuff.

Home » Digital Archaeology » Computer Arcana » Commodore » Commodore 8-bit » Assembly - Convert 16 bit integer to ascii help please
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Assembly - Convert 16 bit integer to ascii help please [message #209891 is a reply to message #32940] Fri, 31 May 2013 22:24 Go to previous messageGo to previous message
Anonymous
Karma:
Originally posted by: The Doctor

On Sat, 12 Jan 2013 07:56:32 -0800 (PST), JB <jbrown1289@gmail.com>
wrote:

> I am looking for a routine to convert a 16 bit integer into ascii (text)
>
> ex. convert $C000 (49152) to the characters "49152" stored in a memory address.
>
> I found one that almost does what I want, but it adds leading 0's.
>
> Ideally I would like to have a routine that you can pass an option to either print leading 0's or strip them. But first things first I guess. :)
>
>
>
> Here is that code:
>
> ;*
> ;* DECIMAL TO ASCII ROUTINE *
> ;* LOW-BYTE IN .X HI-BYTE IN .A
> ;* STORES ASCII STRING IN MEMORY
> ;* PRINTS PRECEDING 0'S
>
> DECIMAL STX BINARY
> STA BINARY+1
> LDY #0
> DEC1 LDX #"0"
> DEC2 LDA BINARY
> CMP DECTBL1,Y
> LDA BINARY+1
> SBC DECTBL2,Y
> BCC DEC3
> STA BINARY+1
> LDA BINARY
> SBC DECTBL1,Y
> STA BINARY
> INX
> BNE DEC2
> DEC3 TXA
> STA DECCHR,Y
> JSR $FFD2
> INY
> CPY #5
> BNE DEC1
> RTS
>
>
> DECTBL1 .BYTE <10000,<1000,<100
> .BYTE <10,<1
> DECTBL2 .BYTE >10000,>1000,>100
> .BYTE >10,>1
>
> DECCHR .WORD 0,0
> BINARY .WORD 0



I used to do a lot of deep assembly on the 64/1541. I was always
looking for speed and the way to get that is by using tables wherever
possible. Eliminate the looping and calculating.

It's been a long long time but I have no doubt there are routines to
accomplish this sitting on some old 5 1/4 floppys in storage. The
question is are the disks good anymore? They haven't been touched in
at least 20 years and they have suffered extremes of temperature.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: PTV-Newsletter 5/2013
Next Topic: THE MULTICART IS FINALLY READY!!!!!!
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sun Jan 29 03:22:08 EST 2023

Total time taken to generate the page: 0.00276 seconds