Answer the question
In order to leave comments, you need to log in
Why is the memory on the stack for the auto variable not reserved by rsp?
Why isn't memory reserved with rsp? What if an interrupt occurs? Or is there some trick here?
int main(void) {
int a = 5;
return 0;
}
main:
pushq %rbp
movq %rsp, %rbp
movl $5, -4(%rbp)
movl $0, %eax
popq %rbp
ret
void f(void){
;
}
int main(void) {
int a = 5;
f();
return 0;
}
f:
pushq %rbp
movq %rsp, %rbp
nop
popq %rbp
ret
main:
pushq %rbp
movq %rsp, %rbp
subq $16, %rsp
movl $5, -4(%rbp)
call f
movl $0, %eax
leave
ret
Answer the question
In order to leave comments, you need to log in
I'm not sure I understood the question correctly. Apparently, you do not understand why in the first example there is no analogue subq $16, %rsp
?
Because you don't have to. rsp is still not used by the main function, it would just be an extra couple of instructions.
In the second example, rsp needs to be configured because there is a call to f(), and it cannot be pushed onto the main() stack.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question