47 lines
3.5 KiB
Markdown
Executable File
47 lines
3.5 KiB
Markdown
Executable File
# ENTER — Make Stack Frame for Procedure Parameters
|
|
|
|
## Description
|
|
|
|
Creates a stack frame (comprising of space for dynamic storage and 1-32 frame pointer storage) for a procedure. The first operand (imm16)
|
|
specifies the size of the dynamic storage in the stack frame (that is, the number of bytes of dynamically allocated on the stack for the
|
|
procedure). The second operand (imm8) gives the lexical nesting level (0 to 31) of the procedure. The nesting level (imm8 mod 32) and the
|
|
OperandSize attribute determine the size in bytes of the storage space for frame pointers.
|
|
|
|
## Instruction
|
|
|
|
| Opcode | Assembly | Op/En | Modern Mode | Legacy Mode | Description |
|
|
|----------|-------------------|-------|-------------|-------------|---------------------------------------------------------------------------|
|
|
| C8 iw 00 | ENTER imm16, 0 | II | Valid | Valid | Create a stack frame for a procedure. |
|
|
| C8 iw 01 | ENTER imm16,1 | II | Valid | Valid | Create a stack frame with a nested pointer for a procedure. |
|
|
| C8 iw ib | ENTER imm16, imm8 | II | Valid | Valid | Create a stack frame with nested pointers for a procedure. |
|
|
|
|
## Information
|
|
|
|
The nesting level determines the number of frame pointers that are copied into the "display area" of the new stack frame from the preceding
|
|
frame. The default size of the frame pointer is the StackAddrSize attribute, but can be overridden using the 66H prefix. Thus, the OperandSize
|
|
attribute determines the size of each frame pointer that will be copied into the stack frame and the data being transferred from SP/ESP/RSP
|
|
register into the BP/EBP/RBP register.
|
|
|
|
The ENTER and companion LEAVE instructions are provided to support block structured languages. The ENTER instruction (when used) is typically
|
|
the first instruction in a procedure and is used to set up a new stack frame for a procedure. The LEAVE instruction is then used at the end of
|
|
the procedure (just before the RET instruction) to release the stack frame.
|
|
|
|
If the nesting level is 0, the processor pushes the frame pointer from the BP/EBP/RBP register onto the stack, copies the current stack pointer
|
|
from the SP/ESP/RSP register into the BP/EBP/RBP register, and loads the SP/ESP/RSP register with the current stack-pointer value minus the
|
|
value in the size operand. For nesting levels of 1 or greater, the processor pushes additional frame pointers on the stack before adjusting the
|
|
stack pointer. These additional frame pointers provide the called procedure with access points to other nested frames on the stack.
|
|
|
|
The ENTER instruction causes a page fault whenever a write using the final value of the stack pointer (within the current stack segment) would
|
|
do so.
|
|
|
|
In 64-bit mode, default operation size is 64 bits; 32-bit operation size cannot be encoded. Use of 66H prefix changes frame pointer operand
|
|
size to 16 bits.
|
|
|
|
When the 66H prefix is used and causing the OperandSize attribute to be less than the StackAddrSize, software is responsible for the following:
|
|
|
|
• The companion LEAVE instruction must also use the 66H prefix.
|
|
|
|
• The value in the RBP/EBP register prior to executing "66H ENTER" must be within the same 16KByte region of the current stack pointer
|
|
(RSP/ESP), such that the value of RBP/EBP after "66H ENTER" remains a valid address in the stack. This ensures "66H LEAVE" can restore 16-bits
|
|
of data from the stack.
|