Created
October 23, 2013 19:09
-
-
Save mertsalik/7124723 to your computer and use it in GitHub Desktop.
microlab experiment 3
This file contains hidden or 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
.org 4000 | |
LDS #$5F00 | |
LDAA #$9 ; i value | |
PSHA ; send param | |
JSR FIB ; sub routine result is in B reg | |
PULA ; get param | |
SWI | |
FIB TSX | |
LDAA 2,x ; get param | |
CMPA #$1 ; check if <= 1 | |
BLE RES | |
SUBA #$2 ; call fib(n-2) | |
PSHA ; send param | |
JSR FIB ; sub routine result is in B register | |
PULA ; get param | |
TSX | |
LDAA 2,x ; get param | |
PSHB ; save previous result | |
SUBA #$1 ; call fib(n-1) | |
PSHA ; send param | |
JSR FIB ; sub routine result is in B reg | |
PULA ; get param | |
ABA ; addition fib(n-2) + fib(n-1) (A <- A + B) | |
TAB ; store result in B reg | |
RTS ; return | |
RES TAB ; n (B <- A) | |
RTS ; return n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment