test_dat equ 34 org $1000 buf ds.b 4 ; to hold the decimal string temp ds.b 2 ; " org $1500 ldab #test_dat lds #$1500 ; initialize stack pointer ldy #buf tstb bne normal movb #$30,buf clr buf+1 ; terminate the string bra done normal movb #0,1,-sp ; push a NULL into the stack clra loop ldx #10 idiv addb #$30 ; convert to ASCII code pshb ; push into stack cpx #0 beq reverse xgdx ; put quotient back to B bra loop reverse tst 0,sp beq done movb 1,sp+,1,y+ bra reverse done swi end