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 #33734 is a reply to message #33090] Fri, 18 January 2013 14:30 Go to previous messageGo to previous message
Anonymous
Karma:
Originally posted by: <fr>

I finally found some time to test it with an emulator, here is an updated
code.
Frederic

.ORG $C000
LDA #$04
LDX #$00
LDY #$01

;* DECIMAL TO ASCII ROUTINE *
;* LOW-BYTE IN .X HI-BYTE IN .A
;* STORES ASCII STRING IN MEMORY
;* Y=0 REMOVES LEADING 0'S
;* Y=1 PRINTS LEADING 0'S

DECIMAL:
STX BINARY
STA BINARY+1
STY DIGITS
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
BNE DEC4
CPY #4
BEQ DEC4
LDX DIGITS
BEQ DEC5
DEC4:
INC DIGITS
CLC
ADC #$30 ;* ASCII CODE FOR 0
JSR $FFD2
DEC5:
INY
CPY #5
BNE DEC1
RTS

DECTBL1:
.BYTE <10000,<1000,<100,<10,<1
DECTBL2:
.BYTE >10000,>1000,>100,>10,>1
BINARY:
.WORD 0
DECCHR:
.BYTE 0,0,0,0,0
DIGITS:
.BYTE 0 ;* NUMBER OF DIGITS IF Y=0
[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: Fri Mar 29 02:49:30 EDT 2024

Total time taken to generate the page: 0.00357 seconds