📄 nasmdoc.src
字号:
\S{opt-Z} The \i\c{-Z} Option: Send Errors to a File
Under \I{DOS}\c{MS-DOS} it can be difficult (though there are ways) to
redirect the standard-error output of a program to a file. Since
NASM usually produces its warning and \i{error messages} on
\i\c{stderr}, this can make it hard to capture the errors if (for
example) you want to load them into an editor.
NASM therefore provides the \c{-Z} option, taking a filename argument
which causes errors to be sent to the specified files rather than
standard error. Therefore you can \I{redirecting errors}redirect
the errors into a file by typing
\c nasm -Z myfile.err -f obj myfile.asm
In earlier versions of NASM, this option was called \c{-E}, but it was
changed since \c{-E} is an option conventionally used for
preprocessing only, with disastrous results. See \k{opt-E}.
\S{opt-s} The \i\c{-s} Option: Send Errors to \i\c{stdout}
The \c{-s} option redirects \i{error messages} to \c{stdout} rather
than \c{stderr}, so it can be redirected under \I{DOS}\c{MS-DOS}. To
assemble the file \c{myfile.asm} and pipe its output to the \c{more}
program, you can type:
\c nasm -s -f obj myfile.asm | more
See also the \c{-Z} option, \k{opt-Z}.
\S{opt-i} The \i\c{-i}\I\c{-I} Option: Include File Search Directories
When NASM sees the \i\c{%include} or \i\c{%pathsearch} directive in a
source file (see \k{include}, \k{pathsearch} or \k{incbin}), it will
search for the given file not only in the current directory, but also
in any directories specified on the command line by the use of the
\c{-i} option. Therefore you can include files from a \i{macro
library}, for example, by typing
\c nasm -ic:\macrolib\ -f obj myfile.asm
(As usual, a space between \c{-i} and the path name is allowed, and
optional).
NASM, in the interests of complete source-code portability, does not
understand the file naming conventions of the OS it is running on;
the string you provide as an argument to the \c{-i} option will be
prepended exactly as written to the name of the include file.
Therefore the trailing backslash in the above example is necessary.
Under Unix, a trailing forward slash is similarly necessary.
(You can use this to your advantage, if you're really \i{perverse},
by noting that the option \c{-ifoo} will cause \c{%include "bar.i"}
to search for the file \c{foobar.i}...)
If you want to define a \e{standard} \i{include search path},
similar to \c{/usr/include} on Unix systems, you should place one or
more \c{-i} directives in the \c{NASMENV} environment variable (see
\k{nasmenv}).
For Makefile compatibility with many C compilers, this option can also
be specified as \c{-I}.
\S{opt-p} The \i\c{-p}\I\c{-P} Option: \I{pre-including files}Pre-Include a File
\I\c{%include}NASM allows you to specify files to be
\e{pre-included} into your source file, by the use of the \c{-p}
option. So running
\c nasm myfile.asm -p myinc.inc
is equivalent to running \c{nasm myfile.asm} and placing the
directive \c{%include "myinc.inc"} at the start of the file.
For consistency with the \c{-I}, \c{-D} and \c{-U} options, this
option can also be specified as \c{-P}.
\S{opt-d} The \i\c{-d}\I\c{-D} Option: \I{pre-defining macros}Pre-Define a Macro
\I\c{%define}Just as the \c{-p} option gives an alternative to placing
\c{%include} directives at the start of a source file, the \c{-d}
option gives an alternative to placing a \c{%define} directive. You
could code
\c nasm myfile.asm -dFOO=100
as an alternative to placing the directive
\c %define FOO 100
at the start of the file. You can miss off the macro value, as well:
the option \c{-dFOO} is equivalent to coding \c{%define FOO}. This
form of the directive may be useful for selecting \i{assembly-time
options} which are then tested using \c{%ifdef}, for example
\c{-dDEBUG}.
For Makefile compatibility with many C compilers, this option can also
be specified as \c{-D}.
\S{opt-u} The \i\c{-u}\I\c{-U} Option: \I{Undefining macros}Undefine a Macro
\I\c{%undef}The \c{-u} option undefines a macro that would otherwise
have been pre-defined, either automatically or by a \c{-p} or \c{-d}
option specified earlier on the command lines.
For example, the following command line:
\c nasm myfile.asm -dFOO=100 -uFOO
would result in \c{FOO} \e{not} being a predefined macro in the
program. This is useful to override options specified at a different
point in a Makefile.
For Makefile compatibility with many C compilers, this option can also
be specified as \c{-U}.
\S{opt-E} The \i\c{-E}\I{-e} Option: Preprocess Only
NASM allows the \i{preprocessor} to be run on its own, up to a
point. Using the \c{-E} option (which requires no arguments) will
cause NASM to preprocess its input file, expand all the macro
references, remove all the comments and preprocessor directives, and
print the resulting file on standard output (or save it to a file,
if the \c{-o} option is also used).
This option cannot be applied to programs which require the
preprocessor to evaluate \I{preprocessor expressions}\i{expressions}
which depend on the values of symbols: so code such as
\c %assign tablesize ($-tablestart)
will cause an error in \i{preprocess-only mode}.
For compatiblity with older version of NASM, this option can also be
written \c{-e}. \c{-E} in older versions of NASM was the equivalent
of the current \c{-Z} option, \k{opt-Z}.
\S{opt-a} The \i\c{-a} Option: Don't Preprocess At All
If NASM is being used as the back end to a compiler, it might be
desirable to \I{suppressing preprocessing}suppress preprocessing
completely and assume the compiler has already done it, to save time
and increase compilation speeds. The \c{-a} option, requiring no
argument, instructs NASM to replace its powerful \i{preprocessor}
with a \i{stub preprocessor} which does nothing.
\S{opt-O} The \i\c{-O} Option: Specifying \i{Multipass Optimization}
NASM defaults to not optimizing operands which can fit into a signed byte.
This means that if you want the shortest possible object code,
you have to enable optimization.
Using the \c{-O} option, you can tell NASM to carry out different
levels of optimization. The syntax is:
\b \c{-O0}: No optimization. All operands take their long forms,
if a short form is not specified, except conditional jumps.
This is intended to match NASM 0.98 behavior.
\b \c{-O1}: Minimal optimization. As above, but immediate operands
which will fit in a signed byte are optimized,
unless the long form is specified. Conditional jumps default
to the long form unless otherwise specified.
\b \c{-Ox} (where \c{x} is the actual letter \c{x}): Multipass optimization.
Minimize branch offsets and signed immediate bytes,
overriding size specification unless the \c{strict} keyword
has been used (see \k{strict}). For compatability with earlier
releases, the letter \c{x} may also be any number greater than
one. This number has no effect on the actual number of passes.
The \c{-Ox} mode is recommended for most uses.
Note that this is a capital \c{O}, and is different from a small \c{o}, which
is used to specify the output file name. See \k{opt-o}.
\S{opt-t} The \i\c{-t} option: Enable TASM Compatibility Mode
NASM includes a limited form of compatibility with Borland's \i\c{TASM}.
When NASM's \c{-t} option is used, the following changes are made:
\b local labels may be prefixed with \c{@@} instead of \c{.}
\b size override is supported within brackets. In TASM compatible mode,
a size override inside square brackets changes the size of the operand,
and not the address type of the operand as it does in NASM syntax. E.g.
\c{mov eax,[DWORD val]} is valid syntax in TASM compatibility mode.
Note that you lose the ability to override the default address type for
the instruction.
\b unprefixed forms of some directives supported (\c{arg}, \c{elif},
\c{else}, \c{endif}, \c{if}, \c{ifdef}, \c{ifdifi}, \c{ifndef},
\c{include}, \c{local})
\S{opt-w} The \i\c{-w} Option: Enable or Disable Assembly \i{Warnings}
NASM can observe many conditions during the course of assembly which
are worth mentioning to the user, but not a sufficiently severe
error to justify NASM refusing to generate an output file. These
conditions are reported like errors, but come up with the word
`warning' before the message. Warnings do not prevent NASM from
generating an output file and returning a success status to the
operating system.
Some conditions are even less severe than that: they are only
sometimes worth mentioning to the user. Therefore NASM supports the
\c{-w} command-line option, which enables or disables certain
classes of assembly warning. Such warning classes are described by a
name, for example \c{orphan-labels}; you can enable warnings of
this class by the command-line option \c{-w+orphan-labels} and
disable it by \c{-w-orphan-labels}.
The \i{suppressible warning} classes are:
\b \i\c{error} decides if warnings should be treated as errors.
It is disabled by default.
\b \i\c{macro-params} covers warnings about \i{multi-line macros}
being invoked with the wrong number of parameters. This warning
class is enabled by default; see \k{mlmacover} for an example of why
you might want to disable it.
\b \i\c{macro-selfref} warns if a macro references itself. This
warning class is disabled by default.
\b\i\c{macro-defaults} warns when a macro has more default
parameters than optional parameters. This warning class
is enabled by default; see \k{mlmacdef} for why you might want to disable it.
\b \i\c{orphan-labels} covers warnings about source lines which
contain no instruction but define a label without a trailing colon.
NASM warns about this somewhat obscure condition by default;
see \k{syntax} for more information.
\b \i\c{number-overflow} covers warnings about numeric constants which
don't fit in 64 bits. This warning class is enabled by default.
\b \i\c{gnu-elf-extensions} warns if 8-bit or 16-bit relocations
are used in \c{-f elf} format. The GNU extensions allow this.
This warning class is disabled by default.
\b \i\c{float-overflow} warns about floating point overflow.
Enabled by default.
\b \i\c{float-denorm} warns about floating point denormals.
Disabled by default.
\b \i\c{float-underflow} warns about floating point underflow.
Disabled by default.
\b \i\c{float-toolong} warns about too many digits in floating-point numbers.
Enabled by default.
\b \i\c{user} controls \c{%warning} directives (see \k{pperror}).
Enabled by default.
In addition, you can set warning classes across sections.
Warning classes may be enabled with \i\c{[warning +warning-name]},
disabled with \i\c{[warning -warning-name]} or reset to their
original value with \i\c{[warning *warning-name]}. No "user form"
(without the brackets) exists.
\S{opt-v} The \i\c{-v} Option: Display \i{Version} Info
Typing \c{NASM -v} will display the version of NASM which you are using,
and the date on which it was compiled.
You will need the version number if you report a bug.
\S{opt-y} The \i\c{-y} Option: Display Available Debug Info Formats
Typing \c{nasm -f <option> -y} will display a list of the available
debug info formats for the given output format. The default format
is indicated by an asterisk. For example:
\c nasm -f elf -y
\c valid debug formats for 'elf32' output format are
\c ('*' denotes default):
\c * stabs ELF32 (i386) stabs debug format for Linux
\c dwarf elf32 (i386) dwarf debug format for Linux
\S{opt-pfix} The \i\c{--prefix} and \i\c{--postfix} Options.
The \c{--prefix} and \c{--postfix} options prepend or append
(respectively) the given argument to all \c{global} or
\c{extern} variables. E.g. \c{--prefix _} will prepend the
underscore to all global and external variables, as C sometimes
(but not always) likes it.
\S{nasmenv} The \i\c{NASMENV} \i{Environment} Variable
If you define an environment variable called \c{NASMENV}, the program
will interpret it as a list of extra command-line options, which are
processed before the real command line. You can use this to define
standard search directories for include files, by putting \c{-i}
options in the \c{NASMENV} variable.
The value of the variable is split up at white space, so that the
value \c{-s -ic:\\nasmlib} will be treated as two separate options.
However, that means that the value \c{-dNAME="my name"} won't do
what you might want, because it will be split at the space and the
NASM command-line processing will get confused by the two
nonsensical words \c{-dNAME="my} and \c{name"}.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -