Search code examples
assemblyx86stack-memorystack-pointer

pop or add esp, 4 ? What is the difference?


I saw this question, but I didn't find my answer in it..

So, why would I prefer to use add esp, 4 or add esp, 8 instead of using pop one or two times? Is there any difference (performance, safety, etc.) at all or it's a matter of personal choice?


Solution

  • pop does add esp, 4 too, it simply saves whatever there is on the top of the stack in its operand before. If you need what's on the stack probably pop is faster than mov wherever, [esp]; add esp, 4 but if you simply need to clear the stack add esp, 4 will be fine.