> 6502.ProgTips.PrDecDemo   Print decimal numbers ( ===================== 2+ PrDec16 - print 16-bit decimal number <+ PrDec24 - print 24-bit decimal number F+ PrDec32 - print 32-bit decimal number P9 These can be optimised for specific implementations Z: d OS Entries: nOSWRCH=&FFEE x:  Memory locations: pad=&70:num=&71 : mc% 299 P=0 1 P%=mc%:O%=P% [OPT P*3+4 : !\ --------------------------- !\ Print 16-bit decimal number !\ --------------------------- #\ On entry num=number to print 6\ pad=0 or pad character (eg '0' or ' ') \ On entry at PrDec16Lp1 ;\ Y=(number of digits)*2-2, eg 8 for 5 digits '\ On exit A,X,Y,num,pad corrupted "\ Size 69 bytes ,G\ ----------------------------------------------------------------- 6 .PrDec16 @GLDY #8 :\ Offset to powers of ten J.PrDec16Lp1 TCLDX #&FF:SEC :\ Start with digit=-1 ^.PrDec16Lp2 hELDA num+0:SBC PrDec16Tens+0,Y:STA num+0 :\ Subtract current tens r+LDA num+1:SBC PrDec16Tens+1,Y:STA num+1 |=INX:BCS PrDec16Lp2 :\ Loop until <0 HLDA num+0:ADC PrDec16Tens+0,Y:STA num+0 :\ Add current tens back in +LDA num+1:ADC PrDec16Tens+1,Y:STA num+1 BTXA:BNE PrDec16Digit :\ Not zero, print it >LDA pad:BNE PrDec16Print:BEQ PrDec16Next :\ pad<>0, use it .PrDec16Digit BLDX #"0":STX pad :\ No more zero padding =A #"0" :\ Print this digit .PrDec16Print JSR OSWRCH .PrDec16Next CDEY:DEY:BPL PrDec16Lp1 :\ Loop for next digit RTS : .PrDec16Tens  EQUW 1  EQUW 10 & EQUW 100 0 EQUW 1000 :EQUW 10000 DG\ ----------------------------------------------------------------- N X b!\ --------------------------- l!\ Print 24-bit decimal number v!\ --------------------------- #\ On entry num=number to print 6\ pad=0 or pad character (eg '0' or ' ') \ On entry at PrDec24Lp1 <\ Y=(number of digits)*3-3, eg 21 for 8 digits '\ On exit A,X,Y,num,pad corrupted \ Size 98 bytes G\ -----------------------------------------------------------------  .PrDec24 GLDY #21 :\ Offset to powers of ten .PrDec24Lp1 CLDX #&FF:SEC :\ Start with digit=-1 .PrDec24Lp2 ELDA num+0:SBC PrDec24Tens+0,Y:STA num+0 :\ Subtract current tens +LDA num+1:SBC PrDec24Tens+1,Y:STA num+1  +LDA num+2:SBC PrDec24Tens+2,Y:STA num+2 =INX:BCS PrDec24Lp2 :\ Loop until <0  HLDA num+0:ADC PrDec24Tens+0,Y:STA num+0 :\ Add current tens back in *+LDA num+1:ADC PrDec24Tens+1,Y:STA num+1 4+LDA num+2:ADC PrDec24Tens+2,Y:STA num+2 >BTXA:BNE PrDec24Digit :\ Not zero, print it H>LDA pad:BNE PrDec24Print:BEQ PrDec24Next :\ pad<>0, use it R.PrDec24Digit \BLDX #"0":STX pad :\ No more zero padding f=A #"0" :\ Print this digit p.PrDec24Print zJSR OSWRCH .PrDec24Next CDEY:DEY:DEY:BPL PrDec24Lp1 :\ Loop for next digit RTS : .PrDec24Tens  EQUW 1 :EQUB 1 65536 !EQUW 10 :EQUB 10 65536 "EQUW 100 :EQUB 100 65536 #EQUW 1000 :EQUB 1000 65536 $EQUW 10000 :EQUB 10000 65536 %EQUW 100000 :EQUB 100000 65536 &EQUW 1000000 :EQUB 1000000 65536 'EQUW 10000000:EQUB 10000000 65536 G\ -----------------------------------------------------------------   $!\ --------------------------- .!\ Print 32-bit decimal number 8!\ --------------------------- B#\ On entry num=number to print L6\ pad=0 or pad character (eg '0' or ' ') V\ On entry at PrDec32Lp1 `=\ Y=(number of digits)*4-4, eg 36 for 10 digits j'\ On exit A,X,Y,num,pad corrupted t\ Size 129 bytes ~G\ -----------------------------------------------------------------  .PrDec32 GLDY #36 :\ Offset to powers of ten .PrDec32Lp1 CLDX #&FF:SEC :\ Start with digit=-1 .PrDec32Lp2 ELDA num+0:SBC PrDec32Tens+0,Y:STA num+0 :\ Subtract current tens +LDA num+1:SBC PrDec32Tens+1,Y:STA num+1 +LDA num+2:SBC PrDec32Tens+2,Y:STA num+2 +LDA num+3:SBC PrDec32Tens+3,Y:STA num+3 =INX:BCS PrDec32Lp2 :\ Loop until <0 HLDA num+0:ADC PrDec32Tens+0,Y:STA num+0 :\ Add current tens back in +LDA num+1:ADC PrDec32Tens+1,Y:STA num+1 +LDA num+2:ADC PrDec32Tens+2,Y:STA num+2  +LDA num+3:ADC PrDec32Tens+3,Y:STA num+3 BTXA:BNE PrDec32Digit :\ Not zero, print it >LDA pad:BNE PrDec32Print:BEQ PrDec32Next :\ pad<>0, use it (.PrDec32Digit 2BLDX #"0":STX pad :\ No more zero padding <=A #"0" :\ Print this digit F.PrDec32Print PJSR OSWRCH Z.PrDec32Next dCDEY:DEY:DEY:DEY:BPL PrDec32Lp1 :\ Loop for next digit nRTS x: .PrDec32Tens  EQUD 1  EQUD 10  EQUD 100  EQUD 1000 EQUD 10000 EQUD 100000 EQUD 1000000 EQUD 10000000 EQUD 100000000 EQUD 1000000000 G\ -----------------------------------------------------------------  ]: :  " "Enter test number: "A% , "Enter pad character: "B% 6. "PrDec16: ";:?pad=B%:!num=A%: PrDec16: @. "PrDec24: ";:?pad=B%:!num=A%: PrDec24: J. "PrDec32: ";:?pad=B%:!num=A%: PrDec32: T