Does anyone know of examples of these instructions? Thanks :bg
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.
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.
Take a look at Instructions for Block-Structured Languages (http://www7.informatik.uni-erlangen.de/~msdoerfe/embedded/386html/s03_07.htm).
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?
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
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.