223 lines
3.5 KiB
HTML
223 lines
3.5 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
<HTML
|
|
><HEAD
|
|
><TITLE
|
|
>Introduction</TITLE
|
|
><META
|
|
NAME="GENERATOR"
|
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
|
|
REL="HOME"
|
|
TITLE="Linux Assembly HOWTO"
|
|
HREF="index.html"><LINK
|
|
REL="UP"
|
|
TITLE="Quick start"
|
|
HREF="quickstart.html"><LINK
|
|
REL="PREVIOUS"
|
|
TITLE="Quick start"
|
|
HREF="quickstart.html"><LINK
|
|
REL="NEXT"
|
|
TITLE="Hello, world!"
|
|
HREF="hello.html"></HEAD
|
|
><BODY
|
|
CLASS="section"
|
|
BGCOLOR="#FFFFFF"
|
|
TEXT="#000000"
|
|
LINK="#0000FF"
|
|
VLINK="#840084"
|
|
ALINK="#0000FF"
|
|
><DIV
|
|
CLASS="NAVHEADER"
|
|
><TABLE
|
|
SUMMARY="Header navigation table"
|
|
WIDTH="100%"
|
|
BORDER="0"
|
|
CELLPADDING="0"
|
|
CELLSPACING="0"
|
|
><TR
|
|
><TH
|
|
COLSPAN="3"
|
|
ALIGN="center"
|
|
>Linux Assembly HOWTO</TH
|
|
></TR
|
|
><TR
|
|
><TD
|
|
WIDTH="10%"
|
|
ALIGN="left"
|
|
VALIGN="bottom"
|
|
><A
|
|
HREF="quickstart.html"
|
|
ACCESSKEY="P"
|
|
>Prev</A
|
|
></TD
|
|
><TD
|
|
WIDTH="80%"
|
|
ALIGN="center"
|
|
VALIGN="bottom"
|
|
>Chapter 6. Quick start</TD
|
|
><TD
|
|
WIDTH="10%"
|
|
ALIGN="right"
|
|
VALIGN="bottom"
|
|
><A
|
|
HREF="hello.html"
|
|
ACCESSKEY="N"
|
|
>Next</A
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
><HR
|
|
ALIGN="LEFT"
|
|
WIDTH="100%"></DIV
|
|
><DIV
|
|
CLASS="section"
|
|
><H1
|
|
CLASS="section"
|
|
><A
|
|
NAME="AEN832"
|
|
></A
|
|
>6.1. Introduction</H1
|
|
><P
|
|
> Finally, if you still want to try this crazy idea and write something in
|
|
assembly (if you've reached this section -- you're real assembly fan),
|
|
here's what you need to start.
|
|
</P
|
|
><P
|
|
> As you've read before, you can write for Linux in different ways; I'll show
|
|
how to use <EM
|
|
>direct</EM
|
|
> kernel calls, since this is the fastest
|
|
way to call kernel service; our code is not linked to any library, does not
|
|
use ELF interpreter, it communicates with kernel directly.
|
|
</P
|
|
><P
|
|
> I will show the same sample program in two assemblers, <B
|
|
CLASS="command"
|
|
>nasm</B
|
|
>
|
|
and <B
|
|
CLASS="command"
|
|
>gas</B
|
|
>, thus showing Intel and AT&T syntax.
|
|
</P
|
|
><P
|
|
> You may also want to read
|
|
|
|
Introduction to UNIX assembly programming tutorial, it contains sample
|
|
code for other UNIX-like OSes.
|
|
</P
|
|
><DIV
|
|
CLASS="section"
|
|
><H2
|
|
CLASS="section"
|
|
><A
|
|
NAME="AEN842"
|
|
></A
|
|
>6.1.1. Tools you need</H2
|
|
><P
|
|
> First of all you need assembler (compiler) -- <B
|
|
CLASS="command"
|
|
>nasm</B
|
|
> or
|
|
<B
|
|
CLASS="command"
|
|
>gas</B
|
|
>.
|
|
</P
|
|
><P
|
|
> Second, you need a linker -- <B
|
|
CLASS="command"
|
|
>ld</B
|
|
>, since assembler produces
|
|
only object code. Almost all distributions have <SPAN
|
|
CLASS="application"
|
|
>gas</SPAN
|
|
>
|
|
and <SPAN
|
|
CLASS="application"
|
|
>ld</SPAN
|
|
>, in the binutils package.
|
|
</P
|
|
><P
|
|
> As for <SPAN
|
|
CLASS="application"
|
|
>nasm</SPAN
|
|
>, you may have to download and install
|
|
binary packages for Linux and docs from the
|
|
nasm site; note that several distributions
|
|
(Stampede, Debian, SuSe, Mandrake) already have <SPAN
|
|
CLASS="application"
|
|
>nasm</SPAN
|
|
>,
|
|
check first.
|
|
</P
|
|
><P
|
|
> If you're going to dig in, you should also install include files for your OS,
|
|
and if possible, kernel source.
|
|
</P
|
|
></DIV
|
|
></DIV
|
|
><DIV
|
|
CLASS="NAVFOOTER"
|
|
><HR
|
|
ALIGN="LEFT"
|
|
WIDTH="100%"><TABLE
|
|
SUMMARY="Footer navigation table"
|
|
WIDTH="100%"
|
|
BORDER="0"
|
|
CELLPADDING="0"
|
|
CELLSPACING="0"
|
|
><TR
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="left"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="quickstart.html"
|
|
ACCESSKEY="P"
|
|
>Prev</A
|
|
></TD
|
|
><TD
|
|
WIDTH="34%"
|
|
ALIGN="center"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="index.html"
|
|
ACCESSKEY="H"
|
|
>Home</A
|
|
></TD
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="right"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="hello.html"
|
|
ACCESSKEY="N"
|
|
>Next</A
|
|
></TD
|
|
></TR
|
|
><TR
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="left"
|
|
VALIGN="top"
|
|
>Quick start</TD
|
|
><TD
|
|
WIDTH="34%"
|
|
ALIGN="center"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="quickstart.html"
|
|
ACCESSKEY="U"
|
|
>Up</A
|
|
></TD
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="right"
|
|
VALIGN="top"
|
|
>Hello, world!</TD
|
|
></TR
|
|
></TABLE
|
|
></DIV
|
|
></BODY
|
|
></HTML
|
|
> |