<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Building an executable</title><meta name="generator" content="DocBook XSL Stylesheets V1.76.1"><meta name="keywords" content="assembly, assembler, asm, inline, 32-bit, IA-32, i386, x86, nasm, gas, as, as86, yasm, fasm, shasm, osimpa, OS, Linux, Unix, kernel, system, libc, glibc, system call, interrupt, small, fast, embedded, hardware, port, macroprocessor, metaprogramming, preprocessor"><link rel="home" href="Assembly-HOWTO.html" title="Linux Assembly HOWTO"><link rel="up" href="quickstart.html" title="Chapter 6. Quick start"><link rel="prev" href="hello.html" title="Hello, world!"><link rel="next" href="mips.html" title="MIPS Example"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Building an executable</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="hello.html">Prev</a> </td><th width="60%" align="center">Chapter 6. Quick start</th><td width="20%" align="right"> <a accesskey="n" href="mips.html">Next</a></td></tr></table><hr></div><div class="section" title="Building an executable"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="idp469008"></a>Building an executable</h2></div></div></div>
<div class="section" title="Producing object code"><div class="titlepage"><div><div><h3 class="title"><a name="idp469904"></a>Producing object code</h3></div></div></div>
<p>
First step of building an executable is compiling (or assembling)
object file from the source:
</p>
<p>
For <span class="application">nasm</span> example:
</p>
<p>
</p><pre class="screen">
$ nasm -f elf hello.asm
</pre><p>
</p>
<p>
For <span class="application">gas</span> example:
</p>
<p>
</p><pre class="screen">
$ as -o hello.o hello.S
</pre><p>
</p>
<p>
This makes <code class="filename">hello.o</code> object file.
</p>
</div>
<div class="section" title="Producing executable"><div class="titlepage"><div><div><h3 class="title"><a name="idp475920"></a>Producing executable</h3></div></div></div>
<p>
Second step is producing executable file itself
from the object file by invoking linker:
</p>
<p>
</p><pre class="screen">
$ ld -s -o hello hello.o
</pre><p>
</p>
<p>
This will finally build <code class="filename">hello</code> executable.
</p>
<p>
Hey, try to run it... Works? That's it. Pretty simple.
</p>
</div>
</div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="hello.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="quickstart.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="mips.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Hello, world! </td><td width="20%" align="center"><a accesskey="h" href="Assembly-HOWTO.html">Home</a></td><td width="40%" align="right" valign="top"> MIPS Example</td></tr></table></div></body></html>