4-5
PROCEDURE CALLS, INTERRUPTS, AND EXCEPTIONS
4.3.CALLING PROCEDURES USING CALL AND RET
The CALL instructions allows control transfers to procedures within the current code segment
(near call) and in a different code segment (far call). Near calls usually provide access to local
procedures within the currently running program or task. Far calls are usually used to access
operating system procedures or procedures in a different task. Refer to Chapter 3, Instruction
Set Reference of the Intel Architecture Software Developers Manual, Volume 2, for a detailed
description of the CALL instruction.
The RET instruction also allows near and far returns to match the near and far versions of the
CALL instruction. In addition, the RET instruction allows a program to increment the stack
pointer on a return to release parameters from the stack. The number of bytes released from the
stack is determined by an optional argument (n) to the RET instruction. Refer to Chapter 3,
Instruction Set Reference of the Intel Architecture Software Developers Manual, Volume 2, for
a detailed description of the RET instruction.
4.3.1.Near CALL and RET Operation
When executing a near call, the processor does the following (refer to Figure 4-2):
1.Pushes the current value of the EIP register on the stack.
2.Loads the offset of the called procedure in the EIP register.
3.Begins execution of the called procedure.
When executing a near return, the processor performs these actions:
1.Pops the top-of-stack value (the return instruction pointer) into the EIP register.
2.(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.
3.Resumes execution of the calling procedure.