Skip to content

Instantly share code, notes, and snippets.

@Blecki
Created May 13, 2012 18:49
Show Gist options
  • Save Blecki/2689711 to your computer and use it in GitHub Desktop.
Save Blecki/2689711 to your computer and use it in GitHub Desktop.
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