I have been recently learning x86 assembly language via GNU Assembler on Ubuntu by the book Programming Ground UP at somewhere on the internet.
There are always 2 sections that's a "Must-Have" when creating a function:
At the beginning, it's considered to save old %ebp and set new frame pointer
pushl %ebp
movl %esp,%ebp
At the end, it's used to restore old %ebp and pop out return address
movl %ebp, %esp
popl %ebp
ret
please help me know what's really happen and what's that used for.
- Why they must copy the bottom-most stack pointer to %ebp to set a new frame pointer?
- And why the must copy back the %ebp to %esp when done ?
- When copy without ( )
is that just an address ?
Thanks.