Fibonacci Tutorial
This tutorial prints Fibonacci numbers with the debug print-number interrupt.
int 0x90 prints the value currently in r1.
#const INT_PRINT_NUM, 0x90#const COUNT, 12
start: mov r0, 0 ; a = 0 mov r1, 1 ; b = 1 mov r4, 0 ; i = 0
loop: int INT_PRINT_NUM ; print current b
mov r2, r1 ; r2 = b add r2, r0 ; r2 = a + b (next) mov r0, r1 ; a = old b mov r1, r2 ; b = next
add r4, 1 ; i++ cmp r4, COUNT jne loop
halt: jmp haltHow it works
Section titled “How it works”r0andr1store the two latest Fibonacci values (aandb).- Each loop iteration prints
r1usingint 0x90. r2is a temporary register fora + b.- The pair shifts forward:
a = b,b = a + b. - The loop stops after
COUNTnumbers.
Build and run (CatLauncher)
Section titled “Build and run (CatLauncher)”Because this tutorial uses the debug print interrupt (0x90), you must pass --test-ints.
catasm fibonacci.cat -o fibonacci.bincatlaunch run --rom fibonacci.bin --test-intsExpected style of output (decimal + hex per line):
1 0x000000011 0x000000012 0x000000023 0x000000035 0x00000005...