* remove "\r" nonsense
[mascara-docs.git] / i386 / i386.reference / ENTER.htm
blob92f40876892ff652c928f6f77ac24a8efb83adb2
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
2 <HTML>
3 <HEAD>
4 <TITLE>80386 Programmer's Reference Manual -- Opcode ENTER</TITLE>
5 </HEAD>
6 <BODY>
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>
11 <P>
12 <HR>
13 <P>
14 <H1>ENTER -- Make Stack Frame for Procedure Parameters</H1>
16 <PRE>
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
21 parameters
22 C8 iw ib ENTER imm16,imm8 15+4(n-1) Make stack frame for
23 procedure parameters
24 </PRE>
26 <H2>Operation</H2>
28 <PRE>
29 level := level MOD 32
30 IF OperandSize = 16 THEN Push(BP) ELSE Push (EBP) FI;
31 (* Save stack pointer *)
32 frame-ptr := eSP
33 IF level > 0
34 THEN (* level is rightmost parameter *)
35 FOR i := 1 TO level - 1
37 IF OperandSize = 16
38 THEN
39 BP := BP - 2;
40 Push[BP]
41 ELSE (* OperandSize = 32 *)
42 EBP := EBP - 4;
43 Push[EBP];
44 FI;
45 OD;
46 Push(frame-ptr)
47 FI;
48 IF OperandSize = 16 THEN BP := frame-ptr ELSE EBP := frame-ptr; FI;
49 IF StackAddrSize = 16
50 THEN SP := SP - First operand;
51 ELSE ESP := ESP - ZeroExtend(First operand);
52 FI;
53 </PRE>
55 <H2>Description</H2>
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
64 stack frame pointer.
65 <P>
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
69 pointer.
70 <P>
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
74 value.
75 <P>
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>
85 None
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>
94 None
96 <H2>Virtual 8086 Mode Exceptions</H2>
98 None
102 <HR>
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>
108 </BODY>