00 C0 20 9B B7 A2 00 8A 4A A8 90 05 A9 3C 20 D2 FF A9 2D C0 00 F0 06 20 D2 FF
88 D0 FA 8A 4A B0 05 A9 3E 20 D2 FF A9 0D 20 D2 FF E8 E4 65 D0 D7 60
仍然比BASIC短很多;)255
由于计算机的自然整数只有8位,因此该位的最大数字范围最大。
用法:(SYS49152,[n]
例如SYS49152,3
,来自挑战的示例)
已评论拆解:
00 C0 .WORD $C000 ; load address
.C:c000 20 9B B7 JSR $B79B ; get unsigned byte from commandline
.C:c003 A2 00 LDX #$00 ; main loop counter
.C:c005 .loop:
.C:c005 8A TXA ; loop counter to accumulator
.C:c006 4A LSR A ; divide by 2, shift lowest bit to C
.C:c007 A8 TAY ; result to Y
.C:c008 90 05 BCC .toright ; C clear -> counter even, skip '<'
.C:c00a A9 3C LDA #$3C ; load character '<'
.C:c00c 20 D2 FF JSR $FFD2 ; output character
.C:c00f .toright:
.C:c00f A9 2D LDA #$2D ; load character '-'
.C:c011 C0 00 CPY #$00 ; counter/2 == 0 ? then no dashes
.C:c013 F0 06 BEQ .skipdashes
.C:c015 .printdashes:
.C:c015 20 D2 FF JSR $FFD2 ; output character
.C:c018 88 DEY ; decrement Y
.C:c019 D0 FA BNE .printdashes ; not 0 yet -> repeat
.C:c01b .skipdashes:
.C:c01b 8A TXA ; loop counter to accumulator
.C:c01c 4A LSR A ; shift lowest bit to C
.C:c01d B0 05 BCS .toleft ; C set -> counter odd, skip '>'
.C:c01f A9 3E LDA #$3E ; load character '>'
.C:c021 20 D2 FF JSR $FFD2 ; output character
.C:c024 .toleft:
.C:c024 A9 0D LDA #$0D ; load newline character
.C:c026 20 D2 FF JSR $FFD2 ; output character
.C:c029 E8 INX ; next loop iteration
.C:c02a E4 65 CPX $65 ; compare to command line argument
.C:c02c D0 D7 BNE .loop ; not reached yet -> repeat main loop
.C:c02e 60 RTS ; exit