News:

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

frame pointer omission

Started by redskull, November 16, 2006, 05:10:38 AM

Previous topic - Next topic

redskull

Can anyone shed some light on the advantages/disadvantages of using EBP to set up a stack frame in a function vs. just using ESP alone?  INVOKE apparently uses the EBP set-up, but whenever I do it 'by hand' I always just sort of instinctivly went with ESP (for lack of any 'formal' training).  Are there any reasons why one is better than the other?  Maybe a historical context I'm not old enough to have experienced first hand, or some unique cases I havn't come across yet?
As always, you guys rule.

alan
Strange women, lying in ponds, distributing swords, is no basis for a system of government

Relvinian

Redskull,

This is my own personal rule to use and not use EBP and stack-frames.

All low-level code that changes very in-frequently, I will 99% of the time use ESP and manually code the offsets into ESP needed for stack variables, parameters, etc. High level code like functions is applications that can change a lot as you develop your application or may have the possibility of new features, etc, I usually use a stack frame.  Easier to not have to worry about changing all the ESP offsets and just let ML do the work when compiling the source file.

Relvinian

ToutEnMasm


Using ebp in the stack frame grant you that esp is unchanged after the proc return.
The only inconvenient is that you lose some ยต seconds to do that.
The code must be repeat a MILLENIUM of time before you lose something visible.
Invoke use this type of stack frame and offer you a very secure code and easy detection of wrongs call (Number of parameters and sze of parameters).
                              ToutEnMasm

sinsi

And of course using [ESP+?] frees up another register (EBP)
Light travels faster than sound, that's why some people seem bright until you hear them.

ToutEnMasm


EBP must not be modified in the proc .It is his value that is put in esp when return.
When you want to adress a local variable or an argument of the proc just use:
His name to have is value.
preeced it by addr to have his adrress.

Let masm translate the code in offset like that
MOV DWORD PTR SS:[EBP+08H],EAX      

Note that EBP is used as a pointer on the local variable and arguments.
Esp is used normally as a stack pointer
                                          ToutEnMasm





Tedd

EBP is used as a static reference point to the parameters/variables within a function, so you don't have to dynamically keep track of this each time you use the stack. For modern compilers this isn't really a problem, so they tend to do this directly. For your own functions it's safe to do this when you get the parameters at the beginning and don't bother with any local varaibles, otherwise you have to keep track of the stack-level and mess yourself up if you modify the function again afterwards.
(invoke doesn't have anything to do with the stack-frame, it just takes care of pushing the parameters and calling the function (and cleaning up the stack on return, if necessary); it's proc that sets up the stack-frame.)
No snowflake in an avalanche feels responsible.