Created
October 14, 2011 00:54
-
-
Save pedrofranceschi/1285964 to your computer and use it in GitHub Desktop.
Fibonacci calculation in 6502 processor assembly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Fibonacci calculator in 6502 asm | |
; by Pedro Franceschi (pedrohfranceschi@gmail.com) | |
; test it in http://www.6502asm.com/beta/index.html | |
; the accumulator in the end will hold the Nth fibonacci number | |
LDX #$01; x = 1 | |
STX $00; stores x | |
SEC; clean carry; | |
LDY #$07; calculates 7th fibonacci number (13 = D in hex) (CHANGE HERE IF YOU WANT TO CALCULATE ANOTHER NUMBER) | |
TYA; transfer y register to accumulator | |
SBC #$03; handles the algorithm iteration counting | |
TAY; transfer the accumulator to the y register | |
CLC; clean carry | |
LDA #$02; a = 2 | |
STA $01; stores a | |
loop: LDX $01; x = a | |
ADC $00; a += x | |
STA $01; stores a | |
STX $00; stores x | |
DEY; y -= 1 | |
BNE loop; jumps back to loop if Z bit != 0 (y's decremention isn't zero yet) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment