📄 nasmdoc.src
字号:
\W{ftp://ftp.kernel.org/pub/software/devel/nasm/}\i\c{ftp.kernel.org}
and
\W{ftp://ibiblio.org/pub/Linux/devel/lang/assemblers/}\i\c{ibiblio.org}.
Announcements are posted to
\W{news:comp.lang.asm.x86}\i\c{comp.lang.asm.x86},
\W{news:alt.lang.asm}\i\c{alt.lang.asm} and
\W{news:comp.os.linux.announce}\i\c{comp.os.linux.announce}
If you want information about NASM beta releases, and the current
development status, please subscribe to the \i\c{nasm-devel} email list
by registering at
\W{http://sourceforge.net/projects/nasm}\c{http://sourceforge.net/projects/nasm}.
\H{install} Installation
\S{instdos} \i{Installing} NASM under MS-\i{DOS} or Windows
Once you've obtained the appropriate archive for NASM,
\i\c{nasm-XXX-dos.zip} or \i\c{nasm-XXX-win32.zip} (where \c{XXX}
denotes the version number of NASM contained in the archive), unpack
it into its own directory (for example \c{c:\\nasm}).
The archive will contain a set of executable files: the NASM
executable file \i\c{nasm.exe}, the NDISASM executable file
\i\c{ndisasm.exe}, and possibly additional utilities to handle the
RDOFF file format.
The only file NASM needs to run is its own executable, so copy
\c{nasm.exe} to a directory on your PATH, or alternatively edit
\i\c{autoexec.bat} to add the \c{nasm} directory to your
\i\c{PATH} (to do that under Windows XP, go to Start > Control Panel >
System > Advanced > Environment Variables; these instructions may work
under other versions of Windows as well.)
That's it - NASM is installed. You don't need the nasm directory
to be present to run NASM (unless you've added it to your \c{PATH}),
so you can delete it if you need to save space; however, you may
want to keep the documentation or test programs.
If you've downloaded the \i{DOS source archive}, \i\c{nasm-XXX.zip},
the \c{nasm} directory will also contain the full NASM \i{source
code}, and a selection of \i{Makefiles} you can (hopefully) use to
rebuild your copy of NASM from scratch. See the file \c{INSTALL} in
the source archive.
Note that a number of files are generated from other files by Perl
scripts. Although the NASM source distribution includes these
generated files, you will need to rebuild them (and hence, will need a
Perl interpreter) if you change insns.dat, standard.mac or the
documentation. It is possible future source distributions may not
include these files at all. Ports of \i{Perl} for a variety of
platforms, including DOS and Windows, are available from
\W{http://www.cpan.org/ports/}\i{www.cpan.org}.
\S{instdos} Installing NASM under \i{Unix}
Once you've obtained the \i{Unix source archive} for NASM,
\i\c{nasm-XXX.tar.gz} (where \c{XXX} denotes the version number of
NASM contained in the archive), unpack it into a directory such
as \c{/usr/local/src}. The archive, when unpacked, will create its
own subdirectory \c{nasm-XXX}.
NASM is an \I{Autoconf}\I\c{configure}auto-configuring package: once
you've unpacked it, \c{cd} to the directory it's been unpacked into
and type \c{./configure}. This shell script will find the best C
compiler to use for building NASM and set up \i{Makefiles}
accordingly.
Once NASM has auto-configured, you can type \i\c{make} to build the
\c{nasm} and \c{ndisasm} binaries, and then \c{make install} to
install them in \c{/usr/local/bin} and install the \i{man pages}
\i\c{nasm.1} and \i\c{ndisasm.1} in \c{/usr/local/man/man1}.
Alternatively, you can give options such as \c{--prefix} to the
configure script (see the file \i\c{INSTALL} for more details), or
install the programs yourself.
NASM also comes with a set of utilities for handling the \c{RDOFF}
custom object-file format, which are in the \i\c{rdoff} subdirectory
of the NASM archive. You can build these with \c{make rdf} and
install them with \c{make rdf_install}, if you want them.
\C{running} Running NASM
\H{syntax} NASM \i{Command-Line} Syntax
To assemble a file, you issue a command of the form
\c nasm -f <format> <filename> [-o <output>]
For example,
\c nasm -f elf myfile.asm
will assemble \c{myfile.asm} into an \c{ELF} object file \c{myfile.o}. And
\c nasm -f bin myfile.asm -o myfile.com
will assemble \c{myfile.asm} into a raw binary file \c{myfile.com}.
To produce a listing file, with the hex codes output from NASM
displayed on the left of the original sources, use the \c{-l} option
to give a listing file name, for example:
\c nasm -f coff myfile.asm -l myfile.lst
To get further usage instructions from NASM, try typing
\c nasm -h
As \c{-hf}, this will also list the available output file formats, and what they
are.
If you use Linux but aren't sure whether your system is \c{a.out}
or \c{ELF}, type
\c file nasm
(in the directory in which you put the NASM binary when you
installed it). If it says something like
\c nasm: ELF 32-bit LSB executable i386 (386 and up) Version 1
then your system is \c{ELF}, and you should use the option \c{-f elf}
when you want NASM to produce Linux object files. If it says
\c nasm: Linux/i386 demand-paged executable (QMAGIC)
or something similar, your system is \c{a.out}, and you should use
\c{-f aout} instead (Linux \c{a.out} systems have long been obsolete,
and are rare these days.)
Like Unix compilers and assemblers, NASM is silent unless it
goes wrong: you won't see any output at all, unless it gives error
messages.
\S{opt-o} The \i\c{-o} Option: Specifying the Output File Name
NASM will normally choose the name of your output file for you;
precisely how it does this is dependent on the object file format.
For Microsoft object file formats (\i\c{obj} and \i\c{win32}), it
will remove the \c{.asm} \i{extension} (or whatever extension you
like to use - NASM doesn't care) from your source file name and
substitute \c{.obj}. For Unix object file formats (\i\c{aout},
\i\c{coff}, \i\c{elf}, \i\c{macho} and \i\c{as86}) it will substitute \c{.o}. For
\i\c{rdf}, it will use \c{.rdf}, and for the \i\c{bin} format it
will simply remove the extension, so that \c{myfile.asm} produces
the output file \c{myfile}.
If the output file already exists, NASM will overwrite it, unless it
has the same name as the input file, in which case it will give a
warning and use \i\c{nasm.out} as the output file name instead.
For situations in which this behaviour is unacceptable, NASM
provides the \c{-o} command-line option, which allows you to specify
your desired output file name. You invoke \c{-o} by following it
with the name you wish for the output file, either with or without
an intervening space. For example:
\c nasm -f bin program.asm -o program.com
\c nasm -f bin driver.asm -odriver.sys
Note that this is a small o, and is different from a capital O , which
is used to specify the number of optimisation passes required. See \k{opt-O}.
\S{opt-f} The \i\c{-f} Option: Specifying the \i{Output File Format}
If you do not supply the \c{-f} option to NASM, it will choose an
output file format for you itself. In the distribution versions of
NASM, the default is always \i\c{bin}; if you've compiled your own
copy of NASM, you can redefine \i\c{OF_DEFAULT} at compile time and
choose what you want the default to be.
Like \c{-o}, the intervening space between \c{-f} and the output
file format is optional; so \c{-f elf} and \c{-felf} are both valid.
A complete list of the available output file formats can be given by
issuing the command \i\c{nasm -hf}.
\S{opt-l} The \i\c{-l} Option: Generating a \i{Listing File}
If you supply the \c{-l} option to NASM, followed (with the usual
optional space) by a file name, NASM will generate a
\i{source-listing file} for you, in which addresses and generated
code are listed on the left, and the actual source code, with
expansions of multi-line macros (except those which specifically
request no expansion in source listings: see \k{nolist}) on the
right. For example:
\c nasm -f elf myfile.asm -l myfile.lst
If a list file is selected, you may turn off listing for a
section of your source with \c{[list -]}, and turn it back on
with \c{[list +]}, (the default, obviously). There is no "user
form" (without the brackets). This can be used to list only
sections of interest, avoiding excessively long listings.
\S{opt-M} The \i\c{-M} Option: Generate \i{Makefile Dependencies}
This option can be used to generate makefile dependencies on stdout.
This can be redirected to a file for further processing. For example:
\c nasm -M myfile.asm > myfile.dep
\S{opt-MG} The \i\c{-MG} Option: Generate \i{Makefile Dependencies}
This option can be used to generate makefile dependencies on stdout.
This differs from the \c{-M} option in that if a nonexisting file is
encountered, it is assumed to be a generated file and is added to the
dependency list without a prefix.
\S{opt-MF} The \i\c\{-MF} Option: Set Makefile Dependency File
This option can be used with the \c{-M} or \c{-MG} options to send the
output to a file, rather than to stdout. For example:
\c nasm -M -MF myfile.dep myfile.asm
\S{opt-MD} The \i\c{-MD} Option: Assemble and Generate Dependencies
The \c{-MD} option acts as the combination of the \c{-M} and \c{-MF}
options (i.e. a filename has to be specified.) However, unlike the
\c{-M} or \c{-MG} options, \c{-MD} does \e{not} inhibit the normal
operation of the assembler. Use this to automatically generate
updated dependencies with every assembly session. For example:
\c nasm -f elf -o myfile.o -MD myfile.dep myfile.asm
\S{opt-MT} The \i\c{-MT} Option: Dependency Target Name
The \c{-MT} option can be used to override the default name of the
dependency target. This is normally the same as the output filename,
specified by the \c{-o} option.
\S{opt-MQ} The \i\c{-MQ} Option: Dependency Target Name (Quoted)
The \c{-MQ} option acts as the \c{-MT} option, except it tries to
quote characters that have special meaning in Makefile syntax. This
is not foolproof, as not all characters with special meaning are
quotable in Make.
\S{opt-MP} The \i\c{-MP} Option: Emit phony targets
When used with any of the dependency generation options, the \c{-MP}
option causes NASM to emit a phony target without dependencies for
each header file. This prevents Make from complaining if a header
file has been removed.
\S{opt-F} The \i\c{-F} Option: Selecting a \i{Debug Information Format}
This option is used to select the format of the debug information
emitted into the output file, to be used by a debugger (or \e{will}
be). Prior to version 2.03.01, the use of this switch did \e{not} enable
output of the selected debug info format. Use \c{-g}, see \k{opt-g},
to enable output. Versions 2.03.01 and later automatically enable \c{-g}
if \c{-F} is specified.
A complete list of the available debug file formats for an output
format can be seen by issuing the command \c{nasm -f <format> -y}. Not
all output formats currently support debugging output. See \k{opt-y}.
This should not be confused with the \c{-f dbg} output format option which
is not built into NASM by default. For information on how
to enable it when building from the sources, see \k{dbgfmt}.
\S{opt-g} The \i\c{-g} Option: Enabling \i{Debug Information}.
This option can be used to generate debugging information in the specified
format. See \k{opt-F}. Using \c{-g} without \c{-F} results in emitting
debug info in the default format, if any, for the selected output format.
If no debug information is currently implemented in the selected output
format, \c{-g} is \e{silently ignored}.
\S{opt-X} The \i\c{-X} Option: Selecting an \i{Error Reporting Format}
This option can be used to select an error reporting format for any
error messages that might be produced by NASM.
Currently, two error reporting formats may be selected. They are
the \c{-Xvc} option and the \c{-Xgnu} option. The GNU format is
the default and looks like this:
\c filename.asm:65: error: specific error message
where \c{filename.asm} is the name of the source file in which the
error was detected, \c{65} is the source file line number on which
the error was detected, \c{error} is the severity of the error (this
could be \c{warning}), and \c{specific error message} is a more
detailed text message which should help pinpoint the exact problem.
The other format, specified by \c{-Xvc} is the style used by Microsoft
Visual C++ and some other programs. It looks like this:
\c filename.asm(65) : error: specific error message
where the only difference is that the line number is in parentheses
instead of being delimited by colons.
See also the \c{Visual C++} output format, \k{win32fmt}.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -