News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Enter , Leave

Started by cman, June 28, 2005, 08:39:49 PM

Previous topic - Next topic

cman

Does anyone know of examples of these instructions? Thanks :bg

Jeff

in its most simplest form:
thisproc PROC
    ENTER 0,0
    ;...
    ENTER 1024,0
    ;...
    LEAVE
    ;...
    LEAVE
    RET
thisproc ENDS
is equivalent tothisproc PROC
    PUSH ebp
    MOV ebp,esp
    ;...
    PUSH ebp
    MOV ebp,esp
    SUB esp,1024
    ;...
    ADD esp,1024
    MOV esp,ebp
    POP ebp
    ;...
    MOV esp,ebp
    POP ebp
    RET
thisproc ENDS


the first operand for enter is the amount of bytes in the stack to reserve for local variables and whatnot.  the second sets the nesting level.  in laymans terms, how many stack frames to have pointers to so you can access local variables from those frames.  for the most part, you would have the second operand 0.  it is difficult to show the nesting levels in action so you should try experimenting with it and check out the stack in a debugger.

hutch--

The manual expansion that Jeff has shown is usually more efficient at the entry end than the exit end. ENTER is slow where LEAVE on exit saves a potential read after write stall.

MASM has used this combination for years since it was viable to use leave simply because it was smaller but it survives in modern code because it actualy works well.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php


AeroASM

Quote from: hutch-- on June 29, 2005, 12:32:32 AM
LEAVE on exit saves a potential read after write stall.

Surely a write after read?

thomasantony

Quote from: AeroASM on June 29, 2005, 10:08:49 AM
Quote from: hutch-- on June 29, 2005, 12:32:32 AM
LEAVE on exit saves a potential read after write stall.

Surely a write after read?
Hi,
   I don't know about read or write but a LEAVE takes only 4-5 cycles and 1 byte while the mov esp,ebp pop ebp combo takes 6-8 cycles and 3-4 bytes. But at the same time ENTER is much slower than push ebp. mov ebp,esp

Thomas :U
There are 10 types of people in the world. Those who understand binary and those who don't.


Programmer's Directory. Submit for free

hutch--

Aero,

Write after read does not procude a stall, its usually dependency on the previous operation that causes the problem.


    MOV esp,ebp    ; read EBP
    POP ebp          ; next OP that depends on completion of previous OP.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php