Created
May 13, 2012 18:49
-
-
Save Blecki/2689711 to your computer and use it in GitHub Desktop.
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
function fib(n) | |
{ | |
if (2 > n) return n; | |
return fib(n-1) + fib(n-2); | |
} | |
var a = fib(6); | |
Compiles too... | |
; var a = fib(6); | |
SET A, 0x0006 | |
JSR L1fib | |
SET PUSH, A | |
:L0main_footer | |
SUB PC, 0x0001 | |
;DCPUC FUNCTION fib L1fib 1 | |
; function fib(n) | |
:L1fib | |
; if (2 > n) | |
IFA 0x0002, A | |
; return n; | |
SET PC, POP | |
; return fib(n-1) + fib(n-2); | |
SET PUSH, A | |
SUB A, 0x0001 | |
JSR L1fib | |
SET PUSH, A | |
SET A, [0x0001+SP] | |
SUB A, 0x0002 | |
JSR L1fib | |
ADD A, POP | |
ADD SP, 0x0001 | |
SET PC, POP | |
:L2fib_footer | |
SET PC, POP | |
;END FUNCTION | |
:ENDOFPROGRAM |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment