Date: Tue, 24 Jul 2001 11:54:18 -0700 (PDT) From: John Baldwin <jhb@FreeBSD.org> To: j mckitrick <jcm@FreeBSD-uk.eu.org> Cc: freebsd-chat@FreeBSD.org, Greg Lehey <grog@FreeBSD.org> Subject: Re: stack use preference Message-ID: <XFMail.010724115418.jhb@FreeBSD.org> In-Reply-To: <20010724022658.A63186@dogma.freebsd-uk.eu.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On 24-Jul-01 j mckitrick wrote: > IIUC, here is what happens: > > foo: ; (int i, char *s) > push %ebp ; save current stack frame > mov %esp, %ebp ; make a new one at the current stack pointer > sub $8, %ebp ; make space for local vars > mov 8(%ebp), ebx; get char * param > mov 4(%ebp), eax; get int param > [...] > leave > ret > ; same as ??? > mov %ebp, %esp ; reset stack pointer > pop %ebp ; restore old frame > ret Yes. On x86, doing enter $8, $0 ; 8 bytes of local storage is equivalent to: push %ebp mov %esp, %ebp sub $8, %esp but most compilers that I've seen unroll 'enter' rather than using it directly. *shrug* Thus, you could do: foo: enter $8, $0 mov 12(%ebp), %ebx ; get char * param mov 8(%ebp), %eax ; get int param ; note that 4(%ebp) is the saved IP, not a param ... leave ret > main: > push %eax ; char * > push %ebx ; int > call foo > [...] -- John Baldwin <jhb@FreeBSD.org> -- 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?XFMail.010724115418.jhb>