Reading a program's disassembly, I've noticed a pattern. When setting up a function's frame, the instruction enter
is rarely used. I also used compiler explorer with the latest GCC -- GCC does not use enter
but uses leave
.
Why isn't the instuction enter
used? Why do compilers use two or more instructions to preform an action that can be done in one instruction? (pushing rbp, saving rsp, and allocating on the stack using sub rsp
, rather than using enter 0x20, 0
). But leave
is used... is there something else that leave
does that I'm not aware of? As far as I know, leave
is equivalent to
mov ebp, esp
pop ebp
GCC uses leave
whereas MSVC does not. I don't understand why enter
is never used and leave
is sometimes used.