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
LEAVE
instruction, which does not any operands, reverses the action of the previousENTER
instruction. TheLEAVE
instruction copies the contents of theEBP
register into theESP
register to release all stack space allocated to the procedure. Then it restores the old value of theEBP
register from the stack. This simultaneously restores theESP
register to its original value. A subsequentRET
instruction 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.