Hi All,
This didn't turn into the mega-thread I expected.
Here's one that I use with my LCD display, it is from "6502 Software Design" by Leo J. Scanlon. Its purpose is to convert a byte into a three digit decimal number that gets printed on the display.
[code:1:23a4a2c25a]B2AD: LDX #$00 ;INITIALIZE HUNDREDS COUNTER
C100: CMP #100 ;BINARY VALUE = OR GREATER THAN 100?
BCC OUT1 ;NO. GO PRINT DECIMAL DIGIT
SBC #100 ;YES. SUBTRACT 100
INX ;INCREMENT DECIMAL COUNT
JMP C100 ; AND COMPARE AGAIN
OUT1: JSR PUTOUT ;GO PRINT DECIMAL DIGIT
LDX #00 ;INITIALIZE TENS COUNTER
C10: CMP #10 ;BINARY VALUE = OR GREATER THAN 10?
BCC OUT2 ;NO. GO PRINT DECIMAL DIGIT
SBC #10 ;YES. SUBTRACT 10
INX ;INCREMENT DECIMAL COUNT
JMP C10 ; AND COMPARE AGAIN
OUT2: JSR PUTOUT ;GO PRINT DECIMAL DIGIT
CLC ;CONVERT REMAINDER TO ASCII
ADC #$30 JMP PTROUT ;AND PRINT IT
RTSPUTOUT: PHA ;SAVE REMAINDER ON STACK
TXA ;MOVE DECIMAL COUNT TO ACCUMULATOR,
ADC #$30 ; CONVERT IT TO ASCII,
JSR PTROUT ; AND PRINT IT
PLA ;RETRIEVE REMAINDER
RTS
[/code:1:23a4a2c25a]
To call this routine, load the byte you want printed into the accumulator and JSR B2AD ("Binary to ASCII Decimal"). Theroutine will return three decimal digits in the accumulatorto a routine "PTROUT".
Anyone else have a good subroutine?