CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2011

    Four Lines of Code

    Hi. I had some basic questions about these four lines of code. I just want to confirm I'm understanding a few points correctly.

    lea     eax, [esp]
    push    eax
    call    dword ptr [edx]
    mov     edi, eax
    Let's say eax was orginally 11 and line 1 made eax 22, would the eax on line 4...

    1. 11?
    2. 22 if the line 2 push instruction wasn't there?
    3. 22 if the line 2 and 3 weren't there whether the instruction on line 1 was lea or mov?
    4. ...ever be impacted by the line 3 call?

    Thanks for any help clarifying these points.
    Last edited by Mr. Smith; August 24th, 2014 at 01:17 PM. Reason: Clarity

  2. #2
    Join Date
    Apr 2000
    Belgium (Europe)

    Re: Four Lines of Code

    the value after the call depends on what the call did.

    for C/C++, eax typically holds the return value of the function assuming it's a function that returns a pointer, reference, or integer type. For any other return types "it depends".
    even if the function returns void, the value can change, there is no requirement for functions to preserve the content of eax through a function call (unlike some other registers that are required to be preserved).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width