Skip to content

Instantly share code, notes, and snippets.

@cassiebeckley
Created April 20, 2012 16:55
Show Gist options
  • Save cassiebeckley/2430271 to your computer and use it in GitHub Desktop.
Save cassiebeckley/2430271 to your computer and use it in GitHub Desktop.
DCPU-16 Fibonacci sequence
SET j, 0
SET x, 0 ; Fib 1
SET y, 1 ; Fib 2
SET c, 10 ; Maximum
SUB c, 1
SET a, x
JSR printnum
:fibloop
set a, y
JSR printnum
ADD x, y
XOR x, y
XOR y, x
XOR x, y
SUB c, 1
IFG c, 0
SET PC, fibloop
SET PC, end
:printnum
SET i, 0
:loop
SET b, a
MOD a, 10
SUB b, a
DIV b, 10
SET PUSH, a
ADD i, 1
SET a, b
IFG a, 0
SET PC, loop
:printloop
SET a, POP
ADD a, 0x1030
SET [0x8000+j], a
ADD j, 1
SUB i, 1
IFG i, 0
SET PC, printloop
ADD j, 1
SET PC, POP
:end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment