ia-32_volume1_basic-arch

The esp register the ebp register automatically

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: B, for a detailed description of the RET instruction. 6.3.1 Near CALL and RET Operation When executing a near call, the processor does the following (see Figure 6-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. Vol. 1 6-5 PROCEDURE CALLS, INTERRUPTS, AND EXCEPTIONS 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. 6.3.2 Far CALL and RET Operation When executing a far call, the processor performs these actions (see Figure 6-2): 1. Pushes the current value of the CS register on the stack. 2. Pushes the current value of the EIP register on the stack. 3. Loads the segment selector of the segment that contains the called procedure in the CS register. 4. Loads the offset of the called procedure in the EIP register. 5. Begins execution of the called procedure. 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. 6-6 Vol. 1 PROCEDURE CALLS, INTERRUPTS, AND EXCEPTIONS Stack Frame Before Call Stack During Near Call Stack Frame After Call Param 1 Param 2 Param 3 Calling EIP Stack Frame Before Call ESP Before Call ESP After Call Stack Frame After Call Stack During Far Call Param 1 Param 2 Param 3 Calling CS Calling EIP ESP Before Call ESP After Call Stack During Near Return Stack During Far Return ESP After Return Param 1 Param 2 Param 3 Calling EIP Param 1 Param 2 Param 3 Calling CS Calling EIP ESP After Return ESP Before Return ESP Before Return Note: On a near or far return, parameters are released from the stack based on the optional n operand in the RET n instruction. Figure 6-2. Stack on Near and Far Calls 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 registers) prior to executing the CALL instruction. The called procedure can likewise pass parameters back to the ca...
View Full Document

This note was uploaded on 10/01/2013 for the course CPE 103 taught by Professor Watlins during the Winter '11 term at Mississippi State.

Ask a homework question - tutors are online