2
votes

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.

1
Function prologues and epilogues are usually generated only by compilers, and nowadays even then they need tpo be explicitly enabled on some architectures. For a programmer writing some assembly its very unusual. So they are far from "must-have"Gunther Piez

1 Answers

-1
votes

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.