Using the following C code
void func() {
int a=1,b=2,c=3;
}
Compiling using gcc -S -O -o- myfile.c
I get the output
.file "myfile.c"
.intel_syntax noprefix
.text
.globl func
.type func, @function
func:
push ebp
mov ebp, esp
sub esp, 16
mov DWORD PTR [ebp-4], 1
mov DWORD PTR [ebp-8], 2
mov DWORD PTR [ebp-12], 3
mov DWORD PTR [ebp-16], 4
mov DWORD PTR [ebp-20], 5
leave
ret
.size func, .-func
.ident "GCC: (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5"
.section .note.GNU-stack,"",@progbits
Here I would expect the third line after func:
to be sub esp,12
instead of sub esp,16
. I played with different numbers of automatic variables in the function and found that it grows in increments of 16 bytes. Why does this happen? Does this happen on all platforms, or is it platform specific?
I'm currently running an Intel Mac with OSX, compiling through an Ubuntu (32-bit) VirtualBox guest using GCC.