fibo.asm 457 B

12345678910111213141516171819202122232425
  1. ;; fibo(30)
  2. 30
  3. fibo rel call
  4. ;; pop arguments and push return value to stack
  5. pop rv
  6. ;; call print_number (syscall number is 1)
  7. 1 syscall
  8. exit
  9. fibo: ;; function fibo(x)
  10. ;; if (x > 2) then
  11. 0 ldarg 2 gt
  12. .else rel jz
  13. ;; return fibo(x - 2) + fibo(x - 1)
  14. 0 ldarg 1 sub
  15. fibo rel call
  16. pop rv
  17. 0 ldarg 2 sub
  18. fibo rel call
  19. pop rv add
  20. srv
  21. ret
  22. .else:
  23. ;; else return 1
  24. 1 srv
  25. ret