وو

وحید آنلاین . آرشیو وبلاگ وحیدمی دات آی آر . شرکت بیان. vahidmy.blog.ir

وو

وحید آنلاین . آرشیو وبلاگ وحیدمی دات آی آر . شرکت بیان. vahidmy.blog.ir

ENTER

ENTER

Usage:  ENTER   locals,level                      Modifies flags: None

Modifies stack for entry to procedure for high level language. Operand 'locals' specifies the amount of storage to be allocated on the stack. 'Level' specifies the nesting level of the routine. Paired with the LEAVE instruction, this is an efficient method of entry and exit to procedures.

Create Stack Frame


ENTER imm,imm                 ; C8 iw ib             [186]


ENTER constructs a stack frame for a high-level language procedure call. The first operand (the iw in the opcode definition above refers to the first operand) gives the amount of stack space to allocate for local variables; the second (the ib  above) gives the nesting level of the procedure (for languages like Pascal, with nested procedures).


The stack-size attribute determines whether the BP (16 bits) or EBP (32 bits) register specifies the current frame pointer and whether SP (16 bits) or ESP (32 bits) specifies the stack pointer.


The first operand (size operand) specifies the size of the stack frame (that is, the number of bytes of dynamic storage allocated on the stack for the procedure). The second operand (nesting level operand) gives the lexical nesting level (0 to 31) of the procedure. The nesting level determines the number of stack frame pointers that are copied into the 'display area' of the new stack frame from the preceding frame. Both of these operands are

immediate values.


The function of ENTER, with a nesting level of zero, is equivalent to


          PUSH EBP            ; or PUSH BP         in 16 bits

          MOV EBP,ESP         ; or MOV BP,SP       in 16 bits

          SUB ESP,operand1    ; or SUB SP,operand1 in 16 bits


This creates a stack frame with the procedure parameters accessible upwards from EBP, and local variables accessible downwards from EBP.


With a nesting level of one, the stack frame created is 4 (or 2) bytes bigger, and the value of the final frame pointer EBP is accessible in memory at [EBP-4].


This allows ENTER, when called with a nesting level of two, to look at the stack frame described by the  value of EBP, find the frame pointer at offset -4 from that, and push it along with its new frame pointer, so that when a level-two procedure is called from within a level-one procedure, [EBP-4] holds the frame pointer of the most recent level-one procedure call and [EBP-8] holds that of the most recent level-two call. And so on, for nesting levels up to 31. 


Stack frames created by ENTER can be destroyed by the LEAVE  instruction.


Example:

enter SframeSize NestLvl