www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/09/18/05:34:36

Date: Thu, 18 Sep 1997 11:33:33 +0200 (MET DST)
From: Hans-Bernhard Broeker <broeker AT physik DOT rwth-aachen DOT de>
Subject: Re: Asm Question
In-reply-to: <Pine.LNX.3.91.970918002833.488A-100000@aditya.unigoa.ernet.in>
To: "Gurunandan R. Bhat" <grbhat AT unigoa DOT ernet DOT in>
Cc: djgpp AT delorie DOT com
Message-id: <Pine.LNX.3.91.970918112318.15088A@acp3bf>
MIME-version: 1.0

On Thu, 18 Sep 1997, Gurunandan R. Bhat wrote:
> On Wed, 17 Sep 1997, Hans-Bernhard Broeker wrote:
> > 
> >         pushl %ebp
> >         movl %esp,%ebp
> >         subl $8,%esp
> > 
> > The %ebp is pushed to the stack, then the stack pointer is copied to
> > %ebp. So %ebp always holds the value of the stack pointer as it was
> > when the function was started. 
> 
> Is it correct to say then that, at any given time:

Almost any given time, i.e. always, except during the starting phase of a
newly called function, and during its finalisation and return. 

> 1) %ebp always points to the current stack frame
> 2) (%ebp) always points to the earlier (calling function's) stack frame

I wouldn't be *too* sure about 2), might be you have to add or subtract 4
bytes, as I'm not too sure wether the stack pointer usually points to the
last bytes used, or the first free bytes in the stack. 

To learn it directly from the mouth of the beast, I'd suggest fsdb. There
you can see the stack in raw form, and with the knowledge about what %ebp
and %esp are supposed to do, it should be easy to sort out the details. 

I myself never went further than the point where I understood what was
going on, so I could interpret the stack display more easily, back in the
days of edebug32 and early fsdb, which didn't have a way to display values
of variables in upper stack frames themselves. 

> >         movl %ebp,%esp
> >         popl %ebp
> 
> These two statements appear as "leave" right?

Depending on the chosen optimisation, and version of gcc, yes.
Mine was 2.7.0 on Linux, with no optimisation at all. But 'leave'
does just the same, so it doesn't make a difference. It's just
that some of the x86's execute the movl;popl sequence faster than
the 'leave' operation. Same goes for the 'enter' opcode, which I
haven't ever seen used by gcc, I think.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019