linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Value to subtract from ESP register?
@ 2004-03-24 16:22 zavandi
  2004-03-24 17:25 ` Chris Nanakos
  0 siblings, 1 reply; 4+ messages in thread
From: zavandi @ 2004-03-24 16:22 UTC (permalink / raw)
  To: linux-c-programming

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.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-03-24 21:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-03-24 16:22 Value to subtract from ESP register? zavandi
2004-03-24 17:25 ` Chris Nanakos
2004-03-24 19:39   ` zavandi
2004-03-24 21:37     ` Glynn Clements

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).