Optimized 117 bytes

This commit is contained in:
Michaelangel007 2017-07-05 19:38:09 -07:00
parent 7baae0bc3f
commit dbc87d60ed
3 changed files with 34 additions and 28 deletions

View File

@ -1,6 +1,6 @@
# Print unsigned 16-bit
6502 assembly code to print an unsigned 16-bit in 124 bytes ($7C).
6502 assembly code to print an unsigned 16-bit in 117 bytes ($75).
* No zero-page usage
@ -13,22 +13,21 @@ Copy/Paste into your favorite emulator.
```asm
0800:A9 12 A2 34 4C 07 08 8E
0808:81 08 8D 82 08 A9 00 8D
0810:6F 08 8D 77 08 8D 78 08
0818:8D 79 08 A2 10 F8 0E 81
0820:08 2E 82 08 A0 FD B9 7A
0828:07 79 7A 07 99 7A 07 C8
0830:D0 F4 CA D0 E9 D8 A0 03
0838:B9 77 08 20 5B 08 88 10
0840:F7 C8 CC 6F 08 F0 07 B9
0848:7B 08 C9 B0 F0 F3 B9 7B
0850:08 20 ED FD C8 CC 6F 08
0858:90 F4 60 48 4A 4A 4A 4A
0860:20 64 08 68 29 0F C9 0A
0868:90 02 69 06 69 B0 A2 00
0870:9D 7B 08 EE 6F 08 60 00
0878:00 00 00 00 00 00 00 00
0880:00 00 00
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
```

Binary file not shown.

View File

@ -1,3 +1,7 @@
; Michael Pohoreski
; Optimized from printm
; Thanks to qkumba for optimizations
; F8 ROM Entry Points
COUT = $FDED
SCRN2 = $F879
@ -41,23 +45,19 @@ _DoubleDabble ; Y=FD Y=FE Y=FF Y=00
CLD ; X=0 = output length
DecWidth
LDY #3 ; intentional buffer overflow - 8 digit output for special case of $0000
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
BCD2Chars
LDA _bcd,Y
LDA _bcd-1,Y
JSR HexA ; _output[0..7] = '?'
DEY
BPL BCD2Chars
BNE BCD2Chars
STX _len ; output buffer len = num digits to print
SkipLeadZero
INY
CPY _len
BEQ OutDigits
LDA _output,Y
CMP #'0' + $80 ; skip all leading zero's
BEQ SkipLeadZero
OutDigits
LDA _output,Y ; always print digit in "ones" place
JSR COUT
@ -77,7 +77,13 @@ HexA
PLA
AND #$F
_HexNib
BNE _HaveLeadingDigit ; If have leading zero and no output yet ...
CPX #0 ; ... then skip storing it
BEQ _HexAsciiDone
_HaveLeadingDigit
CMP #$A ; n < 10 ?
BCC _Hex2Asc
ADC #6 ; n += 6 $A -> +6 + (C=1) = $11
_Hex2Asc
@ -85,6 +91,7 @@ _Hex2Asc
PutChar
STA _output,X
INX ; X = output string length
_HexAsciiDone
RTS