From: zavandi <zavandi@easynet.ro>
To: linux-c-programming@vger.kernel.org
Subject: Value to subtract from ESP register?
Date: Wed, 24 Mar 2004 18:22:28 +0200 [thread overview]
Message-ID: <4061B5C4.7040907@easynet.ro> (raw)
I have a question which regards mostly gcc. If isn't appropriate here, I
apologize, maybe someone can point me to a more appropriate mailing list.
So... the problem: When gcc compiles a function, the first thing the
function does is to subtract a certain value from the ESP register, to
make room for local variables. This value is always >= than the size of
local variables, but I'd be curious to know what algorithm gcc uses to
decide how much greater the value will be.
An example: I have this code in C:
---start------------------
void f1() {
char d[3];
}
void f2() {
char d[4];
}
---end--------------------
The assembly output for f1 and f2 functions is (gcc -S test.c):
---start------------------
f1:
pushl %ebp
movl %esp, %ebp
subl $24, %esp
leave
ret
f2:
pushl %ebp
movl %esp, %ebp
subl $4, %esp
leave
ret
---end--------------------
I would like to know why the subtracted value is 24 when the local
variable is 3 bytes and 4 when the variable is 4 bytes.
next reply other threads:[~2004-03-24 16:22 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-03-24 16:22 zavandi [this message]
2004-03-24 17:25 ` Value to subtract from ESP register? Chris Nanakos
2004-03-24 19:39 ` zavandi
2004-03-24 21:37 ` Glynn Clements
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4061B5C4.7040907@easynet.ro \
--to=zavandi@easynet.ro \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).