Created
April 20, 2012 16:55
-
-
Save cassiebeckley/2430271 to your computer and use it in GitHub Desktop.
DCPU-16 Fibonacci sequence
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
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