Intel 64 and IA-32 Architectures Software Developers Manual Volume 1, Basic Architecture

Vol. 1 6-7
PROCEDURE CALLS, INTERRUPTS, AND EXCEPTIONS
6.3.3 Parameter Passing
Parameters can be passed between procedures in any of three ways: through
general-purpose registers, in an argument list, or on the stack.
6.3.3.1 Passing Parameters Through the General-Purpose Registers
The processor does not save the state of the general-purpose registers on procedure
calls. A calling procedure can thus pass up to six parameters to the called procedure
by copying the parameters into any of these registers (except the ESP and EBP regis-
ters) prior to executing the CALL instruction. The called procedure can likewise pass
parameters back to the calling procedure through general-purpose registers.
6.3.3.2 Passing Parameters on the Stack
To pass a large number of parameters to the called procedure, the parameters can be
placed on the stack, in the stack frame for the calling procedure. Here, it is useful to
Figure 6-2. Stack on Near and Far Calls
Param 1
Param 2
ESP Before Call
Stack During
Near Call
Stack During
Far Call
Calling CS
Param 1
Param 2
Calling EIP
Param 3
Param 3
ESP After Return
Calling CS
Param 1
Param 2
Calling EIP
Param 3
Param 1
Param 2
Param 3
Note: On a near or far return, parameters are
Calling EIP
ESP After Call
Stack During
Near Return
Calling EIP
released from the stack based on the
optional
n operand in the RET n instruction.
ESP Before Return
ESP Before Call
ESP After Call
ESP Before Return
ESP After Return
Stack During
Far Return
Stack
Frame
Before
Call
Stack
Frame
Before
Call
Stack
Frame
After
Call
Stack
Frame
After
Call