Netwide Assembler
   HOME

TheInfoList



OR:

The Netwide Assembler (NASM) is an
assembler Assembler may refer to: Arts and media * Nobukazu Takemura, avant-garde electronic musician, stage name Assembler * Assemblers, a fictional race in the ''Star Wars'' universe * Assemblers, an alternative name of the superhero group Champions of ...
and
disassembler A disassembler is a computer program that translates machine language into assembly language—the inverse operation to that of an assembler. A disassembler differs from a decompiler, which targets a high-level language rather than an assembly l ...
for the
Intel Intel Corporation is an American multinational corporation and technology company headquartered in Santa Clara, California. It is the world's largest semiconductor chip manufacturer by revenue, and is one of the developers of the x86 seri ...
x86 x86 (also known as 80x86 or the 8086 family) is a family of complex instruction set computer (CISC) instruction set architectures initially developed by Intel based on the Intel 8086 microprocessor and its 8088 variant. The 8086 was introd ...
architecture. It can be used to write
16-bit 16-bit microcomputers are microcomputers that use 16-bit microprocessors. A 16-bit register can store 216 different values. The range of integer values that can be stored in 16 bits depends on the integer representation used. With the two mos ...
,
32-bit In computer architecture, 32-bit computing refers to computer systems with a processor, memory, and other major system components that operate on data in 32-bit units. Compared to smaller bit widths, 32-bit computers can perform large calculation ...
(
IA-32 IA-32 (short for "Intel Architecture, 32-bit", commonly called i386) is the 32-bit version of the x86 instruction set architecture, designed by Intel and first implemented in the 80386 microprocessor in 1985. IA-32 is the first incarnation o ...
) and
64-bit In computer architecture, 64-bit Integer (computer science), integers, memory addresses, or other Data (computing), data units are those that are 64 bits wide. Also, 64-bit central processing unit, CPUs and arithmetic logic unit, ALUs are those ...
(
x86-64 x86-64 (also known as x64, x86_64, AMD64, and Intel 64) is a 64-bit version of the x86 instruction set, first released in 1999. It introduced two new modes of operation, 64-bit mode and compatibility mode, along with a new 4-level paging mod ...
) programs. It is considered one of the most popular assemblers for
Linux Linux ( or ) is a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically packaged as a Linux distribution, which ...
. It was originally written by
Simon Tatham Simon Tatham (born 3 May 1977) is a British computer programmer. He created and maintains PuTTY, a free software implementation of Secure Shell (SSH) and Telnet for Microsoft Windows and Unix, along with an xterm terminal emulator. He is also ...
with assistance from Julian Hall. , it is maintained by a small team led by H. Peter Anvin. It is
open-source software Open-source software (OSS) is computer software that is released under a license in which the copyright holder grants users the rights to use, study, change, and distribute the software and its source code to anyone and for any purpose. Op ...
released under the terms of a simplified (2-clause)
BSD license BSD licenses are a family of permissive free software licenses, imposing minimal restrictions on the use and distribution of covered software. This is in contrast to copyleft licenses, which have share-alike requirements. The original BSD lic ...
.


Features

NASM can output several binary formats, including
COFF The Common Object File Format (COFF) is a format for executable, object code, and shared library computer files used on Unix systems. It was introduced in Unix System V, replaced the previously used a.out format, and formed the basis for ex ...
, OMF, a.out,
Executable and Linkable Format In computing, the Executable and Linkable FormatTool Interface Standard (TIS) Portable Formats SpecificationVersion 1.1'' (October 1993) (ELF, formerly named Extensible Linking Format), is a common standard file format for executable files, obj ...
(ELF),
Mach-O Mach-O, short for Mach object file format, is a file format for executables, object code, shared libraries, dynamically-loaded code, and core dumps. It was developed to replace the a.out format. Mach-O is used by some systems based on the ...
and
binary file A binary file is a computer file that is not a text file. The term "binary file" is often used as a term meaning "non-text file". Many binary file formats contain parts that can be interpreted as text; for example, some computer document fil ...
(.bin, binary disk image, used to compile
operating system An operating system (OS) is system software that manages computer hardware, software resources, and provides common services for computer programs. Time-sharing operating systems schedule tasks for efficient use of the system and may also in ...
s), though
position-independent code In computing, position-independent code (PIC) or position-independent executable (PIE) is a body of machine code that, being placed somewhere in the primary memory, executes properly regardless of its absolute address. PIC is commonly used for ...
is supported only for ELF
object file An object file is a computer file containing object code, that is, machine code output of an assembler or compiler. The object code is usually relocatable, and not usually directly executable. There are various formats for object files, and the ...
s. It also has its own binary format called RDOFF. The variety of output formats allows
retargeting In software engineering, retargeting is an attribute of software development tools that have been specifically designed to generate code for more than one computing platform. Compilers A retargetable compiler is a compiler that has been designed ...
programs to virtually any x86 operating system (OS). It can also create
flat binary file A binary file is a computer file that is not a text file. The term "binary file" is often used as a term meaning "non-text file". Many binary file formats contain parts that can be interpreted as text; for example, some computer document fil ...
s, usable to write
boot loaders In computing, booting is the process of starting a computer as initiated via hardware such as a button or by a software command. After it is switched on, a computer's central processing unit (CPU) has no software in its main memory, so so ...
,
read-only memory Read-only memory (ROM) is a type of non-volatile memory used in computers and other electronic devices. Data stored in ROM cannot be electronically modified after the manufacture of the memory device. Read-only memory is useful for storing sof ...
(ROM) images, and in various facets of OS development. It can run on non-x86 platforms as a
cross assembler In computer programming, assembly language (or assembler language, or symbolic machine code), often referred to simply as Assembly and commonly abbreviated as ASM or asm, is any low-level programming language with a very strong correspondence be ...
, such as
PowerPC PowerPC (with the backronym Performance Optimization With Enhanced RISC – Performance Computing, sometimes abbreviated as PPC) is a reduced instruction set computer (RISC) instruction set architecture (ISA) created by the 1991 Apple Inc., App ...
and
SPARC SPARC (Scalable Processor Architecture) is a reduced instruction set computer (RISC) instruction set architecture originally developed by Sun Microsystems. Its design was strongly influenced by the experimental Berkeley RISC system developed ...
, though it cannot generate programs usable by those machines. NASM uses a variant of
Intel assembly syntax x86 assembly language is the name for the family of assembly languages which provide some level of backward compatibility with CPUs back to the Intel 8008 microprocessor, which was launched in April 1972. It is used to produce object code for ...
instead of
AT&T AT&T Inc. is an American multinational telecommunications holding company headquartered at Whitacre Tower in Downtown Dallas, Texas. It is the world's largest telecommunications company by revenue and the third largest provider of mobile tel ...
syntax. It also avoids features such as automatic generation of segment overrides (and the related ASSUME directive) used by
MASM The Microsoft Macro Assembler (MASM) is an x86 assembler that uses the Intel syntax for MS-DOS and Microsoft Windows. Beginning with MASM 8.0, there are two versions of the assembler: One for 16-bit & 32-bit assembly sources, and another (ML64) ...
and compatible assemblers.


Sample programs

