01.09.2014 Views

The Linux Development Platform Configuring, Using, and ... - Classes

The Linux Development Platform Configuring, Using, and ... - Classes

The Linux Development Platform Configuring, Using, and ... - Classes

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CH03.fm Page 62 Monday, October 7, 2002 8:33 PM<br />

62 Chapter 3 • Compilers <strong>and</strong> Assemblers<br />

3.3.3.1 Creating Assembler Code<br />

<strong>Using</strong> the –S (uppercase S) comm<strong>and</strong> line option, you can stop the GCC compiler just<br />

before the assembler process. <strong>The</strong> output is an assembler file with a .s extension. <strong>The</strong> following<br />

comm<strong>and</strong> creates an output file hello.s from source code file hello.c.<br />

gcc –S hello.c<br />

If you look at the output file, you can see the assembler code. Contents of the input file are<br />

as follows:<br />

#include <br />

main()<br />

{<br />

printf ("Hello world\n");<br />

}<br />

<strong>The</strong> output assembler code is shown below:<br />

[root@conformix chap-03]# cat hello.s<br />

.file "hello.c"<br />

.version "01.01"<br />

gcc2_compiled.:<br />

.section .rodata<br />

.LC0:<br />

.string "Hello world\n"<br />

.text<br />

.align 4<br />

.globl main<br />

.type main,@function<br />

main:<br />

pushl %ebp<br />

movl %esp, %ebp<br />

subl $8, %esp<br />

subl $12, %esp<br />

pushl $.LC0<br />

call printf<br />

addl $16, %esp<br />

leave<br />

ret<br />

.Lfe1:<br />

.size main,.Lfe1-main<br />

.ident "GCC: (GNU) 2.96 20000731 (Red Hat <strong>Linux</strong> 7.1<br />

2.96-81)"<br />

[root@conformix chap-03]#<br />

This assembler code may be used with some assembler, like GNU as. Here as is not word<br />

“as” but name of the GNU Assembler which is often written as GNU as as, later on. It can also<br />

be assembled <strong>and</strong> linked to create <strong>and</strong> execute. Please note that for the above comm<strong>and</strong>, the<br />

compiler that is included in RedHat distribution was used.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!