# Assembly code of a C code

**URL:** <https://linux-tips.com/t/assembly-code-of-a-c-code/198>\
**Category:** Programming\
**Created:** [July 29, 2008, 7:29am UTC](https://linux-tips.com/t/assembly-code-of-a-c-code/198 "2008-07-29T07:29:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![demirezen](https://linux-tips.com/letter_avatar_proxy/v4/letter/d/54ee81/32.png) [@demirezen](https://linux-tips.com/u/demirezen)\
**Post date:** [July 29, 2008, 7:29am UTC](https://linux-tips.com/t/assembly-code-of-a-c-code/198/1 "2008-07-29T07:29:25Z")

</div>

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:

**code.c**

```
#include <stdio.h>

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

```

**code.s**

```
.file "code.c"
.text
.globl main
        .type main, @function
main:
        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
        ret
        .size main, .-main
        .ident "GCC: (GNU) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)"
        .section .note.GNU-stack,"",@progbits
```
