4 ms·
You need to restore the stack to what it was before on return. Normally you can easily do that because you know the stack pointer delta at compile time. But whe
by ssp 17y ago
You need to restore the stack to what it was before on return. Normally you can easily do that because you know the stack pointer delta at compile time. But when realigning at runtime, you don't, so you need to compute the difference and then store that somewhere, and on return you have to read that back and add it to the stack pointer.
Or is there some trick that I'm missing?
- jedbrown 17y agoIt's in the frame pointer. Edit: You're right, optimized code might not save the frame pointer and this wouldn't provide any benefit if your frame had unknown size. But usually the preamble saves the old ESP in EBP and it is restored at the end. Maybe there is another alternative.
- ssp 17y agoHmm, I was actually about to edit my comment to say that you are right because usually you'll store the old stack pointer as the new base pointer. I guess the answer is that realigning at runtime costs a register, but most code has to pay that cost anyway.