News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

pop's vs direct stack references

Started by turbo_nutter, September 23, 2005, 12:25:13 AM

Previous topic - Next topic

turbo_nutter

I have quite a simple question - why is it that when a function is being called we PUSH signature attributes onto the stack
THEN the function being called, instead of POP'ing the data off the stack, it uses direct stack pointer instructions - eg

push somecrap
call afunction

afunction:
.....(obligatory stack instructions)
mov eax,dword ptr ss:[esp+somcrapSTACKLOCATION]
...


Ratch

turbo_nutter,
     The simple answer is that the last item PUSHed is the return address.  That will be the first thing POPed, and unless you save it, you will be unable to return to where the subroutine was called.  Also a stack read can be done any number of times, but a POPed value has to be saved if you want to use it more than once.  Ratch

hutch--

#2
nutter,

As long as the function you call balances the stack on exit or with C the stack is balanced by the caller, what you push before your call can be popped after the stack cleanup. With STDCALL you normall use RET NUMBER to balace the stack where with a C call you do an ADD ESP, number after the call has returned.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

turbo_nutter

nice one! thanks - makes things a lot more clear!