Sei sulla pagina 1di 12

The Netwide Assembler (NASM) is

an assembler and disassembler for the Intel x86 architecture. It


can be used to write 16-bit, 32-bit and 64-bit programs. NASM is
considered to be one of the most popular assemblers for Linux.

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.

The initial release is on October 1996,


And stable release on November 7, 2018.
 a86 is good, but not free, and in particular you don’t get any 32−bit
capability until you pay. It’s DOS only, too.
 gas is free, and ports over DOS and Unix, but it’s not very good,
since it’s designed to be a back end to gcc , which always feeds it
correct code. So its error checking is minimal. Also, its syntax is
horrible, from the point of view of anyone trying to actually write
anything in it. Plus you can’t write 16−bit code in it (properly).
 MASM isn’t very good, and it’s (was) expensive, and it runs only
under DOS.
 TASM is better, but still strives for MASM compatibility, which means
millions of directives and tons of red tape. And its syntax is essentially
MASM’s, with the contradictions and quirks that entails (although it
sorts out some of those by means of Ideal mode). It’s expensive too.
And it’s DOS−only
NASM can output several binary formats including COFF,
OMF, a.out, Executable and Linkable Format (ELF), Macho and binary
file (.bin, binary disk image, used to compile operating systems),
though position-independent code is supported only 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 as
a cross assembler, 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
This is a "Hello, world!" program for the DOS operating system.

section .text
org 0x100 mov ah, 0x9
mov dx, hello
int 0x21

mov ax, 0x4c00


int 0x21

section .data
hello: db 'Hello, world!', 13, 10, '$'
An equivalent program for Linux:

global _start

section .text
_start:
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, msg
mov edx, msg.len
int 0x80 ; write(stdout, msg, strlen(msg));

xor eax, msg.len ; invert return value from write()


xchg eax, ebx ; value for exit()
mov eax, 1 ; exit
int 0x80 ; exit(...)

section .data
msg: db "Hello, world!", 10
.len: equ $ - msg
An example of a similar program for Microsoft Windows:

global _main
extern _MessageBoxA@16
extern _ExitProcess@4

section code use32 class=code


_main:
push dword 0 ; UINT uType = MB_OK
push dword title ; LPCSTR lpCaption
push dword banner ; LPCSTR lpText
push dword 0 ; HWND hWnd = NULL
call _MessageBoxA@16

push dword 0 ; UINT uExitCode


call _ExitProcess@4

section data use32 class=data


banner: db 'Hello, world!', 0
title: db 'Hello', 0
 The −o. Option: Specifying the Output File Name.
 The −f Option: Specifying the Output File Format.
 The −l Option: Generating a Listing File.
 The −M Option: Generate Make file Dependencies.
 The −F Option: Selecting a Debug Information Format.
 The −g Option: Enabling Debug Information.
 The −X Option: Selecting an Error Reporting Format.
 The −E Option: Send Errors to a File.
 The −s Option: Send Errors to stdout.
 The −i Option: Include File Search Directories .
 The −p Option: Pre−Include a File .
 The −e Option: Preprocess Only.
THE END

Potrebbero piacerti anche