Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>Enter</code> creates a stack frame, and <code>leave</code> destroys a stack frame. With the <code>0,0</code> parameters on the <code>enter</code>, they're basically equivalent to:</p> <pre><code>; enter push ebp mov ebp, esp ; leave mov esp, ebp pop ebp </code></pre> <p>Although it's not used in the code you posted, <code>enter</code> does support doing a bit more than the simple push/mov combination shown above. The first parameter to <code>enter</code> specifies an amount of space to allocate for local variables. For example, <code>enter 5, 0</code> is roughly equivalent to:</p> <pre><code>push ebp mov ebp, esp sub esp, 5 </code></pre> <p><code>Enter</code> also supports languages like Pascal that can use nested functions/procedures:</p> <pre><code>procedure X; procedure Y; begin { ... } end begin { ... } end </code></pre> <p>In a case like this, <code>Y</code> has access not only to its own local variables, but also to all variables local to <code>X</code>. These can be nested to arbitrary depth, so you could have a <code>Z</code> inside of <code>Y</code> that had access to its own local variables, and the variables of <code>Y</code> and the variables of <code>X</code>. The second parameter to <code>enter</code> specifies the nesting depth, so <code>X</code> would use <code>enter Sx, 0</code>, <code>Y</code> would use <code>enter Sy, 1</code> and <code>Z</code> would use <code>enter Sz, 2</code> (where <code>Sx</code>, <code>Sy</code> and <code>Sz</code> signify the size of variables local to <code>X</code>, <code>Y</code> and <code>Z</code> respectively).</p> <p>This would create a chain of stack frames to give <code>Z</code> access to variables local to <code>Y</code> and <code>X</code>, and so on. This becomes fairly non-trivial if the functions are recursive, so an invocation of <code>Z</code> can't just walk up the stack to the two most recent stack frames--it needs to skip across stack frames from previous invocations of itself, and go directly back to stack frames for the lexical parent function/procedure, which is different from its caller in the case of recursion.</p> <p>This complexity is also why C and C++ prohibit nested functions. Given the presence of enter/leave, they're fairly easy to support on Intel processors, but can be considerably more difficult on many other processors that lack such direct support.</p> <p>This also at least helps explain one other...feature of <code>enter</code>--for the trivial case being used here (i.e., <code>enter 0, 0</code>) it's quite a bit slower than the equivalent using <code>push</code>/<code>mov</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload