Skip to content

Instantly share code, notes, and snippets.

@KyleCartmell
Created May 13, 2018 15:05
Show Gist options
  • Select an option

  • Save KyleCartmell/a8df2c45fb3f728311657f3eea2b17a9 to your computer and use it in GitHub Desktop.

Select an option

Save KyleCartmell/a8df2c45fb3f728311657f3eea2b17a9 to your computer and use it in GitHub Desktop.
naive fizzbuzz in 6502 assembler
;;; Kyle's Amazing 6502 Fizzbuzz Program
LDA #0
STA $0000 ; the current iteration
STA $0001 ; always zero for comparisons
LDA #100
STA $0002 ; the end of the series
LDA #0
main_loop:
INC $0000
LDA $0000
LDY #3
JSR modulo
CMP $0001
BNE fizz_skip
LDA $0000
TAX
INC $0200,X
fizz_skip:
LDA $0000
LDY #5
JSR modulo
CMP $0001
BNE buzz_skip
LDA $0000
TAX
INC $0200,X
INC $0200,X
INC $0200,X
INC $0200,X
buzz_skip:
LDA $0000
CMP $0002
BNE main_loop
JSR end
;; preconditions:
;; - A contains dividend
;; - Y contains divisor
;; postconditions:
;; - A contains remainder
modulo:
STY $0010 ; move Y into memory so we can CMP it
modulo_loop:
CMP $0010
BCC modulo_done
SBC $0010
JMP modulo_loop
modulo_done:
RTS
end:
BRK
0200: 00 00 00 01 00 04 01 00 00 01 04 00 01 00 00 05
0210: 00 00 01 00 04 01 00 00 01 04 00 01 00 00 05 00
0220: 00 01 00 04 01 00 00 01 04 00 01 00 00 05 00 00
0230: 01 00 04 01 00 00 01 04 00 01 00 00 05 00 00 01
0240: 00 04 01 00 00 01 04 00 01 00 00 05 00 00 01 00
0250: 04 01 00 00 01 04 00 01 00 00 05 00 00 01 00 04
0260: 01 00 00 01 04 00 00 00 00 00 00 00 00 00 00 00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment