test_dat equ -2478 org $1000 buf ds.b 7 ; to hold the decimal string org $1500 ldd #test_dat lds #$1500 ; initialize stack pointer ldy #buf cpd #0 bmi negate ; branch if the value is negative bne normal ; branch if the value is positive movb #$30,buf clr buf+1 ; terminate the string bra done negate coma ; when negative, complement the number comb ; " addd #1 ; " movb #$2D,1,y+ ; add minus sign and move pointer normal movb #0,1,-sp ; push a NULL into the stack loop ldx #10 idiv addb #$30 ; convert to ASCII code pshb ; push into stack cpx #0 ; is the quotient zero? beq reverse xgdx ; put quotient back to B bra loop reverse tst 0,sp beq done movb 1,sp+,1,y+ ; pop one byte and store it in buffer bra reverse done swi end