A "Hello, world!" program for the
DOS DOS is shorthand for the MS-DOS and IBM PC DOS family of operating systems. DOS may also refer to: Computing * Data over signalling (DoS), multiplexing data onto a signalling channel * Denial-of-service attack (DoS), an attack on a communicat ...
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 Linux ( or ) is a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically packaged as a Linux distribution, which ...
: 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 Windows is a group of several proprietary graphical operating system families developed and marketed by Microsoft. Each family caters to a certain sector of the computing industry. For example, Windows NT for consumers, Windows Server for serv ...
: 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 macOS (; previously OS X and originally Mac OS X) is a Unix operating system developed and marketed by Apple Inc. since 2001. It is the primary operating system for Apple's Mac computers. Within the market of desktop and lapt ...
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 file An object file is a computer file containing object code, that is, machine code output of an assembler or compiler. The object code is usually relocatable, and not usually directly executable. There are various formats for object files, and the ...
s, which are generally not executable by themselves. The only exception to this are flat binaries (e.g.,
.COM The domain name .com is a top-level domain (TLD) in the Domain Name System (DNS) of the Internet. Added at the beginning of 1985, its name is derived from the word ''commercial'', indicating its original intended purpose for domains registere ...
) which are inherently limited in modern use. To translate the object files into executable programs, an appropriate
linker Linker or linkers may refer to: Computing * Linker (computing), a computer program that takes one or more object files generated by a compiler or generated by an assembler and links them with libraries, generating an executable program or shar ...
must be used, such as the
Visual Studio Visual Studio is an integrated development environment (IDE) from Microsoft. It is used to develop computer programs including web site, websites, web apps, web services and mobile apps. Visual Studio uses Microsoft software development platfor ...
"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 x86-64 (also known as x64, x86_64, AMD64, and Intel 64) is a 64-bit version of the x86 instruction set, first released in 1999. It introduced two new modes of operation, 64-bit mode and compatibility mode, along with a new 4-level paging mod ...
extensions. The development versions are not uploaded to
SourceForge.net SourceForge is a web service that offers software consumers a centralized online location to control and manage open-source software projects and research business software. It provides source code repository hosting, bug tracking, mirroring ...
, but are checked into
GitHub GitHub, Inc. () is an Internet hosting service for software development and version control using Git. It provides the distributed version control of Git plus access control, bug tracking, software feature requests, task management, continuous ...
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 The GNU Lesser General Public License (LGPL) is a free-software license published by the Free Software Foundation (FSF). The license allows developers and companies to use and integrate a software component released under the LGPL into their own ...
, it led to development of Yasm, a complete rewrite of under the
New BSD License BSD licenses are a family of permissive free software licenses, imposing minimal restrictions on the use and distribution of covered software. This is in contrast to copyleft licenses, which have share-alike requirements. The original BSD li ...
. Yasm offered support for x86-64 earlier than NASM. It also added support for
GNU Assembler The GNU Assembler, commonly known as gas or as, is the assembler developed by the GNU Project. It is the default back-end of GCC. It is used to assemble the GNU operating system and the Linux kernel, and various other software. It is a part of ...
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 DOS is shorthand for the MS-DOS and IBM PC DOS family of operating systems. DOS may also refer to: Computing * Data over signalling (DoS), multiplexing data onto a signalling channel * Denial-of-service attack (DoS), an attack on a communicat ...
COM file A COM file is a type of simple executable file. On the Digital Equipment Corporation (DEC) VAX operating systems of the 1970s, .COM was used as a filename extension for text files containing commands to be issued to the operating system (simi ...
s). In version 0.90,
Simon Tatham Simon Tatham (born 3 May 1977) is a British computer programmer. He created and maintains PuTTY, a free software implementation of Secure Shell (SSH) and Telnet for Microsoft Windows and Unix, along with an xterm terminal emulator. He is also ...
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 In computer programming, assembly language (or assembler language, or symbolic machine code), often referred to simply as Assembly and commonly abbreviated as ASM or asm, is any low-level programming language with a very strong correspondence be ...
*
Comparison of assemblers This is an incomplete list of assemblers: computer programs that translate assembly language source code into binary programs. Some assemblers are components of a compiler system for a high level language and may have limited or no usable functio ...


References


Further reading

*


External links

* *
Special edition for Win32 and BeOS.


at IBM * : a converter between the source format of the assemblers NASM and
GAS Gas is one of the four fundamental states of matter (the others being solid, liquid, and plasma). A pure gas may be made up of individual atoms (e.g. a noble gas like neon), elemental molecules made from one type of atom (e.g. oxygen), or ...
{{X86 assembly topics 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