It's not fast however it's the shortest:
Code: Select all
; A = number (0-99)
ldx #ff
sec
- inx
sbc #10
bcs -
; A = lower digit (0-9), X=upper digit(0-9)
Even in the worst case (number is in the 90s) it's still reasonably fast. If you want to go up to 255, it's simple to add a quick check for a number greater than 200, then 100 before this code.
Code: Select all
; A = number (0-255)
ldy #0
cmp #200
bcc +
sbc #200
ldy #2 ; Range 200-255
bne ++
+ cmp #100
bcc ++
sbc #100 ; Range 100-199
iny
++
ldx #ff ; Conversion for lower 2 digits like before
sec
- inx
sbc #10
bcc -
; A = lower digit (0-9), X=middle digit(0-9), Y=upper digit (0-2)
If you have a 16-bit number then it becomes worth doing an actual division/modulo operation.
(Note this code is untested so don't copy/paste without understanding and blame me if you get bugs)