org $1000 data fdb 12345 ; place a number for testing org $1010 result rmb 5 ; reserve five bytes to store the result org $1500 ldd data ; make a copy of the number to be converted ldy #result ldx #10 ; divide the number by 10 idiv ; " addb #$30 ; convert to ASCII code stab 4,Y ; save the least significant digit xgdx ; swap the quotient to D ldx #10 idiv addb #$30 ; convert to ASCII code stab 3,Y ; save the second-to-least-significant digit xgdx ldx #10 idiv addb #$30 stab 2,Y ; save the middle digit xgdx ldx #10 idiv ; separate the most-significant and second-to-most- ; significant digits addb #$30 stab 1,Y ; save the second-to-most-significant digit xgdx ; swap the most significant digit to B addb #$30 ; convert to ASCII code stab 0,Y ; save the most significant digit swi end