Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 24 Jul 2001 09:55:16 +0930
From:      Greg Lehey <grog@FreeBSD.org>
To:        j mckitrick <jcm@FreeBSD-uk.eu.org>
Cc:        freebsd-chat@freebsd.org
Subject:   Re: stack use preference
Message-ID:  <20010724095516.F75783@wantadilla.lemis.com>
In-Reply-To: <20010723183331.A55127@dogma.freebsd-uk.eu.org>; from jcm@FreeBSD-uk.eu.org on Mon, Jul 23, 2001 at 06:33:31PM %2B0100
References:  <20010723183331.A55127@dogma.freebsd-uk.eu.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Monday, 23 July 2001 at 18:33:31 +0100, j mckitrick wrote:
>
> For those of you who write or at one time wrote assembly language programs
> for the x86 cpus, what is your preference for local variable on the stack?
> Do you
>
> (a) push the esp down, then move esp to ebp and allocate memory for local
> vars above the esp?
>
> (b) move esp to ebp first, then push the esp down
>
> (c) real programmers don't need ebp for local vars.  They calculate offsets
> from esp on the fly.  :-)
>
> It seems (a) would be easier for humans, since all offsets, including
> procedure parameters, would be positive.
>
> However, compilers seem to generate type (b), so parameters are positive
> offsets from ebp, and local vars are negative.

OK, I've read the responses, but none of them seem to get the point.
We're talking about local variables here, not another stack frame.  In
this case, ebp should remain unchanged.  Having said that, only (c)
remains.

If you really want to create a new stack frame (which means that you
will not be able to access the current one, and you'll have to clean
up on exit), it makes sense to use (b), since that's what compilers
do.  I think gdb also recognizes the prologue and sets breakpoints "at
the beginning of the function" after the prologue, so that you can at
least see the stack correctly.

Greg
--
See complete headers for address and phone numbers

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-chat" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010724095516.F75783>