Do I need to POP?

[code] push MB_OK
lea eax,MsgBoxCaption

push eax
lea eax, MsgBoxText

push eax

push NULL

call MessageBoxA[/code]

Do I need to pop eax before exiting my app?
If yes, why? Is it like deallocaing in C/C++?

Comments

  • : [code] push MB_OK
    : lea eax,MsgBoxCaption
    :
    : push eax
    : lea eax, MsgBoxText
    :
    : push eax
    :
    : push NULL
    :
    : call MessageBoxA[/code]
    :
    : Do I need to pop eax before exiting my app?
    : If yes, why? Is it like deallocaing in C/C++?

    In this case I believe you are pushing the arguments to MessageBoxA onto the stack so that MessageBoxA can pop them off and use them, so no, you don't need to pop eax (unless perhaps MessageBoxA puts a return value there). I'm very new to this so that's just a semi-educated guess.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

  • : : [code] push MB_OK
    : : lea eax,MsgBoxCaption
    : :
    : : push eax
    : : lea eax, MsgBoxText
    : :
    : : push eax
    : :
    : : push NULL
    : :
    : : call MessageBoxA[/code]
    : :
    : : Do I need to pop eax before exiting my app?
    : : If yes, why? Is it like deallocaing in C/C++?
    :
    : In this case I believe you are pushing the arguments to MessageBoxA onto the stack so that MessageBoxA can pop them off and use them, so no, you don't need to pop eax (unless perhaps MessageBoxA puts a return value there). I'm very new to this so that's just a semi-educated guess.
    :
    :
    : [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
    :
    :
    [blue]That is correct - when you call Win32 to 'serve' you - POPs not needed. And the return code of a Win32 API Function is always in EAX register.[/blue]

  • : : : [code] push MB_OK
    : : : lea eax,MsgBoxCaption
    : : :
    : : : push eax
    : : : lea eax, MsgBoxText
    : : :
    : : : push eax
    : : :
    : : : push NULL
    : : :
    : : : call MessageBoxA[/code]
    : : :
    : : : Do I need to pop eax before exiting my app?
    : : : If yes, why? Is it like deallocaing in C/C++?
    : :
    : : In this case I believe you are pushing the arguments to MessageBoxA onto the stack so that MessageBoxA can pop them off and use them, so no, you don't need to pop eax (unless perhaps MessageBoxA puts a return value there). I'm very new to this so that's just a semi-educated guess.
    : :
    : :
    : : [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
    : :
    : :
    : [blue]That is correct - when you call Win32 to 'serve' you - POPs not needed. And the return code of a Win32 API Function is always in EAX register.[/blue]
    :
    :


    Ok, thanks, I'm a newbie so I wonder:
    I sometimes see in samples that they push in the beginning of the code and then, just before xiting the program, they're poping. What's the need to pop something when your app is about to exit?


  • [b][red]This message was edited by AsmGuru62 at 2003-10-8 6:38:20[/red][/b][hr]
    : : : : [code] push MB_OK
    : : : : lea eax,MsgBoxCaption
    : : : :
    : : : : push eax
    : : : : lea eax, MsgBoxText
    : : : :
    : : : : push eax
    : : : :
    : : : : push NULL
    : : : :
    : : : : call MessageBoxA[/code]
    : : : :
    : : : : Do I need to pop eax before exiting my app?
    : : : : If yes, why? Is it like deallocaing in C/C++?
    : : :
    : : : In this case I believe you are pushing the arguments to MessageBoxA onto the stack so that MessageBoxA can pop them off and use them, so no, you don't need to pop eax (unless perhaps MessageBoxA puts a return value there). I'm very new to this so that's just a semi-educated guess.
    : : :
    : : :
    : : : [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
    : : :
    : : :
    : : [blue]That is correct - when you call Win32 to 'serve' you - POPs not needed. And the return code of a Win32 API Function is always in EAX register.[/blue]
    : :
    : :
    :
    :
    : Ok, thanks, I'm a newbie so I wonder:
    : I sometimes see in samples that they push in the beginning of the code and then, just before xiting the program, they're poping. What's the need to pop something when your app is about to exit?
    :
    :
    :
    [blue]Usually, when Win32 program exits you do not have to POP anything. BTW, the best source to study Win32 ASM programming is this one:

    http://win32assembly.online.fr/tutorials.html

    Also, you need to remember some important things, like:

    1. Registers EBX, ESI, EDI are all preserved across the Win32 API calls, so you can keep the values there and afetr you call Win32 they are NOT destroyed - VERY useful feature!

    2. You MUST follow the same convention (save and restore EBX, ESI, EDI) only when you write the callback functions for Win32, such as: dialog procedures, window procedures, enumeration procedures, hooks, etc. - all functions that you pass to Win32 as parameters - it all goes with the same convention. Here is an example of correct WNDPROC function:
    [code]
    ; --- TASM32 code sample...
    MyWndProc Proc StdCall hWnd:DWORD, uiMsg:DWORD, wp:DWORD, lp:DWORD
    Push ebx
    Push esi
    Push edi

    ; ... your whole code here

    ExitWndProc:
    Pop edi
    Pop esi
    Pop ebx
    Ret
    MyWndProc EndP
    [/code][/blue]


  • : Ok, thanks, I'm a newbie so I wonder:
    : I sometimes see in samples that they push in the beginning of the code and then, just before xiting the program, they're poping. What's the need to pop something when your app is about to exit?

    Think about what it's doing. It's pushing the current value of a register on to the stack. Then it performs some action(s) which may or may not change the value of that register. Then when it's all done it pops that original value back into the register. It's like using a temporary variable to save state while you mess with things so you can put things back the way they were.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories