assemblyx86cdecl

Why is there no companion instruction to leave?


Why is there no companion instruction to leave on the x86? That way,

pushl   %ebp
movl    %esp,%ebp
pushl   $3
popl    %eax
leave
ret

could become:

enter #or something
pushl   $3
popl    %eax
leave
ret

Isn't that just faster in general?


Solution

  • In fact, there is an enter instruction. As to why it's not seeing much use, "IntelĀ® 64 and IA-32 Architectures Optimization Reference Manual" offers a hint:

    Assembly/ Compiler Coding Rule 32. (MH impact, M generality) Use push/pop to manage stack space and address adjustments between function calls/returns instead of enter/leave. Using enter instruction with non-zero immediates can experience significant delays in the pipeline in addition to misprediction.