I have been recently learning x86 assembly language via GNU Assembler on Ubuntu by th开发者_StackOverflowe 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.
This is a function perilogue. The Frequently Given Answer giving the gen on function perilogues explains what's happening, stack frames, and the frame pointer register.
精彩评论