Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Лаб2012 / 253665.pdf
Скачиваний:
46
Добавлен:
02.02.2015
Размер:
3.31 Mб
Скачать

PROCEDURE CALLS, INTERRUPTS, AND EXCEPTIONS

 

 

 

Stack During

 

 

 

 

 

 

 

 

 

 

 

 

 

Stack During

 

 

 

 

 

 

Stack

Near Call

 

 

 

 

 

Stack

 

Far Call

 

 

 

 

 

 

Frame

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Frame

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Before

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Before

 

 

 

 

 

 

 

 

 

 

 

 

 

Call

 

 

Param 1

 

 

 

 

 

 

 

 

 

 

Param 1

 

 

 

 

 

 

 

 

 

 

 

 

Call

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Param 2

 

 

 

 

 

 

 

 

 

 

Param 2

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ESP Before Call

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Param 3

 

 

 

 

 

 

 

 

 

 

Param 3

 

 

 

 

 

ESP Before Call

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Stack

 

 

Calling EIP

 

 

 

 

 

ESP After Call

 

 

 

 

Calling CS

 

 

 

 

 

ESP After Call

Frame

 

 

 

 

 

 

 

Stack

 

 

 

Calling EIP

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

After

 

 

 

 

 

 

Frame

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Call

 

 

 

 

 

 

After

 

 

 

 

 

 

 

 

 

 

 

Stack During

 

 

 

 

 

Call

 

Stack During

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Near Return

 

 

 

 

ESP After Return

 

Far Return

 

 

 

 

 

ESP After Return

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Param 1

 

 

 

 

 

 

 

 

 

 

 

 

 

Param 1

 

 

 

 

 

 

 

 

 

Param 2

 

 

 

 

 

 

 

 

 

 

 

 

 

Param 2

 

 

 

 

 

 

 

 

 

Param 3

 

 

 

 

 

 

 

 

 

 

 

 

 

Param 3

 

 

 

 

 

 

 

 

 

Calling EIP

 

 

 

 

 

ESP Before Return

 

Calling CS

 

 

 

 

 

ESP Before Return

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Calling EIP

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

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.3Parameter 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.1Passing 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 calling procedure through general-purpose registers.

6.3.3.2Passing 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

Vol. 1 6-7

Соседние файлы в папке Лаб2012