Smaller instruction than "add esp, 4"
assembly, optimization, x86
Solution
pop edx
Or any other integer register you don't mind destroying.
This is what modern compilers actually do (clang and sometimes gcc) because it's often optimal for performance as well as code-size on modern CPUs.
An `add esp,4` after a `call` would force the CPU's stack engine to insert a stack-sync uop before doing the actual `add`. If you otherwise don't modify use ESP directly except with stack instructions (e.g. as part of an addressing mode) before the next push/pop/call/ret, then you saved a uop by using `pop`.
That cache line of stack memory is going to be hot in cache (making the load cheap) if any other stack instructions ran recently.
Problem
Me again. I'm having a lot of "add esp, 4" in my program and I'm trying to reduce its size. Is there any smaller instruction that can replace "add esp, 4" ?