Blame nasm.txt

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