aboutsummaryrefslogtreecommitdiff
path: root/examples/fibo.asm
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2024-12-07 18:02:04 +0800
committerMistivia <i@mistivia.com>2024-12-07 18:10:12 +0800
commit22b08dbf32e9c5de1f10c19897422168100fa639 (patch)
treeda09e02c8319917d96b0116600e905ebcbd5c0db /examples/fibo.asm
parent24dc16285d6b35d6da4733ac95d5d401f1b6c7b0 (diff)
add README for exmaples
Diffstat (limited to 'examples/fibo.asm')
-rw-r--r--examples/fibo.asm10
1 files changed, 9 insertions, 1 deletions
diff --git a/examples/fibo.asm b/examples/fibo.asm
index a1a3e82..7aa0cb9 100644
--- a/examples/fibo.asm
+++ b/examples/fibo.asm
@@ -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 2 bpick
imm 1 sub
fibo rel call
@@ -19,6 +26,7 @@ fibo:
srv
.end rel jmp
.else:
+ ;; else return 1
imm 1 srv
.end rel jmp
.end: