Blame nasm.txt

Packit Service 3b8507
nasm(1)
Packit Service 3b8507
=======
Packit Service 3b8507
:doctype:	manpage
Packit Service 3b8507
:man source:	NASM
Packit Service 3b8507
:man manual:	The Netwide Assembler Project
Packit Service 3b8507
Packit Service 3b8507
NAME
Packit Service 3b8507
----
Packit Service 3b8507
nasm - the Netwide Assembler, a portable 80x86 assembler
Packit Service 3b8507
Packit Service 3b8507
SYNOPSIS
Packit Service 3b8507
--------
Packit Service 3b8507
*nasm* [*-@* response file] [*-f* format] [*-o* outfile] [*-l* listfile] ['options'...] filename
Packit Service 3b8507
Packit Service 3b8507
DESCRIPTION
Packit Service 3b8507
-----------
Packit Service 3b8507
The *nasm* command assembles the file 'filename' and directs output to the file
Packit Service 3b8507
'outfile' if specified. If 'outfile' is not specified, *nasm* will derive a default
Packit Service 3b8507
output file name from the name of its input file, usually by appending `.o' or
Packit Service 3b8507
`.obj', or by removing all extensions for a raw binary file. Failing that, the
Packit Service 3b8507
output file name will be `nasm.out'.
Packit Service 3b8507
Packit Service 3b8507
OPTIONS
Packit Service 3b8507
-------
Packit Service 3b8507
*-@* 'filename'::
Packit Service 3b8507
	Causes *nasm* to process options from filename as if they were included on
Packit Service 3b8507
	the command line.
Packit Service 3b8507
Packit Service 3b8507
*-a*::
Packit Service 3b8507
	Causes *nasm* to assemble the given input file without first applying the
Packit Service 3b8507
	macro preprocessor.
Packit Service 3b8507
Packit Service 3b8507
*-D*|*-d* 'macro[=value]'::
Packit Service 3b8507
	Pre-defines a single-line macro.
Packit Service 3b8507
Packit Service 3b8507
*-E*|*-e*::
Packit Service 3b8507
	Causes *nasm* to preprocess the given input file, and write the output to
Packit Service 3b8507
	'stdout' (or the specified output file name), and not actually assemble
Packit Service 3b8507
	anything.
Packit Service 3b8507
Packit Service 3b8507
*-f* 'format'::
Packit Service 3b8507
	Specifies the output file format. To see a list of valid output formats,
Packit Service 3b8507
	use the *-hf* option.
Packit Service 3b8507
Packit Service 3b8507
*-F* 'format'::
Packit Service 3b8507
	Specifies the debug information format. To see a list of valid output
Packit Service 3b8507
	formats, use the *-y* option (for example *-felf -y*).
Packit Service 3b8507
Packit Service 3b8507
*-g*::
Packit Service 3b8507
	Causes *nasm* to generate debug information.
Packit Service 3b8507
Packit Service 3b8507
*-g*'format'::
Packit Service 3b8507
	Equivalent to **-g -F**__ format__.
Packit Service 3b8507
Packit Service 3b8507
*-h*::
Packit Service 3b8507
	Causes *nasm* to exit immediately, after giving a summary of its
Packit Service 3b8507
	invocation options.
Packit Service 3b8507
Packit Service 3b8507
*-hf*::
Packit Service 3b8507
	Same as *-h* , but also lists all valid output formats.
Packit Service 3b8507
Packit Service 3b8507
*-I*|*-i* 'directory'::
Packit Service 3b8507
	Adds a directory to the search path for include files. The directory
Packit Service 3b8507
	specification must include the trailing slash, as it will be directly
Packit Service 3b8507
	prepended to the name of the include file.
Packit Service 3b8507
Packit Service 3b8507
*-l* 'listfile'::
Packit Service 3b8507
	Causes an assembly listing to be directed to the given file, in which
Packit Service 3b8507
	the original source is displayed on the right hand side (plus the source
Packit Service 3b8507
	for included files and the expansions of multi-line macros) and the
Packit Service 3b8507
	generated code is shown in hex on the left.
Packit Service 3b8507
Packit Service 3b8507
*-M*::
Packit Service 3b8507
	Causes *nasm* to output Makefile-style dependencies to stdout; normal
Packit Service 3b8507
	output is suppressed.
Packit Service 3b8507
Packit Service 3b8507
*-MG* 'file'::
Packit Service 3b8507
	Same as *-M* but assumes that missing Makefile dependecies are generated
Packit Service 3b8507
	and added to dependency list without a prefix.
Packit Service 3b8507
Packit Service 3b8507
*-MF* 'file'::
Packit Service 3b8507
	Output Makefile-style dependencies to the specified file.
Packit Service 3b8507
Packit Service 3b8507
*-MD* 'file'::
Packit Service 3b8507
	Same as a combination of *-M* and *-MF* options.
Packit Service 3b8507
Packit Service 3b8507
*-MT* 'file'::
Packit Service 3b8507
	Override the default name of the dependency target dependency target name.
Packit Service 3b8507
	This is normally the same as the output filename, specified by
Packit Service 3b8507
	the *-o* option.
Packit Service 3b8507
Packit Service 3b8507
*-MQ* 'file'::
Packit Service 3b8507
	The same as *-MT* except it tries to quote characters that have special
Packit Service 3b8507
	meaning in Makefile syntax. This is not foolproof, as not all characters
Packit Service 3b8507
	with special meaning are quotable in Make.
Packit Service 3b8507
Packit Service 3b8507
*-MP*::
Packit Service 3b8507
	Emit phony target.
Packit Service 3b8507
Packit Service 3b8507
*-O* 'number'::
Packit Service 3b8507
	Optimize branch offsets.
Packit Service 3b8507
	* *-O0*: No optimization
Packit Service 3b8507
	* *-O1*: Minimal optimization
Packit Service 3b8507
	* *-Ox*: Multipass optimization (default)
Packit Service 3b8507
Packit Service 3b8507
*-o* 'outfile'::
Packit Service 3b8507
	Specifies a precise name for the output file, overriding *nasm*'s default
Packit Service 3b8507
	means of determining it.
Packit Service 3b8507
Packit Service 3b8507
*-P*|*-p* 'file'::
Packit Service 3b8507
	Specifies a file to be pre-included, before the main source file
Packit Service 3b8507
	starts to be processed.
Packit Service 3b8507
Packit Service 3b8507
*-s*::
Packit Service 3b8507
	Causes *nasm* to send its error messages and/or help text to stdout
Packit Service 3b8507
	instead of stderr.
Packit Service 3b8507
Packit Service 3b8507
*-t*::
Packit Service 3b8507
	Causes *nasm* to assemble in SciTech TASM compatible mode.
Packit Service 3b8507
Packit Service 3b8507
*-U*|*-u* 'macro'::
Packit Service 3b8507
	Undefines a single-line macro.
Packit Service 3b8507
Packit Service 3b8507
*-v*::
Packit Service 3b8507
	Causes *nasm* to exit immediately, after displaying its version number.
Packit Service 3b8507
Packit Service 3b8507
*-W[no-]foo'::
Packit Service 3b8507
	Causes *nasm* to enable or disable certain classes of warning messages,
Packit Service 3b8507
	in gcc-like style, for example *-Wlabel-orphan* or *-Wno-orphan-labels*.
Packit Service 3b8507
Packit Service 3b8507
*-w*'[+-]foo'::
Packit Service 3b8507
	Causes *nasm* to enable or disable certain classes of warning messages,
Packit Service 3b8507
	for example *-w+label-orphan* or *-w-macro-params*.
Packit Service 3b8507
Packit Service 3b8507
*-X* 'format'::
Packit Service 3b8507
	Specifies error reporting format (gnu or vc).
Packit Service 3b8507
Packit Service 3b8507
*-y*::
Packit Service 3b8507
	Causes *nasm* to list supported debug formats.
Packit Service 3b8507
Packit Service 3b8507
*-Z* 'filename'::
Packit Service 3b8507
	Causes *nasm* to redirect error messages to 'filename'. This option exists
Packit Service 3b8507
	to support operating systems on which stderr is not easily redirected.
Packit Service 3b8507
Packit Service 3b8507
--prefix::
Packit Service 3b8507
--postfix::
Packit Service 3b8507
	Prepend or append (respectively) the given argument to all global or
Packit Service 3b8507
	extern variables.
Packit Service 3b8507
Packit Service 3b8507
SYNTAX
Packit Service 3b8507
------
Packit Service 3b8507
This man page does not fully describe the syntax of *nasm*'s assembly language,
Packit Service 3b8507
but does give a summary of the differences from other assemblers.
Packit Service 3b8507
Packit Service 3b8507
'Registers' have no leading `%' sign, unlike *gas*, and floating-point stack
Packit Service 3b8507
registers are referred to as 'st0', 'st1', and so on.
Packit Service 3b8507
Packit Service 3b8507
'Floating-point instructions' may use either the single-operand form or the
Packit Service 3b8507
double. A 'TO' keyword is provided; thus, one could either write
Packit Service 3b8507
Packit Service 3b8507
	fadd st0,st1
Packit Service 3b8507
	fadd st1,st0
Packit Service 3b8507
Packit Service 3b8507
or one could use the alternative single-operand forms
Packit Service 3b8507
Packit Service 3b8507
	fadd st1
Packit Service 3b8507
	fadd to st1
Packit Service 3b8507
Packit Service 3b8507
'Uninitialised storage' is reserved using the 'RESB', 'RESW', 'RESD', 'RESQ',
Packit Service 3b8507
'REST' and 'RESO' pseudo-opcodes, each taking one parameter which gives the
Packit Service 3b8507
number of bytes, words, doublewords, quadwords or ten-byte words to reserve.
Packit Service 3b8507
Packit Service 3b8507
'Repetition' of data items is not done by the 'DUP' keyword as seen in DOS
Packit Service 3b8507
assemblers, but by the use of the 'TIMES' prefix, like this:
Packit Service 3b8507
Packit Service 3b8507
	message: times 3 db 'abc'
Packit Service 3b8507
		 times 64-$+message db 0
Packit Service 3b8507
Packit Service 3b8507
which defines the string `abcabcabc`, followed by the right number of zero
Packit Service 3b8507
bytes to make the total length up to 64 bytes.
Packit Service 3b8507
Packit Service 3b8507
'Symbol references' are always understood to be immediate (i.e. the address
Packit Service 3b8507
of the symbol), unless square brackets are used, in which case the contents
Packit Service 3b8507
of the memory location are used. Thus:
Packit Service 3b8507
Packit Service 3b8507
	mov ax,wordvar
