6-36
INSTRUCTION SET SUMMARY
6.9.1.2.CALL AND RETURN INSTRUCTIONS
The CALL (call procedure) and RET (return from procedure) instructions allow a jump from
one procedure (or subroutine) to another and a subsequent jump back (return) to the calling
procedure.
The CALL instruction transfers program control from the current (or calling procedure) to
another procedure (the called procedure). To allow a subsequent return to the calling procedure,
the CALL instruction saves the current contents of the EIP register on the stack before jumping
to the called procedure. The EIP register (prior to transferring program control) contains the
address of the instruction following the CALL instruction. When this address is pushed on the
stack, it is referred to as the return instruction pointer or return address.
The address of the called procedure (the address of the first instruction in the procedure being
jumped to) is specified in a CALL instruction the same way as it is in a JMP instruction (refer
to Section 6.9.1.1., Jump Instruction). The address can be specified as a relative address or an
absolute address. If an absolute address is specified, it can be either a near or a far pointer.
The RET instruction transfers program control from the procedure currently being executed (the
called procedure) back to the procedure that called it (the calling procedure). Transfer of control
is accomplished by copying the return instruction pointer from the stack into the EIP register.
Program execution then continues with the instruction pointed to by the EIP register.
The RET instruction has an optional operand, the value of which is added to the contents of the
ESP register as part of the return operation. This operand allows the stack pointer to be incre-
mented to remove parameters from the stack that were pushed on the stack by the calling
procedure.
Refer to Section 4.3., Calling Procedures Using CALL and RET in Chapter 4, Procedure
Calls, Interrupts, and Exceptions for more information on the mechanics of making procedure
calls with the CALL and RET instructions.
6.9.1.3.RETURN FROM INTERRUPT INSTRUCTION
When the processor services an interrupt, it performs an implicit call to an interrupt-handling
procedure. The IRET (return from interrupt) instruction returns program control from an inter-
rupt handler to the interrupted procedure (that is, the procedure that was executing when the
interrupt occurred). The IRET instruction performs a similar operation to the RET instruction
(refer to Section 6.9.1.2., Call and Return Instructions) except that it also restores the
EFLAGS register from the stack. The contents of the EFLAGS register are automatically stored
on the stack along with the return instruction pointer when the processor services an interrupt.
6.9.2.Conditional Transfer Instructions
The conditional transfer instructions execute jumps or loops that transfer program control to
another instruction in the instruction stream if specified conditions are met. The conditions for
control transfer are specified with a set of condition codes that define various states of the status
flags (CF, ZF, OF, PF, and SF) in the EFLAGS register.