Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- iAPx86 - <b>enter make procedure stack frame flags: not altered</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
ENTER           Make Procedure Stack Frame           Flags: Not altered

ENTER locals,nesting                                 CPU: 186+

        Logic   push eBP
                temp . eSP
                while (nesting > 0)
                   nesting . nesting - 1
                   eBP . eBP - n
                   push [SS:eBP]
                endwhile
                eBP . temp
                eSP . eSP - locals

        Note: If the operand-size attribute of ENTER is 16 bits, BP
              and SP are used and n = 2; if 32 bits, EBP and ESP are
              used and n = 4.
              

    ENTER creates the a stack frame that can be used to implement the
    rules of block-structured, high-level languages. A LEAVE
    instruction at the end of the procedure complements ENTER.

    ENTER has two parameters. The first specifies the number of bytes
    of dynamic storage to be allocated on the stack for the routine
    being entered. The second paramter corresponds to the lexical
    nesting level (0 to 31) of the routine within the high-level
    language source code. This level determines how many sets of stack
    frame pointers the CPU copies into the new stack frame from the
    preceding stack frame. This list of stack frames is often called
    the display. Lexical level has no relationship to either the
    protection levels or to the I/O privilege level.

    ENTER creates the new display for a procedure. Then it allocates
    the dynamic storage space for that procedure by decrementing eSP by
    the number of bytes specified in the first parameter. This new
    value of eSP serves as the starting point for all PUSH and POP
    operations within that procedure.

    ENTER can be used either nested or non-nested. If the lexical
    level is zero, the non-nested form is used (enter n,0). The main
    procedure operates at the highest logical level, level 1. The
    first procedure it calls operates at the next deeper level, level
    2, etc. A level 2 procedure can access the variables in the main
    program because a program operating at a higher logical level
    (calling a program at a lower level) requires that the called
    procedure have access to the variables of the calling program.

    A procedure calling another procedure at the same level implies
    that they are parallel procedures and should not have access to
    the variables of the calling program. The new stack frame does not
    include the pointer for addressing the calling procedure's stack
    frame. ENTER treats a re-entrant procedure as a procedure calling
    another procedure at the same level.


    Note
    Some assemblers support ENTER extensions that force the use of
    SP,BP (ENTERW) or ESP,EBP (ENTERD) regardless of the code
    segment's size attribute (80386+).


    Opcode      Format
    C8 iw ib    ENTER imm16,imm8


    Length and timing
    Operands    Bytes   8088    186     286     386     486     Pentium
    imm16, 0      3      -      15      11      10      14      11   NP
    imm16, 1      4      -      25      15      12      17      15   NP
    imm16, imm8   4      -   22+16n    12+4n   15+4n   17+3i  15+2i  NP
                             n = imm8-1;  i = imm8

See Also: LEAVE PUSH

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson