Puneet Varma (Editor)

Netwide Assembler

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit
Developer(s)
  
H. Peter Anvin, et al.

Type
  
x86 assembler

Available in
  
English

Netwide Assembler

Original author(s)
  
Simon Tatham, Julian Hall

Stable release
  
2.12.02 / July 6, 2016; 8 months ago (2016-07-06)

Operating system
  
Windows, Unix-like, OS/2, OS X, DOS

The Netwide Assembler (NASM) is an assembler and disassembler for the Intel x86 architecture. It can be used to write 16-bit, 32-bit (IA-32) and 64-bit (x86-64) programs. NASM is considered to be one of the most popular assemblers for Linux.

Contents

NASM was originally written by Simon Tatham with assistance from Julian Hall. As of 2016, it is maintained by a small team led by H. Peter Anvin. It is open-source software released under the terms of a simplified (2-clause) BSD license.

Features

NASM can output several binary formats including COFF, Portable Executable, a.out, Executable and Linkable Format (ELF), Mach-O and binary file (.bin, binary disk image, used to compile operating systems), though position-independent code is only supported for ELF object files. NASM also has its own binary format called RDOFF.

The variety of output formats allows retargeting programs to virtually any x86 operating system (OS). Also, NASM can create flat binary files, usable to write boot loaders, read-only memory (ROM) images, and in various facets of OS development. NASM can run on non-x86 platforms, such as PowerPC and SPARC, though it cannot generate programs usable by those machines.

NASM uses a variant of Intel assembly syntax instead of AT&T syntax. It also avoids features such as automatic generation of segment overrides (and the related ASSUME directive) used by MASM and compatible assemblers.

Examples of programs for various operating systems

This is a "Hello, world!" program for the DOS operating system.

An example of a similar program for Microsoft Windows:

An equivalent program for Linux:

Below is a 64-bit program for Apple OS X that inputs a keystroke and shows it on the screen

Linking

NASM principally outputs object files, which are generally not executable by themselves. The only exception to this are flat binaries (e.g., .COM) which are inherently limited in modern use. To translate the object files into executable programs, an appropriate linker must be used, such as the Visual Studio "LINK" utility for Windows or ld for Unix-like systems.

Development

On 28 November 2007, version 2.00 was released, adding support for x86-64 extensions. The development versions are not uploaded to SourceForge.net; instead, they are checked in to the project's own Git repository with binary snapshots available from the project web page.

A search engine for NASM docs is also available.

As of version 2.07, NASM is now under the Simplified (2-clause) BSD license.

RDOFF

Relocatable Dynamic Object File Format (RDOFF) is used by developers to test the integrity of NASM's object file output abilities. It is based heavily on the internal structure of NASM, essentially consisting of a header containing a serialization of the output driver function calls followed by an array of sections containing executable code or data. Tools for using the format, including a linker and loader, are included in the NASM distribution.

Until version 0.90 was released in October 1996, NASM supported output of only flat-format executable files (e.g., DOS COM files). In version 0.90, Simon Tatham added support for an object-file output interface, and for DOS .OBJ files for 16-bit code only.

NASM thus lacked a 32-bit object format. To address this lack, and as an exercise to learn the object-file interface, developer Julian Hall put together the first version of RDOFF, which was released in NASM version 0.91.

Since this initial version, there has been one major update to the RDOFF format, which added a record-length indicator on each header record, allowing programs to skip over records whose format they do not recognise, and support for multiple segments; RDOFF1 only supported three segments: text, data and bss (containing uninitialized data).

References

Netwide Assembler Wikipedia