So I'm trying to learn a little bit of assembly, because I need it for Computer Architecture class. I wrote a few programs, like printing the Fibonacci sequence.
I recognized that whenever I write a function I use those 3 lines (as I learned from comparing assembly code generated from gcc
to its C
equivalent):
pushq %rbp
movq %rsp, %rbp
subq $16, %rsp
I have 2 questions about it:
- First of all, why do I need to use
%rbp
? Isn't it simpler to use %rsp
, as its contents are moved to %rbp
on the 2nd line?
- Why do I have to subtract anything from
%rsp
? I mean it's not always 16
, when I was printf
ing like 7 or 8 variables, then I would subtract 24
or 28
.
I use Manjaro 64 bit on a Virtual Machine (4 GB RAM), Intel 64 bit processor
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…