4-7
PROCEDURE CALLS, INTERRUPTS, AND EXCEPTIONS
When executing a far return, the processor does the following:
1.Pops the top-of-stack value (the return instruction pointer) into the EIP register.
2.Pops the top-of-stack value (the segment selector for the code segment being returned to)
into the CS register.
3.(If the RET instruction has an optional n argument.) Increments the stack pointer by the
number of bytes specified with the n operand to release parameters from the stack.
4.Resumes execution of the calling procedure.
4.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.
4.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 parameter to the called procedure by copying the
parameters into any of these registers (except the ESP and EBP registers) prior to executing the
CALL instruction. The called procedure can likewise pass parameters back to the calling proce-
dure through general-purpose registers.
4.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 use the stack-frame
base pointer (in the EBP register) to make a frame boundary for easy access to the parameters.
The stack can also be used to pass parameters back from the called procedure to the calling
procedure.
4.3.3.3.PASSING PARAMETERS IN AN ARGUMENT LIST
An alternate method of passing a larger number of parameters (or a data structure) to the called
procedure is to place the parameters in an argument list in one of the data segments in memory.
A pointer to the argument list can then be passed to the called procedure through a general-
purpose register or the stack. Parameters can also be passed back to the calling procedure in this
same manner.
4.3.4.Saving Procedure State Information
The processor does not save the contents of the general-purpose registers, segment registers, or
the EFLAGS register on a procedure call. A calling procedure should explicitly save the values