Compilation

The next step after preprocessing is compilation. This phase involves syntax validation, optimization and generation of assembly code. The "gcc" compiler can be instructed to generate only the assembly phase using the "-S" option. The resulting file is an assembly file with ".s" extension

$ gcc -S area.i

This generates a file area.s conatining the following assembly code

.file "area.c"

.version "01.01"

gcc2_compiled.:

.section .rodata

.align 32

.LC0:

.string "Area of Square with side %d is %d"

.text

.align 4

.globl main

.type main,@function

main:

pushl %ebp

movl %esp, %ebp

subl $8, %esp

movl $3, -4(%ebp)

subl $4, %esp

movl -4(%ebp), %eax

imull -4(%ebp), %eax

pushl %eax

pushl -4(%ebp)

pushl $.LC0

call printf

addl $16, %esp

movl $0, %eax

leave

ret

.Lfe1:

.size main,.Lfe1-main

.ident "GCC: (GNU) 2.96 20000731 (Red Hat Linux 7.1 2.96-98)"