1NASM(1)                     General Commands Manual                    NASM(1)
2
3
4

NAME

6       nasm - the Netwide Assembler, a portable 80x86 assembler
7

SYNOPSIS

9       nasm [ -f format ] [ -o outfile ] [ options...  ] infile
10       nasm -h
11       nasm -r
12

DESCRIPTION

14       The  nasm  command  assembles the file infile and directs output to the
15       file outfile if specified. If  outfile  is  not  specified,  nasm  will
16       derive a default output file name from the name of its input file, usu‐
17       ally by appending `.o' or `.obj', or by removing all extensions  for  a
18       raw binary file. Failing that, the output file name will be `nasm.out'.
19
20   OPTIONS
21       -h     Causes  nasm  to exit immediately, after giving a summary of its
22              invocation options, and listing all its  supported  output  file
23              formats.
24
25       -a     Causes  nasm  to  assemble  the  given  input file without first
26              applying the macro preprocessor.
27
28       -e     Causes nasm to preprocess the given input file,  and  write  the
29              output  to  stdout  (or the specified output file name), and not
30              actually assemble anything.
31
32       -M     Causes nasm to output  Makefile-style  dependencies  to  stdout;
33              normal output is suppressed.
34
35       -E filename
36              Causes nasm to redirect error messages to filename.  This option
37              exists to support operating systems on which stderr is not  eas‐
38              ily redirected.
39
40       -r     Causes  nasm  to  exit immediately, after displaying its version
41              number.  (obsolete)
42
43       -v     Causes nasm to exit immediately, after  displaying  its  version
44              number.
45
46       -f format
47              Specifies  the  output file format. Formats include bin, to pro‐
48              duce flat-form binary files, and aout and elf to  produce  Linux
49              a.out and ELF object files, respectively.
50
51       -o outfile
52              Specifies  a precise name for the output file, overriding nasm's
53              default means of determining it.
54
55       -l listfile
56              Causes an assembly listing to be directed to the given file,  in
57              which  the  original  source is displayed on the right hand side
58              (plus the source for included files and the expansions of multi-
59              line macros) and the generated code is shown in hex on the left.
60
61       -s     Causes  nasm to send its error messages and/or help text to std‐
62              out instead of stderr.
63
64       -w[+-]foo
65              Causes nasm to enable or disable certain classes of warning mes‐
66              sages,  for  example  -w+orphan-labels  or  -w-macro-params  to,
67              respectively, enable warnings about labels  alone  on  lines  or
68              disable  warnings about incorrect numbers of parameters in macro
69              calls.
70
71       -I directory
72              Adds a directory to the  search  path  for  include  files.  The
73              directory  specification  must include the trailing slash, as it
74              will be directly prepended to the name of the include file.
75
76       -i directory
77              Same as the -I option.
78
79       -P file
80              Specifies a file to be pre-included, before the main source file
81              starts to be processed.
82
83       -p file
84              Same as the -P option.
85
86       -D macro[=value]
87              Pre-defines a single-line macro.
88
89       -d macro[=value]
90              Same as the -D option.
91
92       -U macro
93              Undefines a single-line macro.
94
95       -u macro
96              Same as the -U option.
97
98   SYNTAX
99       This  man  page  does  not fully describe the syntax of nasm's assembly
100       language, but does give a summary of the differences from other  assem‐
101       blers.
102
103       Registers  have  no  leading  `%'  sign, unlike gas, and floating-point
104       stack registers are referred to as st0, st1, and so on.
105
106       Floating-point instructions may use either the single-operand  form  or
107       the double. A TO keyword is provided; thus, one could either write
108
109                      fadd st0,st1
110                      fadd st1,st0
111
112       or one could use the alternative single-operand forms
113
114                      fadd st1
115                      fadd to st1
116
117       Uninitialised  storage is reserved using the RESB, RESW, RESD, RESQ and
118       REST pseudo-opcodes, each taking one parameter which gives  the  number
119       of bytes, words, doublewords, quadwords or ten-byte words to reserve.
120
121       Repetition  of data items is not done by the DUP keyword as seen in DOS
122       assemblers, but by the use of the TIMES prefix, like this:
123
124             message: times 3 db 'abc'
125                      times 64-$+message db 0
126
127       which defines the string `abcabcabc', followed by the right  number  of
128       zero bytes to make the total length up to 64 bytes.
129
130       Symbol  references  are  always  understood  to  be immediate (i.e. the
131       address of the symbol), unless square brackets are used, in which  case
132       the contents of the memory location are used. Thus:
133
134                      mov ax,wordvar
135
136       loads AX with the address of the variable `wordvar', whereas
137
138                      mov ax,[wordvar]
139                      mov ax,[wordvar+1]
140                      mov ax,[es:wordvar+bx]
141
142       all refer to the contents of memory locations. The syntaxes
143
144                      mov ax,es:wordvar[bx]
145                      es mov ax,wordvar[1]
146
147       are not legal at all, although the use of a segment register name as an
148       instruction prefix is valid, and can be used with instructions such  as
149       LODSB which can't be overridden any other way.
150
151       Constants may be expressed numerically in most formats: a trailing H, Q
152       or B denotes hex, octal or binary respectively, and a leading  `0x'  or
153       `$'  denotes  hex  as  well. Leading zeros are not treated specially at
154       all.  Character constants may be enclosed in single or  double  quotes;
155       there is no escape character. The ordering is little-endian (reversed),
156       so that the  character  constant  'abcd'  denotes  0x64636261  and  not
157       0x61626364.
158
159       Local  labels  begin  with a period, and their `locality' is granted by
160       the assembler prepending the name of  the  previous  non-local  symbol.
161       Thus  declaring  a  label  `.loop'  after  a label `label' has actually
162       defined a symbol called `label.loop'.
163
164   DIRECTIVES
165       SECTION name or SEGMENT name causes nasm to direct all  following  code
166       to  the  named  section.  Section  names  vary with output file format,
167       although most formats support the names .text, .data  and  .bss.   (The
168       exception is the obj format, in which all segments are user-definable.)
169
170       ABSOLUTE address causes nasm to position its notional assembly point at
171       an absolute address: so no code or data may be generated, but  you  can
172       use  RESB, RESW and RESD to move the assembly point further on, and you
173       can define labels. So this directive may be used to define data  struc‐
174       tures.  When  you have finished doing absolute assembly, you must issue
175       another SECTION directive to return to normal assembly.
176
177       BITS 16 or BITS 32 switches the default processor mode for  which  nasm
178       is  generating  code:  it is equivalent to USE16 or USE32 in DOS assem‐
179       blers.
180
181       EXTERN symbol and GLOBAL symbol import and export  symbol  definitions,
182       respectively, from and to other modules. Note that the GLOBAL directive
183       must appear before the definition of the symbol it refers to.
184
185       STRUC strucname and ENDSTRUC, when used to bracket a  number  of  RESB,
186       RESW  or  similar instructions, define a data structure. In addition to
187       defining the offsets of  the  structure  members,  the  construct  also
188       defines  a  symbol  for  the size of the structure, which is simply the
189       structure name with _size tacked on to the end.
190
191   FORMAT-SPECIFIC DIRECTIVES
192       ORG address is used by the bin  flat-form  binary  output  format,  and
193       specifies  the  address  at  which  the  output code will eventually be
194       loaded.
195
196       GROUP grpname seg1 seg2...  is used by the obj (Microsoft 16-bit)  out‐
197       put  format,  and  defines segment groups. This format also uses UPPER‐
198       CASE, which directs that all segment, group and symbol names output  to
199       the  object  file should be in uppercase. Note that the actual assembly
200       is still case sensitive.
201
202       LIBRARY libname is used by the rdf output format, and causes  a  depen‐
203       dency  record to be written to the output file which indicates that the
204       program requires a certain library in order to run.
205
206   MACRO PREPROCESSOR
207       Single-line macros are defined using the %define or %idefine  commands,
208       in a similar fashion to the C preprocessor. They can be overloaded with
209       respect to number of parameters, although  defining  a  macro  with  no
210       parameters prevents the definition of any macro with the same name tak‐
211       ing parameters, and vice versa.  %define  defines  macros  whose  names
212       match   case-sensitively,  whereas  %idefine  defines  case-insensitive
213       macros.
214
215       Multi-line macros are defined using %macro and %imacro (the distinction
216       is  the  same as that between %define and %idefine), whose syntax is as
217       follows:
218
219             %macro name minprm[-maxprm][+][.nolist] [defaults]
220                      <some lines of macro expansion text>
221             %endmacro
222
223       Again, these macros may be overloaded. The trailing plus sign indicates
224       that  any  parameters after the last one get subsumed, with their sepa‐
225       rating commas, into the last parameter. The defaults part can  be  used
226       to  specify  defaults  for unspecified macro parameters after minparam.
227       %endm is a valid synonym for %endmacro.
228
229       To refer to the macro parameters within a macro expansion, you use  %1,
230       %2  and  so on. You can also enforce that a macro parameter should con‐
231       tain a condition code by using %+1, and you can  invert  the  condition
232       code  by  using  %-1.   You can also define a label specific to a macro
233       invocation by prefixing it with a double % sign.
234
235       Files can be included using the %include directive, which works like C.
236
237       The preprocessor has a `context stack', which may be used by one  macro
238       to  store  information  that  a later one will retrieve. You can push a
239       context on the stack using %push, remove one using %pop, and change the
240       name of the top context (without disturbing any associated definitions)
241       using %repl.  Labels and %define macros specific to the top context may
242       be defined by prefixing their names with %$, and things specific to the
243       next context down with %$$, and so on.
244
245       Conditional assembly is done by means of  %ifdef,  %ifndef,  %else  and
246       %endif  as  in C. (Except that %ifdef can accept several putative macro
247       names, and will evaluate TRUE if any of them is defined.) In  addition,
248       the  directives %ifctx and %ifnctx can be used to condition on the name
249       of the top context on the context stack. The obvious set  of  `else-if'
250       directives,  %elifdef,  %elifndef, %elifctx and %elifnctx are also sup‐
251       ported.
252

BUGS

254       There is a reported seg-fault on some (Linux) systems with  some  large
255       source  files.  This  appears  to  be very hard to reproduce. All other
256       known bugs have been fixed...
257

RESTRICTIONS

259       There is no support  for  listing  files,  symbol  maps,  or  debugging
260       object-file  records. The advanced features of the ELF and Win32 object
261       file formats are not supported, and there is no means for  warning  the
262       programmer  against  using  an instruction beyond the capability of the
263       target processor.
264

SEE ALSO

266       as(1), ld(1).
267
268
269
270                         The Netwide Assembler Project                 NASM(1)
Impressum