From owner-freebsd-chat Mon Jul 23 17:25:24 2001 Delivered-To: freebsd-chat@freebsd.org Received: from wantadilla.lemis.com (wantadilla.lemis.com [192.109.197.80]) by hub.freebsd.org (Postfix) with ESMTP id 2F16C37B403 for ; Mon, 23 Jul 2001 17:25:19 -0700 (PDT) (envelope-from grog@lemis.com) Received: by wantadilla.lemis.com (Postfix, from userid 1004) id BE4626ACD1; Tue, 24 Jul 2001 09:55:16 +0930 (CST) Date: Tue, 24 Jul 2001 09:55:16 +0930 From: Greg Lehey To: j mckitrick Cc: freebsd-chat@freebsd.org Subject: Re: stack use preference Message-ID: <20010724095516.F75783@wantadilla.lemis.com> References: <20010723183331.A55127@dogma.freebsd-uk.eu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i 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 +0100 Organization: The FreeBSD Project Phone: +61-8-8388-8286 Fax: +61-8-8388-8725 Mobile: +61-418-838-708 WWW-Home-Page: http://www.FreeBSD.org/ X-PGP-Fingerprint: 6B 7B C3 8C 61 CD 54 AF 13 24 52 F8 6D A4 95 EF Sender: owner-freebsd-chat@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org 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