This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
question about gcc assembly on i386
- From: "William D. Colburn (aka Schlake)" <wcolburn at nmt dot edu>
- To: gcc-help at gcc dot gnu dot org
- Date: Mon, 20 Jan 2003 09:24:50 -0700
- Subject: question about gcc assembly on i386
I have gcc version 2.95.3 20010315 (release) running on a linux ix86 box.
If I compile the following simple program with -S:
-----cut here-----
void hello(void)
{
printf("hello world\n");
}
-----cut here-----
I get this assembly:
-----cut here-----
.file "hello1.c"
.version "01.01"
gcc2_compiled.:
.section .rodata
.LC0:
.string "hello world\n"
.text
.align 4
.globl hello
.type hello,@function
hello:
pushl %ebp
movl %esp,%ebp
subl $8,%esp
addl $-12,%esp
pushl $.LC0
call printf
addl $16,%esp
.L2:
movl %ebp,%esp
popl %ebp
ret
.Lfe1:
.size hello,.Lfe1-hello
.ident "GCC: (GNU) 2.95.3 20010315 (release)"
-----cut here-----
There are two lines which make no sense to me:
subl $8,%esp
addl $-12,%esp
Why does it add these two lines? Why are they added as two lines?
Changing the optimization doesn't seem to affect the code generated for
this program at all.
After the printf call it does this:
addl $16,%esp
So it has recovered the 4 bytes that was pushed onto the stack, plus the
twelve bytes the addl put onto the stack. That makes it seem like there
needs to be 12 bytes on the stack to make a function call, but I don't
know of any reason that linux/x86s need 12 bytes on the stack. The call
needs to store an address on the stack, but it pushes it and doesn't
expect the user to provide the space.
So, does anyone have any clue what gcc is doing, and why?
--
William Colburn, "Sysprog" <wcolburn@nmt.edu>
Computer Center, New Mexico Institute of Mining and Technology
http://www.nmt.edu/tcc/ http://www.nmt.edu/~wcolburn