1

Below posted is my code. Help me out in understanding what the below code means:

   push    ebp
   mov     ebp, esp
   sub     esp, 230h
Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
ramu ranga
  • 57
  • 4
  • Related: http://stackoverflow.com/questions/20695203/behaviour-of-ebp-and-esp-in-stacks-using-function-with-parameter – nrz Oct 31 '14 at 22:53
  • Possible duplicate of [why to use ebp in function prologue/epilogue?](http://stackoverflow.com/questions/15655553/why-to-use-ebp-in-function-prologue-epilogue) – Peter Cordes Jun 23 '16 at 12:24
  • Related: https://stackoverflow.com/questions/21718397/what-are-the-esp-and-the-ebp-registers – riQQ Apr 03 '23 at 10:20

1 Answers1

3

It is a function prologue.

Pushes the old base pointer onto the stack, so it can be restored later:

   push    ebp

Assigns the value of stack pointer into base pointer, then a new stack frame will be created on top of the old stack frame:

   mov     ebp, esp

Moves the stack pointer further by decreasing or increasing its value (depending on whether the stack grows down or up):

   sub     esp, 230h

Here, the230h immediate value is the number of bytes reserved on the stack for local use in the function.

In a similar way, the function epilogue reverses the actions of the prologue and returns control to the calling function.

Check this related SO question: Function Prologue and Epilogue in C

Community
  • 1
  • 1
JosEduSol
  • 5,268
  • 3
  • 23
  • 31
  • Some compilers offer the option of not using frame pointers, which frees up ebp to be used as a generic register (it would still need to be saved). – rcgldr Nov 01 '14 at 02:17