From owner-freebsd-chat Mon Jul 23 13:20: 6 2001 Delivered-To: freebsd-chat@freebsd.org Received: from meow.osd.bsdi.com (meow.osd.bsdi.com [204.216.28.88]) by hub.freebsd.org (Postfix) with ESMTP id E49F337B405 for ; Mon, 23 Jul 2001 13:20:03 -0700 (PDT) (envelope-from jhb@FreeBSD.org) Received: from laptop.baldwin.cx (john@jhb-laptop.osd.bsdi.com [204.216.28.241]) by meow.osd.bsdi.com (8.11.4/8.11.2) with ESMTP id f6NKIVv01875; Mon, 23 Jul 2001 13:18:32 -0700 (PDT) (envelope-from jhb@FreeBSD.org) Message-ID: X-Mailer: XFMail 1.4.0 on FreeBSD X-Priority: 3 (Normal) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit MIME-Version: 1.0 In-Reply-To: <20010723183331.A55127@dogma.freebsd-uk.eu.org> Date: Mon, 23 Jul 2001 13:18:38 -0700 (PDT) From: John Baldwin To: j mckitrick Subject: RE: stack use preference Cc: freebsd-chat@FreeBSD.org 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 23-Jul-01 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. (b), as you can walk back through stack traces when debugging by always looking at [ebp] to get the previous ebp, and [ebp+4] to get the previous IP. (Assuming you do the normal: push %ebp mov %esp, %ebp ... leave ret This is the convention used with the enter/leave 286+ instructions as well. -- John Baldwin -- http://www.FreeBSD.org/~jhb/ PGP Key: http://www.baldwin.cx/~john/pgpkey.asc "Power Users Use the Power to Serve!" - http://www.FreeBSD.org/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-chat" in the body of the message