Click to See Complete Forum and Search --> : GCC Assembly Output


QBasicer
November 23rd, 2006, 03:32 PM
Here is the program basic.c

#include <stdio.h>

int main(){
printf("Test\n");
return 0;
}

And here is the output of gcc -S basic.c:

.file "basic.c"
.def ___main; .scl 2; .type 32; .endef
.text
LC0:
.ascii "Test\12\0"
.globl _main
.def _main; .scl 2; .type 32; .endef
_main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
andl $-16, %esp
movl $0, %eax
movl %eax, -4(%ebp)
movl -4(%ebp), %eax
call __alloca
call ___main
subl $12, %esp
pushl $LC0
call _printf
addl $16, %esp
movl $0, %eax
leave
ret
.def _printf; .scl 2; .type 32; .endef


What do the calls leading up to and including __alloca and ___main do?

I'm trying to understand how gcc compiles, assembles, and executes code.