Question

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?

Était-ce utile?

La 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.

Autres conseils

There is indeed a matching ENTER (Art of Assembly Language) instruction. It's seldom used however, because it is very slow, as explained in the link.

There is enter, for some processors.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top