I don't see what I am doing wrong, this is my C code:
main() {
int i = 0;
if (i == 0) i++;
return 0;
}
Compiling with gcc -S test.c
I was expecting "leave" instead of "popq %rbp".
.L2:
movl $0, %eax
popq %rbp
ret
I don't see what I am doing wrong, this is my C code:
main() {
int i = 0;
if (i == 0) i++;
return 0;
}
Compiling with gcc -S test.c
I was expecting "leave" instead of "popq %rbp".
.L2:
movl $0, %eax
popq %rbp
ret
I don't see what I am doing wrong
It's up to GCC to decide if it uses ENTER/LEAVE.
Since even INTEL deprecates the use of ENTER/LEAVE it's no wonder GCC doesn't use it (anymore).
Also movq %rbp,%rsp wasn't needed here and so you only found popq %rbp.
Intel64 and IA-32 Architectures Software Developer's Manual says:
The
LEAVEinstruction, which does not any operands, reverses the action of the previousENTERinstruction. TheLEAVEinstruction copies the contents of theEBPregister into theESPregister to release all stack space allocated to the procedure. Then it restores the old value of theEBPregister from the stack. This simultaneously restores theESPregister to its original value. A subsequentRETinstruction then can remove any arguments and the return address pushed on the stack by the calling program for use by the procedure.
and gcc do this manually.