1 .TH NASM 1 "The Netwide Assembler Project"
3 nasm \- the Netwide Assembler, a portable 80x86 assembler
22 command assembles the file
24 and directs output to the file
30 will derive a default output file name from the name of its input
31 file, usually by appending `.o' or `.obj', or by removing all
32 extensions for a raw binary file. Failing that, the output file name
39 to exit immediately, after giving a summary of its invocation
40 options, and listing all its supported output file formats.
45 to assemble the given input file without first applying the macro
51 to preprocess the given input file, and write the output to
53 (or the specified output file name), and not actually assemble
59 to output Makefile-style dependencies to stdout; normal output is
65 to redirect error messages to
67 This option exists to support operating systems on which stderr is not
73 to exit immediately, after displaying its version number.
79 to exit immediately, after displaying its version number.
82 Specifies the output file format. Formats include
84 to produce flat-form binary files, and
88 to produce Linux a.out and ELF object files, respectively.
91 Specifies a precise name for the output file, overriding
93 default means of determining it.
96 Causes an assembly listing to be directed to the given file, in
97 which the original source is displayed on the right hand side (plus
98 the source for included files and the expansions of multi-line
99 macros) and the generated code is shown in hex on the left.
104 to send its error messages and/or help text to
112 to enable or disable certain classes of warning messages, for
117 to, respectively, enable warnings about labels alone on lines or
118 disable warnings about incorrect numbers of parameters in macro
122 Adds a directory to the search path for include files. The directory
123 specification must include the trailing slash, as it will be
124 directly prepended to the name of the include file.
132 Specifies a file to be pre-included, before the main source file
133 starts to be processed.
140 .BI \-D " macro[=value]"
141 Pre-defines a single-line macro.
143 .BI \-d " macro[=value]"
149 Undefines a single-line macro.
158 This man page does not fully describe the syntax of
160 assembly language, but does give a summary of the differences from
164 have no leading `%' sign, unlike
166 and floating-point stack registers are referred to as
171 .I Floating-point instructions
172 may use either the single-operand form or the double. A
174 keyword is provided; thus, one could either write
182 or one could use the alternative single-operand forms
190 .I Uninitialised storage
191 is reserved using the
198 pseudo-opcodes, each taking one parameter which gives the number of
199 bytes, words, doublewords, quadwords or ten-byte words to reserve.
202 of data items is not done by the
204 keyword as seen in DOS assemblers, but by the use of the
210 message: times 3 db 'abc'
213 times 64-$+message db 0
215 which defines the string `abcabcabc', followed by the right number
216 of zero bytes to make the total length up to 64 bytes.
219 are always understood to be immediate (i.e. the address of the
220 symbol), unless square brackets are used, in which case the contents
221 of the memory location are used. Thus:
226 loads AX with the address of the variable `wordvar', whereas
235 mov ax,[es:wordvar+bx]
239 of memory locations. The syntaxes
242 mov ax,es:wordvar[bx]
247 are not legal at all, although the use of a segment register name as
248 an instruction prefix is valid, and can be used with instructions
251 which can't be overridden any other way.
254 may be expressed numerically in most formats: a trailing H, Q or B
255 denotes hex, octal or binary respectively, and a leading `0x' or `$'
256 denotes hex as well. Leading zeros are not treated specially at all.
257 Character constants may be enclosed in single or double quotes;
258 there is no escape character. The ordering is little-endian
259 (reversed), so that the character constant
261 denotes 0x64636261 and not 0x61626364.
264 begin with a period, and their `locality' is granted by the
265 assembler prepending the name of the previous non-local symbol. Thus
266 declaring a label `.loop' after a label `label' has actually defined
267 a symbol called `label.loop'.
274 to direct all following code to the named section. Section names
275 vary with output file format, although most formats support the
281 (The exception is the
283 format, in which all segments are user-definable.)
288 to position its notional assembly point at an absolute address: so
289 no code or data may be generated, but you can use
294 to move the assembly point further on, and you can define labels. So
295 this directive may be used to define data structures. When you have
296 finished doing absolute assembly, you must issue another
298 directive to return to normal assembly.
303 switches the default processor mode for which
305 is generating code: it is equivalent to
314 import and export symbol definitions, respectively, from and to
315 other modules. Note that the
317 directive must appear before the definition of the symbol it refers
323 when used to bracket a number of
326 or similar instructions, define a data structure. In addition to
327 defining the offsets of the structure members, the construct also
328 defines a symbol for the size of the structure, which is simply the
331 tacked on to the end.
332 .SS FORMAT-SPECIFIC DIRECTIVES
336 flat-form binary output format, and specifies the address at which
337 the output code will eventually be loaded.
339 .I GROUP grpname seg1 seg2...
342 (Microsoft 16-bit) output format, and defines segment groups. This
345 which directs that all segment, group and symbol names output to the
346 object file should be in uppercase. Note that the actual assembly is
347 still case sensitive.
352 output format, and causes a dependency record to be written to the
353 output file which indicates that the program requires a certain
354 library in order to run.
355 .SS MACRO PREPROCESSOR
356 Single-line macros are defined using the
360 commands, in a similar fashion to the C preprocessor. They can be
361 overloaded with respect to number of parameters, although defining a
362 macro with no parameters prevents the definition of any macro with
363 the same name taking parameters, and vice versa.
365 defines macros whose names match case-sensitively, whereas
367 defines case-insensitive macros.
369 Multi-line macros are defined using
373 (the distinction is the same as that between
377 whose syntax is as follows:
382 .IR minprm [- maxprm "][+][.nolist] [" defaults ]
385 <some lines of macro expansion text>
390 Again, these macros may be overloaded. The trailing plus sign
391 indicates that any parameters after the last one get subsumed, with
392 their separating commas, into the last parameter. The
394 part can be used to specify defaults for unspecified macro
398 is a valid synonym for
401 To refer to the macro parameters within a macro expansion, you use
404 and so on. You can also enforce that a macro parameter should
405 contain a condition code by using
407 and you can invert the condition code by using
409 You can also define a label specific to a macro invocation by
410 prefixing it with a double % sign.
412 Files can be included using the
414 directive, which works like C.
416 The preprocessor has a `context stack', which may be used by one
417 macro to store information that a later one will retrieve. You can
418 push a context on the stack using
422 and change the name of the top context (without disturbing any
423 associated definitions) using
427 macros specific to the top context may be defined by prefixing their
428 names with %$, and things specific to the next context down with
431 Conditional assembly is done by means of
437 as in C. (Except that
439 can accept several putative macro names, and will evaluate TRUE if
440 any of them is defined.) In addition, the directives
444 can be used to condition on the name of the top context on the
445 context stack. The obvious set of `else-if' directives,
453 There is a reported seg-fault on some (Linux) systems with some
454 large source files. This appears to be very hard to reproduce. All
457 bugs have been fixed...
459 There is no support for listing files, symbol maps, or debugging
460 object-file records. The advanced features of the ELF and Win32
461 object file formats are not supported, and there is no means for
462 warning the programmer against using an instruction beyond the
463 capability of the target processor.