I
Ivan Vecerina
:A theoretical question: Sorry if its a beginner question.
Theoretical and beginner questions are ok in this NG,
but questions that are paltform specific are OT here.
A MS-specific or assembly/x86 newsgroup would be more
approriate for your post.
: Here is a quote from the MSDN explaning the C/C++ calling convention..
It
: demonstrates that the calling function is responsible to clean the stack
: pointer and it does it by the command "add esp,8" after returning
from
: the called function.
Note that even on a single platform (MSVC compiler on x86), various
calling conventions may exist (as is the case).
The one you refer to apears to be a classic C-calling convention,
which has the advantage of supporting variadic parameters
( the ... , such as for printf and scanf ).
: My questions:
: 1. Is the stack pointer common in a certain thread(or process)?
Each thread has its own stack pointer.
: 2. How does the called function get the parameters, is it by performing
: twice pop functions?
No. In this context it is accessed by using a stack-pointer relative
addressing. The caller will clean-up the stack.
Also, when calling a subroutine, the return address will
typically be pushed on the stack as well, and would
have to be popped first.
Again, other parameter-passing conventions exist.
: 3. If it pops twice why is there any need to clean the stack?
N/A.
hth -Ivan
Theoretical and beginner questions are ok in this NG,
but questions that are paltform specific are OT here.
A MS-specific or assembly/x86 newsgroup would be more
approriate for your post.
: Here is a quote from the MSDN explaning the C/C++ calling convention..
It
: demonstrates that the calling function is responsible to clean the stack
: pointer and it does it by the command "add esp,8" after returning
from
: the called function.
Note that even on a single platform (MSVC compiler on x86), various
calling conventions may exist (as is the case).
The one you refer to apears to be a classic C-calling convention,
which has the advantage of supporting variadic parameters
( the ... , such as for printf and scanf ).
: My questions:
: 1. Is the stack pointer common in a certain thread(or process)?
Each thread has its own stack pointer.
: 2. How does the called function get the parameters, is it by performing
: twice pop functions?
No. In this context it is accessed by using a stack-pointer relative
addressing. The caller will clean-up the stack.
Also, when calling a subroutine, the return address will
typically be pushed on the stack as well, and would
have to be popped first.
Again, other parameter-passing conventions exist.
: 3. If it pops twice why is there any need to clean the stack?
N/A.
hth -Ivan