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
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;
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.
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.
For example, a procedure with 12 bytes of local variables would have an ENTER 12,0 instruction at its entry point and a LEAVE instruction before every RET. The 12 local bytes would be addressed as negative offsets from the frame pointer.
up:
Chapter 17 -- 80386 Instruction Set
prev: DIV Unsigned Divide
next: HLT Halt