Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 388559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:46:53+00:00 2026-05-12T15:46:53+00:00

Using this example coming from Wikipedia, in which DrawSquare() calls DrawLine() : (Note that

  • 0

Using this example coming from Wikipedia, in which DrawSquare() calls DrawLine():

diagram of stack with annotations

(Note that this diagram has high addresses at the bottom and low addresses at the top.)

Could anyone explain to me what ebp and esp are in this context?

From what I see, I’d say the stack pointer points always to the top of the stack, and the base pointer to the beginning of the current function? Right?


edit: I mean this in the context of Windows programs.

edit2: And how does eip work, too?

edit3: I have the following code from MSVC++:

var_C= dword ptr -0Ch
var_8= dword ptr -8
var_4= dword ptr -4
hInstance= dword ptr  8
hPrevInstance= dword ptr  0Ch
lpCmdLine= dword ptr  10h
nShowCmd= dword ptr  14h

All of them seem to be dwords, thus taking 4 bytes each. So I can see there is a gap from hInstance to var_4 of 4 bytes. What are they? I assume it is the return address, as can be seen in the diagram from Wikipedia.


(editor’s note: removed a long quote from Michael’s answer, which doesn’t belong in the question, but a followup question was edited in):

This is because the flow of the function call is:

  • Push parameters (hInstance, etc.)
  • Call function, which pushes return address
  • Push ebp
  • Allocate space for locals

My question (last one, I hope!) now is, what exactly happens from the instant I pop the arguments of the function I want to call up to the end of the prolog? I want to know how the ebp, esp evolve during those moments (I already understood how the prolog works, I just want to know what is happening after I pushed the arguments on the stack and before the prolog).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T15:46:53+00:00Added an answer on May 12, 2026 at 3:46 pm

    esp is as you say it is, the top of the stack.

    ebp is usually set to esp at the start of the function. Function parameters and local variables are accessed by adding and subtracting, respectively, a constant offset from ebp. All x86 calling conventions define ebp as being preserved across function calls. ebp itself actually points to the previous frame’s base pointer, which enables stack walking in a debugger and viewing other frame’s local variables to work.

    Most function prologs look something like:

    push ebp      ; Preserve current frame pointer
    mov  ebp, esp ; Create new frame pointer pointing to current stack top
    sub  esp, 20  ; allocate 20 bytes worth of locals on stack.
    

    Then later in the function you may have code like (presuming both local variables are 4 bytes)

    mov  [ebp-4], eax   ; Store eax in first local
    mov  ebx, [ebp - 8] ; Load ebx from second local
    

    FPO or frame pointer omission optimization which you can enable will actually eliminate this and use ebp as another register and access locals directly off of esp, but this makes debugging a bit more difficult since the debugger can no longer directly access the stack frames of earlier function calls.

    EDIT:

    For your updated question, the missing two entries in the stack are:

    nShowCmd          = dword ptr +14h
    hlpCmdLine        = dword ptr +10h
    PrevInstance      = dword ptr +0Ch
    hInstance         = dword ptr +08h
    return address    = dword ptr +04h     <==
    savedFramePointer = dword ptr +00h     <==
    var_4             = dword ptr -04h
    var_8             = dword ptr -08h
    var_C             = dword ptr -0Ch
    

    This is because the flow of the function call is:

    • Push parameters (hInstance, PrevInstance, hlpCmdLine, nShowCmd)
    • Call function, which pushes return address
    • Push ebp
    • Allocate space for locals
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 371k
  • Answers 371k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer My advice would be not to use any of them.… May 14, 2026 at 7:09 pm
  • Editorial Team
    Editorial Team added an answer While it would be nice if Interface Builder could do… May 14, 2026 at 7:09 pm
  • Editorial Team
    Editorial Team added an answer <?xml is being mistaken for PHP short-tag, try echoing it… May 14, 2026 at 7:09 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.