Saturday, December 31, 2011

C Function Stack, Stack pointer & Frame pointer

Describe the Stack Frame constructed during a function call.Also discuss the stack pointer and frame pointer and difference between them.

2 comments:

  1. SP----
    stack pointer points to the top of the stack (lower numerical address)

    FP------
    stack frame pointer (FP) holds an address that point to a fixed location within a frame.

    SP vs FP-----
    Looking at the stack frame, local variables could be referenced by giving their offsets from ESP. However, as data are pushed onto the stack and popped off the stack, these offsets change, so the reference of the local variables is not consistent. Consequently, many compilers use another register, generally called Frame Pointer (FP), for referencing both local variables and parameters because their distances from FP do not change with PUSHes and POPs. On Intel CPUs, EBP (Extended Base Pointer) is used for this purpose

    ReplyDelete
  2. http://www.tenouk.com/Bufferoverflowc/Bufferoverflow2a.html

    ReplyDelete