fib.c
lines 3 to 12 of 12
3
long
fib
(
long
n
)
{
4
if
(
n
<
2
)
5
return
n
;
6
return
fib
(
n
-
1
)
+
fib
(
n
-
2
)
;
7
}
8
9
int
main
(
void
)
{
10
printf
(
"%ld\n"
,
fib
(
5
)
)
;
11
return
0
;
12
}
disassembly
fib
10133
95
6
call
1013370
fib
10133
9a
mov
[rbp - 0x18], rax
7fffffffed88
2
10133
9e
mov
rdi, [rbp - 0x10]
7fffffffed90
4
10133
a2
sub
rdi, 2
rdi
2
10133
a6
call
1013370
fib
10133
ab
mov
rcx, rax
rdi
2
10133
ae
mov
rax, [rbp - 0x18]
10133
b2
add
rax, rcx
10133
b5
mov
[rbp - 8], rax
registers
stack
heap
code
data
rwx
read-only
rax
2
rbx
7fffffffee38
7fffffffefe8
"./steps"
rcx
1
rdx
7fffffffee48
0
rsi
7fffffffee38
7fffffffefe8
"./steps"
rdi
2
rbp
7fffffffeda0
7fffffffedd0
7fffffffedf0
7fffffffee20
0
rsp
7fffffffed78
10133ab
fib+59
r8
0
r9
0x800000
r10
0x800000
r11
0x346
838
r12
7fffffffee48
0
r13
0
r14
10133d0
main+0
r15
1
rip
10133a6
fib+54
cf
pf
af
zf
sf
IF
df
of
stack
six words from rsp · the frames they belong to
rsp
+0
7fffffffed
78
10133ab
fib+59
+8
7fffffffed
80
0
+10
7fffffffed
88
2
+18
7fffffffed
90
4
+20
7fffffffed
98
7ffff7ffd000
vdso+0
rbp
+28
saved rbp
7fffffffed
a0
7fffffffedd0
fib(2)
fib(4)
backtrace
the calls waiting · newest at the bottom
#0
fib+0
n=2
fib.c:3
#1
fib+59
n=4
fib.c:6
#2
fib+42
n=5
fib.c:6
#3
main+25
fib.c:10
#4
libc_start_main_stage2+45
__libc_start_main.c:95
#5
_start_c+0
crt1.c:15
calls of fib
each call a node · its result on its shoulder
main
5
4
3
2
2
1
1
1
0
0
1
1
2
moment 752 of 1999
The call pushed its return address, fib+59, on the stack.
That word is the new frame, and the frame is the node fib(2).