📄 nasmdoc2.htm
字号:
<code><nobr>MS-DOS</nobr></code>. To assemble the file<code><nobr>myfile.asm</nobr></code> and pipe its output to the<code><nobr>more</nobr></code> program, you can type:<p><pre>nasm -s -f obj myfile.asm | more</pre><p>See also the <code><nobr>-E</nobr></code> option,<a href="#section-2.1.8">section 2.1.8</a>.<h4><a name="section-2.1.10">2.1.10 The <code><nobr>-i</nobr></code> Option: Include File Search Directories</a></h4><p>When NASM sees the <code><nobr>%include</nobr></code> or<code><nobr>incbin</nobr></code> directive in a source file (see<a href="nasmdoc4.html#section-4.6">section 4.6</a> or<a href="nasmdoc3.html#section-3.2.3">section 3.2.3</a>), it will searchfor the given file not only in the current directory, but also in anydirectories specified on the command line by the use of the<code><nobr>-i</nobr></code> option. Therefore you can include files from amacro library, for example, by typing<p><pre>nasm -ic:\macrolib\ -f obj myfile.asm</pre><p>(As usual, a space between <code><nobr>-i</nobr></code> and the pathname is allowed, and optional).<p>NASM, in the interests of complete source-code portability, does notunderstand the file naming conventions of the OS it is running on; thestring you provide as an argument to the <code><nobr>-i</nobr></code>option will be prepended exactly as written to the name of the includefile. Therefore the trailing backslash in the above example is necessary.Under Unix, a trailing forward slash is similarly necessary.<p>(You can use this to your advantage, if you're really perverse, bynoting that the option <code><nobr>-ifoo</nobr></code> will cause<code><nobr>%include "bar.i"</nobr></code> to search for the file<code><nobr>foobar.i</nobr></code>...)<p>If you want to define a <em>standard</em> include search path, similarto <code><nobr>/usr/include</nobr></code> on Unix systems, you should placeone or more <code><nobr>-i</nobr></code> directives in the<code><nobr>NASMENV</nobr></code> environment variable (see<a href="#section-2.1.22">section 2.1.22</a>).<p>For Makefile compatibility with many C compilers, this option can alsobe specified as <code><nobr>-I</nobr></code>.<h4><a name="section-2.1.11">2.1.11 The <code><nobr>-p</nobr></code> Option: Pre-Include a File</a></h4><p>NASM allows you to specify files to be <em>pre-included</em> into yoursource file, by the use of the <code><nobr>-p</nobr></code> option. Sorunning<p><pre>nasm myfile.asm -p myinc.inc</pre><p>is equivalent to running <code><nobr>nasm myfile.asm</nobr></code> andplacing the directive <code><nobr>%include "myinc.inc"</nobr></code> at thestart of the file.<p>For consistency with the <code><nobr>-I</nobr></code>,<code><nobr>-D</nobr></code> and <code><nobr>-U</nobr></code> options, thisoption can also be specified as <code><nobr>-P</nobr></code>.<h4><a name="section-2.1.12">2.1.12 The <code><nobr>-d</nobr></code> Option: Pre-Define a Macro</a></h4><p>Just as the <code><nobr>-p</nobr></code> option gives an alternative toplacing <code><nobr>%include</nobr></code> directives at the start of asource file, the <code><nobr>-d</nobr></code> option gives an alternativeto placing a <code><nobr>%define</nobr></code> directive. You could code<p><pre>nasm myfile.asm -dFOO=100</pre><p>as an alternative to placing the directive<p><pre>%define FOO 100</pre><p>at the start of the file. You can miss off the macro value, as well: theoption <code><nobr>-dFOO</nobr></code> is equivalent to coding<code><nobr>%define FOO</nobr></code>. This form of the directive may beuseful for selecting assembly-time options which are then tested using<code><nobr>%ifdef</nobr></code>, for example<code><nobr>-dDEBUG</nobr></code>.<p>For Makefile compatibility with many C compilers, this option can alsobe specified as <code><nobr>-D</nobr></code>.<h4><a name="section-2.1.13">2.1.13 The <code><nobr>-u</nobr></code> Option: Undefine a Macro</a></h4><p>The <code><nobr>-u</nobr></code> option undefines a macro that wouldotherwise have been pre-defined, either automatically or by a<code><nobr>-p</nobr></code> or <code><nobr>-d</nobr></code> optionspecified earlier on the command lines.<p>For example, the following command line:<p><pre>nasm myfile.asm -dFOO=100 -uFOO</pre><p>would result in <code><nobr>FOO</nobr></code> <em>not</em> being apredefined macro in the program. This is useful to override optionsspecified at a different point in a Makefile.<p>For Makefile compatibility with many C compilers, this option can alsobe specified as <code><nobr>-U</nobr></code>.<h4><a name="section-2.1.14">2.1.14 The <code><nobr>-e</nobr></code> Option: Preprocess Only</a></h4><p>NASM allows the preprocessor to be run on its own, up to a point. Usingthe <code><nobr>-e</nobr></code> option (which requires no arguments) willcause NASM to preprocess its input file, expand all the macro references,remove all the comments and preprocessor directives, and print theresulting file on standard output (or save it to a file, if the<code><nobr>-o</nobr></code> option is also used).<p>This option cannot be applied to programs which require the preprocessorto evaluate expressions which depend on the values of symbols: so code suchas<p><pre>%assign tablesize ($-tablestart)</pre><p>will cause an error in preprocess-only mode.<h4><a name="section-2.1.15">2.1.15 The <code><nobr>-a</nobr></code> Option: Don't Preprocess At All</a></h4><p>If NASM is being used as the back end to a compiler, it might bedesirable to suppress preprocessing completely and assume the compiler hasalready done it, to save time and increase compilation speeds. The<code><nobr>-a</nobr></code> option, requiring no argument, instructs NASMto replace its powerful preprocessor with a stub preprocessor which doesnothing.<h4><a name="section-2.1.16">2.1.16 The <code><nobr>-On</nobr></code> Option: Specifying Multipass Optimization.</a></h4><p>NASM defaults to being a two pass assembler. This means that if you havea complex source file which needs more than 2 passes to assemble optimally,you have to enable extra passes.<p>Using the <code><nobr>-O</nobr></code> option, you can tell NASM tocarry out multiple passes. The syntax is:<ul><li><code><nobr>-O0</nobr></code> strict two-pass assembly, JMP and Jcc arehandled more like v0.98, except that backward JMPs are short, if possible.Immediate operands take their long forms if a short form is not specified.<li><code><nobr>-O1</nobr></code> strict two-pass assembly, but forwardbranches are assembled with code guaranteed to reach; may produce largercode than -O0, but will produce successful assembly more often if branchoffset sizes are not specified. Additionally, immediate operands which willfit in a signed byte are optimised, unless the long form is specified.<li><code><nobr>-On</nobr></code> multi-pass optimization, minimize branchoffsets; also will minimize signed immediate bytes, overriding sizespecification unless the <code><nobr>strict</nobr></code> keyword has beenused (see <a href="nasmdoc3.html#section-3.7">section 3.7</a>). The numberspecifies the maximum number of passes. The more passes, the better thecode, but the slower is the assembly.</ul><p>Note that this is a capital O, and is different from a small o, which isused to specify the output format. See <a href="#section-2.1.1">section2.1.1</a>.<h4><a name="section-2.1.17">2.1.17 The <code><nobr>-t</nobr></code> option: Enable TASM Compatibility Mode</a></h4><p>NASM includes a limited form of compatibility with Borland's<code><nobr>TASM</nobr></code>. When NASM's <code><nobr>-t</nobr></code>option is used, the following changes are made:<ul><li>local labels may be prefixed with <code><nobr>@@</nobr></code> insteadof <code><nobr>.</nobr></code><li>TASM-style response files beginning with <code><nobr>@</nobr></code>may be specified on the command line. This is different from the<code><nobr>-@resp</nobr></code> style that NASM natively supports.<li>size override is supported within brackets. In TASM compatible mode, asize override inside square brackets changes the size of the operand, andnot the address type of the operand as it does in NASM syntax. E.g.<code><nobr>mov eax,[DWORD val]</nobr></code> is valid syntax in TASMcompatibility mode. Note that you lose the ability to override the defaultaddress type for the instruction.<li><code><nobr>%arg</nobr></code> preprocessor directive is supportedwhich is similar to TASM's <code><nobr>ARG</nobr></code> directive.<li><code><nobr>%local</nobr></code> preprocessor directive<li><code><nobr>%stacksize</nobr></code> preprocessor directive<li>unprefixed forms of some directives supported(<code><nobr>arg</nobr></code>, <code><nobr>elif</nobr></code>,<code><nobr>else</nobr></code>, <code><nobr>endif</nobr></code>,<code><nobr>if</nobr></code>, <code><nobr>ifdef</nobr></code>,<code><nobr>ifdifi</nobr></code>, <code><nobr>ifndef</nobr></code>,<code><nobr>include</nobr></code>, <code><nobr>local</nobr></code>)<li>more...</ul><p>For more information on the directives, see the section on TASMCompatiblity preprocessor directives in<a href="nasmdoc4.html#section-4.9">section 4.9</a>.<h4><a name="section-2.1.18">2.1.18 The <code><nobr>-w</nobr></code> Option: Enable or Disable Assembly Warnings</a></h4><p>NASM can observe many conditions during the course of assembly which areworth mentioning to the user, but not a sufficiently severe error tojustify NASM refusing to generate an output file. These conditions arereported like errors, but come up with the word `warning' before themessage. Warnings do not prevent NASM from generating an output file andreturning a success status to the operating system.<p>Some conditions are even less severe than that: they are only sometimesworth mentioning to the user. Therefore NASM supports the<code><nobr>-w</nobr></code> command-line option, which enables or disablescertain classes of assembly warning. Such warning classes are described bya name, for example <code><nobr>orphan-labels</nobr></code>; you can enablewarnings of this class by the command-line option<code><nobr>-w+orphan-labels</nobr></code> and disable it by<code><nobr>-w-orphan-labels</nobr></code>.<p>The suppressible warning classes are:<ul><li><code><nobr>macro-params</nobr></code> covers warnings about multi-linemacros being invoked with the wrong number of parameters. This warningclass is enabled by default; see<a href="nasmdoc4.html#section-4.3.1">section 4.3.1</a> for an example ofwhy you might want to disable it.<li><code><nobr>macro-selfref</nobr></code> warns if a macro referencesitself. This warning class is enabled by default.<li><code><nobr>orphan-labels</nobr></code> covers warnings about sourcelines which contain no instruction but define a label without a trailingcolon. NASM does not warn about this somewhat obscure condition by default;see <a href="nasmdoc3.html#section-3.1">section 3.1</a> for an example of
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -