diff options
| author | Mistivia <i@mistivia.com> | 2024-12-07 22:54:12 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2024-12-07 22:54:12 +0800 |
| commit | 3e6bf6091cc32cf11d61c0250bde9115208ad5d5 (patch) | |
| tree | d451ea9afa53610fd98b574676b53d932994d130 /examples/fibo.asm | |
| parent | 22b08dbf32e9c5de1f10c19897422168100fa639 (diff) | |
simplify asm language
Diffstat (limited to 'examples/fibo.asm')
| -rw-r--r-- | examples/fibo.asm | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/examples/fibo.asm b/examples/fibo.asm index 7aa0cb9..5be4217 100644 --- a/examples/fibo.asm +++ b/examples/fibo.asm @@ -1,34 +1,25 @@ ;; fibo(30) - imm 30 + 30 fibo rel call ;; pop arguments and push return value to stack pop rv ;; call print_number (syscall number is 1) - imm 1 syscall + 1 syscall exit -fibo: - ;; setup stack pointer and base pointer - bp sp sbp - ;; get first argument - imm 2 bpick +fibo: ;; function fibo(x) ;; if (x > 2) then - imm 2 gt + 0 ldarg 2 gt .else rel jz ;; return fibo(x - 2) + fibo(x - 1) - imm 2 bpick - imm 1 sub + 0 ldarg 1 sub fibo rel call pop rv - imm 2 bpick - imm 2 sub + 0 ldarg 2 sub fibo rel call pop rv add srv - .end rel jmp + ret .else: ;; else return 1 - imm 1 srv - .end rel jmp -.end: - bp ssp sbp + 1 srv ret |
