Chapter 6. Quick start

Table of Contents

Introduction
Tools you need
Hello, world!
Program layout
NASM (hello.asm)
GAS (hello.S)
Building an executable
Producing object code
Producing executable
MIPS Example

Introduction

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.

As you've read before, you can write for Linux in different ways; I'll show how to use direct 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.

I will show the same sample program in two assemblers, nasm and gas, thus showing Intel and AT&T syntax.

You may also want to read Introduction to UNIX assembly programming tutorial, it contains sample code for other UNIX-like OSes.

Tools you need

First of all you need assembler (compiler) -- nasm or gas.

Second, you need a linker -- ld, since assembler produces only object code. Almost all distributions have gas and ld, in the binutils package.

As for nasm, 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 nasm, check first.

If you're going to dig in, you should also install include files for your OS, and if possible, kernel source.