I've been learning Assembly and I have a fairly good grasp on how the stack works. However I am a bit confused about pushing the base and stack pointer to the stack. When pushing registers and expanding the 'stack frame' (subl $8, %esp for example) the stack makes room for 8 bytes or 2 longs. But when pushing %ebp, does this just make %ebp point to the top of the stack? And when doing [movl %esp, %ebp], does this just make %esp point to the same place as %ebp? Or is there actually an expansion occurring where the stack moves again to make room for the %esp and/or %ebp?
Asked
Active
Viewed 173 times
0
-
3`push %ebp` does not change `ebp`. It is used because `ebp` is a callee saved register, its value must be preserved. `push` itself makes room for the operand of course. The `movl %esp, %ebp` is just so you can remember the original value of `esp` in case you modify it later. – Jester May 17 '22 at 14:42
-
Ah okay I think I get it now, thanks so much! – MrRed May 17 '22 at 14:55