78 lines
3.7 KiB
HTML
78 lines
3.7 KiB
HTML
<html><!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
|
|
<html>
|
|
|
|
<head>
|
|
<title>80386 Programmer's Reference Manual -- Opcode ENTER</title>
|
|
</head>
|
|
|
|
<body>
|
|
<b>up:</b> <a href="C17.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/C17.HTM">Chapter 17 -- 80386 Instruction Set</a><br>
|
|
<b>prev:</b><a href="DIV.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/DIV.HTM"> DIV Unsigned Divide</a><br>
|
|
<b>next:</b><a href="HLT.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/HLT.HTM"> HLT Halt</a>
|
|
<p>
|
|
<hr>
|
|
<p>
|
|
<h1>ENTER -- Make Stack Frame for Procedure Parameters</h1>
|
|
<pre>
|
|
|
|
|
|
|
|
Opcode Instruction Clocks Description
|
|
|
|
C8 iw 00 ENTER imm16,0 10 Make procedure stack frame
|
|
C8 iw 01 ENTER imm16,1 12 Make stack frame for procedure
|
|
parameters
|
|
C8 iw ib ENTER imm16,imm8 15+4(n-1) Make stack frame for
|
|
procedure parameters
|
|
</pre>
|
|
<h2>Operation</h2>
|
|
<pre>
|
|
|
|
|
|
|
|
level := level MOD 32
|
|
IF OperandSize = 16 THEN Push(BP) ELSE Push (EBP) FI;
|
|
(* Save stack pointer *)
|
|
frame-ptr := eSP
|
|
IF level > 0
|
|
THEN (* level is rightmost parameter *)
|
|
FOR i := 1 TO level - 1
|
|
DO
|
|
IF OperandSize = 16
|
|
THEN
|
|
BP := BP - 2;
|
|
Push[BP]
|
|
ELSE (* OperandSize = 32 *)
|
|
EBP := EBP - 4;
|
|
Push[EBP];
|
|
FI;
|
|
OD;
|
|
Push(frame-ptr)
|
|
FI;
|
|
IF OperandSize = 16 THEN BP := frame-ptr ELSE EBP := frame-ptr; FI;
|
|
IF StackAddrSize = 16
|
|
THEN SP := SP - First operand;
|
|
ELSE ESP := ESP - ZeroExtend(First operand);
|
|
FI;
|
|
</pre>
|
|
<h2>Description</h2>
|
|
ENTER creates the stack frame required by most block-structured high-level languages. The first operand specifies the number of bytes of dynamic storage allocated on the stack for the routine being entered. The second operand gives the lexical nesting level (0 to 31) of the routine within the high-level language source code. It determines the number of stack frame pointers copied into the new stack frame from the preceding frame. BP (or EBP, if the operand-size attribute is 32 bits) is the current stack frame pointer.
|
|
<p>If the operand-size attribute is 16 bits, the processor uses BP as the frame pointer and SP as the stack pointer. If the operand-size attribute is 32 bits, the processor uses EBP for the frame pointer and ESP for the stack pointer.
|
|
<p>If the second operand is 0, ENTER pushes the frame pointer (BP or EBP) onto the stack; ENTER then subtracts the first operand from the stack pointer and sets the frame pointer to the current stack-pointer value.
|
|
<p>For example, a procedure with 12 bytes of local variables would have an ENTER 12,0 instruction at its entry point and a <a href="LEAVE.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/LEAVE.HTM">LEAVE</a> instruction before every <a href="RET.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/RET.HTM">RET</a>. The 12 local bytes would be addressed as negative offsets from the frame pointer.
|
|
<h2>Flags Affected</h2>
|
|
None
|
|
<h2>Protected Mode Exceptions</h2>
|
|
#SS(0) if SP or ESP would exceed the stack limit at any point during instruction execution; #PF(fault-code) for a page fault
|
|
<h2>Real Address Mode Exceptions</h2>
|
|
None
|
|
<h2>Virtual 8086 Mode Exceptions</h2>
|
|
None
|
|
<p>
|
|
<hr>
|
|
<p><b>up:</b> <a href="C17.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/C17.HTM">Chapter 17 -- 80386 Instruction Set</a><br>
|
|
<b>prev:</b><a href="DIV.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/DIV.HTM"> DIV Unsigned Divide</a><br>
|
|
<b>next:</b><a href="HLT.HTM" tppabs="http://webster.cs.ucr.edu/Page_TechDocs/Doc386/HLT.HTM"> HLT Halt</a>
|
|
</body>
|
|
|