aboutsummaryrefslogtreecommitdiff
path: root/examples/fibo.asm
blob: 7aa0cb99366683401b46e370a5bda37a0cd5cee3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
    ;; 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
    pop rv
    imm 2 bpick
    imm 2 sub
    fibo rel call
    pop rv add
    srv
    .end rel jmp
.else:
    ;; else return 1
    imm 1 srv
    .end rel jmp
.end:
    bp ssp sbp
    ret