Packit Service 3b8507
Packit Service 3b8507
loads AX with the address of the variable `wordvar`, whereas
Packit Service 3b8507
Packit Service 3b8507
	mov ax,[wordvar]
Packit Service 3b8507
	mov ax,[wordvar+1]
Packit Service 3b8507
	mov ax,[es:wordvar+bx]
Packit Service 3b8507
Packit Service 3b8507
all refer to the 'contents' of memory locations. The syntaxes
Packit Service 3b8507
Packit Service 3b8507
	mov ax,es:wordvar[bx]
Packit Service 3b8507
	es mov ax,wordvar[1]
Packit Service 3b8507
Packit Service 3b8507
are not legal at all, although the use of a segment register name as an instruction
Packit Service 3b8507
prefix is valid, and can be used with instructions such as 'LODSB' which can't
Packit Service 3b8507
be overridden any other way.
Packit Service 3b8507
Packit Service 3b8507
'Constants' may be expressed numerically in most formats: a trailing H, Q or
Packit Service 3b8507
B denotes hex, octal or binary respectively, and a leading `0x' or `$' denotes
Packit Service 3b8507
hex as well. Leading zeros are not treated specially at all. Character constants
Packit Service 3b8507
may be enclosed in single or double quotes; there is no escape character. The
Packit Service 3b8507
ordering is little-endian (reversed), so that the character constant ''abcd''
Packit Service 3b8507
denotes 0x64636261 and not 0x61626364.
Packit Service 3b8507
Packit Service 3b8507
Local labels begin with a period, and their `locality' is granted by the assembler
Packit Service 3b8507
prepending the name of the previous non-local symbol. Thus declaring a label
Packit Service 3b8507
`.loop' after a label `label' has actually defined a symbol called `label.loop'.
Packit Service 3b8507
Packit Service 3b8507
DIRECTIVES
Packit Service 3b8507
----------
Packit Service 3b8507
'SECTION' 'name' or 'SEGMENT' 'name' causes *nasm* to direct all following code
Packit Service 3b8507
to the named section. Section names vary with output file format, although most
Packit Service 3b8507
formats support the names '.text', '.data' and '.bss'. (The exception is the
Packit Service 3b8507
'obj' format, in which all segments are user-definable.)
Packit Service 3b8507
Packit Service 3b8507
'ABSOLUTE' 'address' causes *nasm* to position its notional assembly point at
Packit Service 3b8507
an absolute address: so no code or data may be generated, but you can use 'RESB',
Packit Service 3b8507
'RESW' and 'RESD' to move the assembly point further on, and you can define labels.
Packit Service 3b8507
So this directive may be used to define data structures. When you have finished
Packit Service 3b8507
doing absolute assembly, you must issue another 'SECTION' directive to return to
Packit Service 3b8507
normal assembly.
Packit Service 3b8507
Packit Service 3b8507
'BITS' '16', 'BITS' '32' or 'BITS' '64' switches the default processor mode for
Packit Service 3b8507
which *nasm* is generating code: it is equivalent to 'USE16' or 'USE32' in DOS
Packit Service 3b8507
assemblers.
Packit Service 3b8507
Packit Service 3b8507
'EXTERN' 'symbol' and 'GLOBAL' 'symbol' import and export symbol definitions,
Packit Service 3b8507
respectively, from and to other modules. Note that the 'GLOBAL' directive must
Packit Service 3b8507
appear before the definition of the symbol it refers to.
Packit Service 3b8507
Packit Service 3b8507
'STRUC' 'strucname' and 'ENDSTRUC', when used to bracket a number of 'RESB',
Packit Service 3b8507
'RESW' or similar instructions, define a data structure. In addition to
Packit Service 3b8507
defining the offsets of the structure members, the construct also defines a symbol
Packit Service 3b8507
for the size of the structure, which is simply the structure name with 'size'
Packit Service 3b8507
tacked on to the end.
Packit Service 3b8507
Packit Service 3b8507
FORMAT-SPECIFIC DIRECTIVES
Packit Service 3b8507
--------------------------
Packit Service 3b8507
'ORG' 'address' is used by the 'bin' flat-form binary output format, and
Packit Service 3b8507
specifies the address at which the output code will eventually be loaded.
Packit Service 3b8507
Packit Service 3b8507
'GROUP' 'grpname' 'seg1' 'seg2'... is used by the obj (Microsoft 16-bit)
Packit Service 3b8507
output format, and defines segment groups. This format also uses 'UPPERCASE',
Packit Service 3b8507
which directs that all segment, group and symbol names output to the object
Packit Service 3b8507
file should be in uppercase. Note that the actual assembly is still case
Packit Service 3b8507
sensitive.
Packit Service 3b8507
Packit Service 3b8507
'LIBRARY' 'libname' is used by the 'rdf' output format, and causes a
Packit Service 3b8507
dependency record to be written to the output file which indicates that
Packit Service 3b8507
the program requires a certain library in order to run.
Packit Service 3b8507
Packit Service 3b8507
MACRO PREPROCESSOR
Packit Service 3b8507
------------------
Packit Service 3b8507
Single-line macros are defined using the '%define' or '%idefine' commands, in
Packit Service 3b8507
a similar fashion to the C preprocessor. They can be overloaded with respect
Packit Service 3b8507
to number of parameters, although defining a macro with no parameters prevents
Packit Service 3b8507
the definition of any macro with the same name taking parameters, and vice versa.
Packit Service 3b8507
'%define' defines macros whose names match case-sensitively, whereas '%idefine'
Packit Service 3b8507
defines case-insensitive macros.
Packit Service 3b8507
Packit Service 3b8507
Multi-line macros are defined using '%macro' and '%imacro' (the distinction is the
Packit Service 3b8507
same as that between '%define' and '%idefine'), whose syntax is as follows
Packit Service 3b8507
Packit Service 3b8507
	%macro name minprm[-maxprm][+][.nolist] [defaults]
Packit Service 3b8507
		<some lines of macro expansion text>
Packit Service 3b8507
	%endmacro
Packit Service 3b8507
Packit Service 3b8507
Again, these macros may be overloaded. The trailing plus sign indicates that
Packit Service 3b8507
any parameters after the last one get subsumed, with their separating commas,
Packit Service 3b8507
into the last parameter. The 'defaults' part can be used to specify defaults for
Packit Service 3b8507
unspecified macro parameters after 'minparam'. '%endm' is a valid synonym for
Packit Service 3b8507
'%endmacro'.
Packit Service 3b8507
Packit Service 3b8507
To refer to the macro parameters within a macro expansion, you use '%1', '%2' and
Packit Service 3b8507
so on. You can also enforce that a macro parameter should contain a condition
Packit Service 3b8507
code by using '%+1', and you can invert the condition code by using '%-1'. You can also
Packit Service 3b8507
define a label specific to a macro invocation by prefixing it with a double `%' sign.
Packit Service 3b8507
Packit Service 3b8507
Files can be included using the '%include' directive, which works like C.
Packit Service 3b8507
Packit Service 3b8507
The preprocessor has a `context stack', which may be used by one macro to store
Packit Service 3b8507
information that a later one will retrieve. You can push a context on the stack
Packit Service 3b8507
using '%push', remove one using '%pop', and change the name of the top context (without
Packit Service 3b8507
disturbing any associated definitions) using '%repl'. Labels and '%define' macros
Packit Service 3b8507
specific to the top context may be defined by prefixing their names with %$,
Packit Service 3b8507
and things specific to the next context down with %$$, and so on.
Packit Service 3b8507
Packit Service 3b8507
Conditional assembly is done by means of '%ifdef', '%ifndef', '%else' and '%endif'
Packit Service 3b8507
as in C. (Except that '%ifdef' can accept several putative macro names, and
Packit Service 3b8507
will evaluate TRUE if any of them is defined.) In addition, the directives
Packit Service 3b8507
'%ifctx' and '%ifnctx' can be used to condition on the name of the top context
Packit Service 3b8507
on the context stack. The obvious set of `else-if' directives, '%elifdef',
Packit Service 3b8507
'%elifndef', '%elifctx' and '%elifnctx' are also supported.
Packit Service 3b8507
Packit Service 3b8507
BUGS
Packit Service 3b8507
----
Packit Service 3b8507
Please report bugs through the bug tracker function at http://nasm.us.
Packit Service 3b8507
Packit Service 3b8507
SEE ALSO
Packit Service 3b8507
--------
Packit Service 3b8507
*as*(1), *ld*(1).