2

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.

Paul R
  • 208,748
  • 37
  • 389
  • 560
Little Jack
  • 558
  • 4
  • 14
  • 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 May 25 '11 at 13:33
  • preamble: http://stackoverflow.com/questions/1147623/trying-to-understand-the-main-disassembly-first-instructions – Ciro Santilli OurBigBook.com Oct 16 '15 at 07:07

1 Answers1

-2

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.

JdeBP
  • 2,127
  • 16
  • 24
  • THanks, the link is very useful. Perhaps, at 1st I didn't know what they call it. – Little Jack May 25 '11 at 14:45
  • 5
    I've downvoted this because it is effectively a link only answer that offers no information. If the link dies this answer is unusable. I'd remove the downvote if a summary of the information that answers the OPs specific question appeared directly in the answer – Michael Petch Aug 15 '16 at 13:56