1 <!DOCTYPE HTML PUBLIC
"-//IETF//DTD HTML 2.0//EN">
4 <TITLE>80386 Programmer's Reference Manual -- Opcode ENTER
</TITLE>
7 <B>up:
</B> <A HREF=
"c17.htm">
8 Chapter
17 --
80386 Instruction Set
</A><BR>
9 <B>prev:
</B><A HREF=
"DIV.htm"> DIV Unsigned Divide
</A><BR>
10 <B>next:
</B><A HREF=
"HLT.htm"> HLT Halt
</A>
14 <H1>ENTER -- Make Stack Frame for Procedure Parameters
</H1>
17 Opcode Instruction Clocks Description
19 C8 iw
00 ENTER imm16,
0 10 Make procedure stack frame
20 C8 iw
01 ENTER imm16,
1 12 Make stack frame for procedure
22 C8 iw ib ENTER imm16,imm8
15+
4(n-
1) Make stack frame for
30 IF OperandSize =
16 THEN Push(BP) ELSE Push (EBP) FI;
31 (* Save stack pointer *)
34 THEN (* level is rightmost parameter *)
35 FOR i :=
1 TO level -
1
41 ELSE (* OperandSize =
32 *)
48 IF OperandSize =
16 THEN BP := frame-ptr ELSE EBP := frame-ptr; FI;
50 THEN SP := SP - First operand;
51 ELSE ESP := ESP - ZeroExtend(First operand);
57 ENTER creates the stack frame required by most block-structured
58 high-level languages. The first operand specifies the number of bytes of
59 dynamic storage allocated on the stack for the routine being entered.
60 The second operand gives the lexical nesting level (
0 to
31) of the routine
61 within the high-level language source code. It determines the number of
62 stack frame pointers copied into the new stack frame from the preceding
63 frame. BP (or EBP, if the operand-size attribute is
32 bits) is the current
66 If the operand-size attribute is
16 bits, the processor uses BP as the
67 frame pointer and SP as the stack pointer. If the operand-size attribute is
68 32 bits, the processor uses EBP for the frame pointer and ESP for the stack
71 If the second operand is
0, ENTER pushes the frame pointer (BP or
72 EBP) onto the stack; ENTER then subtracts the first operand from the
73 stack pointer and sets the frame pointer to the current stack-pointer
76 For example, a procedure with
12 bytes of local variables would have an
77 ENTER
12,
0 instruction at its entry point and a
78 <A HREF=
"LEAVE.htm">LEAVE
</A> instruction
79 before every
<A HREF=
"RET.htm">RET
</A>.
80 The
12 local bytes would be addressed as negative
81 offsets from the frame pointer.
83 <H2>Flags Affected
</H2>
87 <H2>Protected Mode Exceptions
</H2>
89 #SS(
0) if SP or ESP would exceed the stack limit at any point during
90 instruction execution; #PF(fault-code) for a page fault
92 <H2>Real Address Mode Exceptions
</H2>
96 <H2>Virtual
8086 Mode Exceptions
</H2>
104 <B>up:
</B> <A HREF=
"c17.htm">
105 Chapter
17 --
80386 Instruction Set
</A><BR>
106 <B>prev:
</B><A HREF=
"DIV.htm"> DIV Unsigned Divide
</A><BR>
107 <B>next:
</B><A HREF=
"HLT.htm"> HLT Halt
</A>