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. It is considered one of the most popular assemblers for Linux and x86 chips.

It was originally written by Simon Tatham with assistance from Julian Hall. , 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, OMF, 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 supported only for ELF object files. It also has its own binary format called RDOFF.

The variety of output formats allows retargeting programs to virtually any x86 operating system (OS). It can also create flat binary files, usable to write boot loaders, read-only memory (ROM) images, and in various facets of OS development. It 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.

Sample programs 
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
A 64-bit program for Apple OS X that inputs a keystroke and shows it on the screen:
global _start

section .data

	query_string:		db	"Enter a character:  "
	query_string_len:	equ	$ - query_string
	out_string:			db	"You have input:  "
	out_string_len:		equ	$ - out_string

section .bss

	in_char:			resw 4

section .text

_start:

	mov	rax, 0x2000004	 	; put the write-system-call-code into register rax
	mov	rdi, 1				; tell kernel to use stdout
	mov	rsi, query_string	; rsi is where the kernel expects to find the address of the message
	mov	rdx, query_string_len	; and rdx is where the kernel expects to find the length of the message 
	syscall

	; read in the character
	mov	rax, 0x2000003		; read system call
	mov	rdi, 0				; stdin
	mov	rsi, in_char		; address for storage, declared in section .bss
	mov	rdx, 2				; get 2 bytes from the kernel's buffer (one for the carriage return)
	syscall

	; show user the output
	mov	rax, 0x2000004		; write system call
	mov	rdi, 1				; stdout
	mov	rsi, out_string
	mov	rdx, out_string_len
	syscall

	mov	rax, 0x2000004		; write system call
	mov	rdi, 1				; stdout
	mov	rsi, in_char
	mov	rdx, 2				; the second byte is to apply the carriage return expected in the string
	syscall

	; exit system call
	mov	rax, 0x2000001		; exit system call
	xor     rdi, rdi
	syscall

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 
NASM version 0.90 was released in October 1996.

Version 2.00 was released on 28 November 2007, adding support for x86-64 extensions. The development versions are not uploaded to SourceForge.net, but are checked into GitHub with binary snapshots available from the project web page.

A search engine for NASM documentation is also available.

In July 2009, as of version 2.07, NASM was released under the Simplified (2-clause) BSD license. Previously, because it was licensed under LGPL, it led to development of Yasm, a complete rewrite of under the New BSD License. Yasm offered support for x86-64 earlier than NASM. It also added support for GNU Assembler syntax.

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).

The RDOFF format is strongly deprecated and has been disabled starting in NASM 2.15.04.

See also 

 Assembly language
 Comparison of assemblers

References

Further reading

External links 
 
 
 Special edition for Win32 and BeOS.
 A comparison of GAS and NASM at IBM
 : a converter between the source format of the assemblers NASM and GAS

1996 software
Assemblers
Disassemblers
DOS software
Free compilers and interpreters
Linux programming tools
MacOS
MacOS programming tools
Programming tools for Windows
Software using the BSD license
넷와이드 어셈블러(Netwide Assembler, NASM)은 인텔 x86 아키텍처용 어셈블러이자 역어셈블러이다. 16비트, 32비트(IA-32), 64비트(x86-64) 프로그램 작성에 사용할 수 있다. NASM은 가장 대중적인 리눅스용 어셈블러들 가운데 하나로 인식된다.

NASM은 원래 줄리안 홀(Julian Hall)의 도움을 받아 Simon Tatham에 의해 작성되었다. 2016년 기준으로, H. Peter Anvin이 주도하는 조그마한 팀에 의해 유지보수되고 있다. 단순화된 (2-clause) BSD 라이선스 조항에 의거하여 출시되는 오픈 소스 소프트웨어이다.

운영 체제별 프로그램의 예 
아래는 도스용 운영 체제를 위한 헬로 월드 프로그램이다.
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, '$'
비슷한 프로그램으로 마이크로소프트 윈도우용의 예는 다음과 같다:
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
리눅스용으로는 다음과 같다:
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));

	mov	eax, 1 ; exit
	mov	ebx, 0
	int	0x80 ; exit(0)

section .data
msg:	db	"Hello, world!", 10
.len:	equ	$ - msg
아래는 애플 OS X용 64비트 프로그램의 하나로, 키 입력을 받아 화면에 표시하는 부분이다
global _start

section .data

	query_string:		db	"Enter a character: "
	query_string_len:	equ	$ - query_string
	out_string:			db	"You have input: "
	out_string_len:		equ	$ - out_string

section .bss

	in_char:			resw 4

section .text

_start:

	mov	rax, 0x2000004 	; put the write-system-call-code into register rax
	mov	rdi, 1				; tell kernel to use stdout
	mov	rsi, query_string	; rsi is where the kernel expects to find the address of the message
	mov	rdx, query_string_len	; and rdx is where the kernel expects to find the length of the message
	syscall

	; read in the character
	mov	rax, 0x2000003		; read system call
	mov	rdi, 0				; stdin
	mov	rsi, in_char		; address for storage, declared in section .bss
	mov	rdx, 2				; get 2 bytes from the kernel's buffer (one for the carriage return)
	syscall

	; show user the output
	mov	rax, 0x2000004		; write system call
	mov	rdi, 1				; stdout
	mov	rsi, out_string
	mov	rdx, out_string_len
	syscall

	mov	rax, 0x2000004		; write system call
	mov	rdi, 1				; stdout
	mov	rsi, in_char
	mov	rdx, 2				; the second byte is to apply the carriage return expected in the string
	syscall

	; exit system call
	mov	rax, 0x2000001		; exit system call
        xor     rdi, rdi
	syscall

개발 
2007년 11월 28일, 버전 2.00이 출시되었으며 x86-64 확장 지원을 추가하였다. 개발 버전들은 소스포지에 업로드되지 않지만, 프로젝트 웹 페이지에서 이용 가능한 바이너리 스냅샷을 포함하여 프로젝트 자체의 Git 저장소에서 검진된다.

NASM 문서의 검색 엔진 또한 이용이 가능하다.

2.07 버전의 NASM은 단순화된 (2-clause) BSD 라이선스 하에서 배포된다.

RDOFF 
RODFF(Relocatable Dynamic Object File Format)는 개발자들이 NASM의 오브젝트 파일 출력 속성을 테스트하는 목적으로 사용된다. 상당 부분 NASM의 내부 구조에 기반을 두고 있으며 필수적으로 출력 드라이버 함수 호출과 실행 가능한 코드나 데이터를 포함하는 섹션 배열의 직렬화를 포함하는 헤더로 이루어져 있다. 링커와 로더를 포함한, 이 포맷을 사용하는 도구들은 NASM 배포판에 포함되어 있다.

같이 보기 
 어셈블리어
 Yasm

각주

참고 문헌

외부 링크 
 
 
 Win32 및 BeOS용 특별판
 GAS와 NASM 비교 - IBM

어셈블러
역어셈블러
BSD 라이선스 소프트웨어
자유 컴파일러와 인터프리터