Skip to content

Instantly share code, notes, and snippets.

@Blecki
Created April 17, 2012 04:21
Show Gist options
  • Save Blecki/2403424 to your computer and use it in GitHub Desktop.
Save Blecki/2403424 to your computer and use it in GitHub Desktop.
SET A, 0x0006
JSR L4fibonacci
SET X, A
IFE X, 0x0008
SET PC, L12THEN
SET A, L7_DATA
JSR L2print
SET PC, L13END
:L12THEN
SET A, L6_DATA
JSR L2print
:L13END
SET A, 0x0001
SET B, 0x0002
SET C, 0x0003
SET PUSH, 0x0004
SET PUSH, 0x0005
SET PUSH, 0x0006
SET PUSH, 0x0007
SET PUSH, 0x0008
JSR L8spill
ADD SP, 0x0005
SET X, A
IFE X, 0xFFEB
SET PC, L14THEN
SET A, L11_DATA
JSR L2print
SET PC, L15END
:L14THEN
SET A, L10_DATA
JSR L2print
:L15END
:L0main_footer
BRK
:L2print
SET PUSH, X
SET PUSH, Y
:L16BEGIN_WHILE
SET X, A
SET X, [X]
IFN X, 0x0000
SET PC, L17YES
SET PC, L18END_WHILE
:L17YES
SET X, A
SET X, [X]
IFE X, 0x000A
SET PC, L19THEN
SET X, 0x7000
SET Y, A
SET Y, [Y]
ADD X, Y
SET Y, [L1_STATIC_vram_ptr]
SET [Y], X
SET X, [L1_STATIC_vram_ptr]
ADD X, 0x0001
SET [L1_STATIC_vram_ptr], X
ADD A, 0x0001
SET PC, L20END
:L19THEN
ADD A, 0x0001
SET X, [L1_STATIC_vram_ptr]
ADD X, 0x0020
SET [L1_STATIC_vram_ptr], X
SET X, [L1_STATIC_vram_ptr]
SET Y, [L1_STATIC_vram_ptr]
MOD Y, 0x0020
SUB X, Y
SET [L1_STATIC_vram_ptr], X
:L20END
SET PC, L16BEGIN_WHILE
:L18END_WHILE
:L3print_footer
SET Y, POP
SET X, POP
SET PC, POP
:L4fibonacci
SET PUSH, X
SET PUSH, Y
SET X, A
IFG 0x0002, X
SET PC, L21THEN
SET PC, L22END
:L21THEN
SET X, A
SET A, X
SET PC, L5fibonacci_footer
:L22END
SET PUSH, A
SET A, PEEK
SUB A, 0x0001
JSR L4fibonacci
SET J, A
SET A, POP
SET X, J
SET PUSH, A
SET A, PEEK
SUB A, 0x0002
JSR L4fibonacci
SET J, A
SET A, POP
SET Y, J
ADD X, Y
SET A, X
SET PC, L5fibonacci_footer
:L5fibonacci_footer
SET Y, POP
SET X, POP
SET PC, POP
:L8spill
SET PUSH, X
SET PUSH, Y
SET PUSH, Z
SET PUSH, I
SET X, A
SET PUSH, B
SET PUSH, C
SET J, POP
MUL PEEK, J
ADD X, POP
SET PUSH, [0x0009+SP]
SET PUSH, [0x0009+SP]
SET J, POP
MUL PEEK, J
SUB X, POP
SET I, [0x0007+SP]
SET PUSH, [0x0006+SP]
DIV I, POP
ADD X, I
SET Z, [0x0005+SP]
SUB X, Z
SET Y, B
SET Z, C
DIV Y, Z
ADD X, Y
SET A, X
SET PC, L9spill_footer
:L9spill_footer
SET I, POP
SET Z, POP
SET Y, POP
SET X, POP
SET PC, POP
:L1_STATIC_vram_ptr DAT 0x8000
:L6_DATA DAT 0x0046, 0x0069, 0x0062, 0x006F, 0x006E, 0x0061, 0x0063, 0x0063, 0x0069, 0x0020, 0x0070, 0x0061, 0x0073, 0x0073, 0x0065, 0x0064, 0x000A, 0x0000
:L7_DATA DAT 0x0046, 0x0069, 0x0062, 0x006F, 0x006E, 0x0061, 0x0063, 0x0063, 0x0069, 0x0020, 0x0066, 0x0061, 0x0069, 0x006C, 0x0065, 0x0064, 0x000A, 0x0000
:L10_DATA DAT 0x0053, 0x0070, 0x0069, 0x006C, 0x006C, 0x0020, 0x0070, 0x0061, 0x0073, 0x0073, 0x0065, 0x0064, 0x000A, 0x0000
:L11_DATA DAT 0x0053, 0x0070, 0x0069, 0x006C, 0x006C, 0x0020, 0x0066, 0x0061, 0x0069, 0x006C, 0x0065, 0x0064, 0x000A, 0x0000
:ENDOFPROGRAM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment