Assembly code of a C code


We usually use gcc to compile C codes. However, to see assembly code of the C code that we write, we should add -S option while compiling the code:

gcc -S -c code.c

The command above compiles code.c as it generates code.s file which includes assembly code.

Example C code and generated Assembly Code:


#include <stdio.h>

int main(int argc, char *argv[])
        return 0;


.file   "code.c"
.globl main
        .type   main, @function
        leal    4(%esp), %ecx
        andl    $-16, %esp
        pushl   -4(%ecx)
        pushl   %ebp
        movl    %esp, %ebp
        pushl   %ecx
        movl    $0, %eax
        popl    %ecx
        popl    %ebp
        leal    -4(%ecx), %esp
        .size   main, .-main
        .ident  "GCC: (GNU) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)"
        .section        .note.GNU-stack,"",@progbits