Optimized down to 96 bytes

This commit is contained in:
Michaelangel007 2017-07-05 20:28:10 -07:00
parent 1e45852a50
commit 205f5e2132
3 changed files with 19 additions and 34 deletions

View File

@ -1,6 +1,6 @@
# Print unsigned 16-bit
6502 assembly code to print an unsigned 16-bit in 117 bytes ($75).
6502 assembly code to print an unsigned 16-bit in 96 bytes ($60).
* No zero-page usage
@ -13,21 +13,18 @@ Copy/Paste into your favorite emulator.
```asm
0800:A9 12 A2 34 4C 07 08 8E
0808:7A 08 8D 7B 08 A9 00 8D
0810:70 08 8D 71 08 8D 72 08
0818:A2 10 F8 0E 7A 08 2E 7B
0820:08 A0 FD B9 73 07 79 73
0828:07 99 73 07 C8 D0 F4 CA
0830:D0 E9 D8 A0 04 A9 B0 8D
0838:74 08 B9 6F 08 20 53 08
0840:88 D0 F7 8E 70 08 B9 74
0848:08 20 ED FD C8 CC 70 08
0850:90 F4 60 48 20 7B F8 20
0858:5D 08 68 29 0F D0 04 E0
0860:00 F0 0C C9 0A 90 02 69
0868:06 69 B0 9D 74 08 E8 60
0870:00 00 00 00 00 00 00 00
0878:00 00 00 00
0808:65 08 8D 66 08 A9 00 8D
0810:61 08 8D 62 08 8D 63 08
0818:A2 10 F8 0E 65 08 2E 66
0820:08 A0 FD B9 64 07 79 64
0828:07 99 64 07 C8 D0 F4 CA
0830:D0 E9 D8 A0 03 B9 60 08
0838:20 44 08 88 D0 F7 8A E0
0840:00 F0 11 60 48 20 7B F8
0848:20 4E 08 68 29 0F D0 04
0850:E0 00 F0 0C C9 0A 90 02
0858:69 06 69 B0 20 ED FD E8
0860:60 00 00 00 00 00 00
```

Binary file not shown.

View File

@ -45,25 +45,17 @@ _DoubleDabble ; Y=FD Y=FE Y=FF Y=00
CLD ; X=0 = output length
DecWidth
LDY #4 ; 6 digit output for special case of $0000
LDA #'0' + $80 ; handle special case input = $0000
STA _output ; since we always print at least 1 digit
LDY #3 ; maximum 6 digits output
BCD2Chars
LDA _bcd-1,Y
JSR HexA ; _output[0..7] = '?'
JSR HexA ; print 0, 1, or 2 hex digits
DEY
BNE BCD2Chars
STX _len ; output buffer len = num digits to print
TXA
CPX #0 ; Handle special case input = $0000 of no output
BEQ _HaveLeadingDigit
OutDigits
LDA _output,Y ; always print digit in "ones" place
JSR COUT
INY
CPY _len
BCC OutDigits
_PrintDone
RTS
@ -83,20 +75,16 @@ _HexNib
_HaveLeadingDigit
CMP #$A ; n < 10 ?
BCC _Hex2Asc
ADC #6 ; n += 6 $A -> +6 + (C=1) = $11
_Hex2Asc
ADC #'0' + $80 ; inverse=remove #$80
PutChar
STA _output,X
JSR COUT
INX ; X = output string length
_HexAsciiDone
RTS
_bcd ds 4 ; 6 chars for printing dec
_len = _bcd ; alias
_output ds 6 ; BCD -> 6 chars
_temp db 0,0