-
Notifications
You must be signed in to change notification settings - Fork 108
/
fib.s
40 lines (39 loc) · 748 Bytes
/
fib.s
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
35
36
37
38
39
40
.data
format:
.asciz "%llu \n"
.text
.global main
fib:
push %rbp
mov %rsp, %rbp
push %r14
push %rbx
mov %rdi, %r14
cmp $2, %rdi
jb fib_below_2
mov %rdi, %rbx
fib_2:
lea -1(%rbx), %rdi
call fib
add $-2, %rbx
add %rax, %r14
cmp $1, %rbx
ja fib_2
fib_below_2:
mov %r14, %rax
pop %rbx
pop %r14
pop %rbp
ret
main:
push %rbp
mov %rsp, %rbp
mov $47, %rdi # param 1 to fib
call fib # calling fib
lea format(%rip), %rdi
mov %rax, %rsi
xor %rax, %rax
call printf
xor %rax, %rax
pop %rbp
ret