@@ -0,0 +1,7 @@
+## Assemble
+
+ ../assembler/fvm-as fibo.asm fibo.bin
+## Run
+ ./fvm fibo.bin
@@ -1,13 +1,20 @@
- imm 40
+ ;; fibo(30)
+ imm 30
fibo rel call
+ ;; pop arguments and push return value to stack
pop rv
+ ;; call print_number (syscall number is 1)
imm 1 syscall
exit
fibo:
+ ;; setup stack pointer and base pointer
bp sp sbp
+ ;; get first argument
imm 2 bpick
+ ;; if (x > 2) then
imm 2 gt
.else rel jz
+ ;; return fibo(x - 2) + fibo(x - 1)
imm 1 sub
@@ -19,6 +26,7 @@ fibo:
srv
.end rel jmp
.else:
+ ;; else return 1
imm 1 srv
.end: