This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Why gcc align stack to 16-bytes when passing arguments to a function?


Hello, All:

There is a simple program printf.c
#include <stdio.h>
int main()
{
        printf("%d\n",5);
        printf("%f\n",4.0);
        return 1;
}
When I compile it using "gcc -S printf.c", I get as follows.
      1         .file   "print.c"
      2         .section        .rodata
      3 .LC0:
      4         .string "%d\n"
      5 .LC1:
      6         .string "%f\n"
      7         .text
      8 .globl main
      9         .type   main,@function
     10 main:
     11         pushl   %ebp
     12         movl    %esp, %ebp
     13         subl    $8, %esp
     14         andl    $-16, %esp
     15         movl    $0, %eax
     16         subl    %eax, %esp
     17         subl    $8, %esp
     18         pushl   $5
     19         pushl   $.LC0
     20         call    printf
     21         addl    $16, %esp
     22         subl    $4, %esp
     23         pushl   $1074790400
     24         pushl   $0
     25         pushl   $.LC1
     26         call    printf
     27         addl    $16, %esp
     28         movl    $1, %eax
     29         leave
     30         ret
     31 .Lfe1:
     32         .size   main,.Lfe1-main
     33         .ident  "GCC: (GNU) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)"

 The colored lines show that gcc has aligned the stack to 16-bytes. Why is that?

Regards,
Kevin
From  Southeast University, China


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]