⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nasmdoc2.htm

📁 nasm手册 大家可以看看 对要写汇编程序的帮助很大
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<html><head><title>NASM Manual</title></head><body><h1 align=center>The Netwide Assembler: NASM</h1><p align=center><a href="nasmdoc3.html">Next Chapter</a> |<a href="nasmdoc1.html">Previous Chapter</a> |<a href="nasmdoc0.html">Contents</a> |<a href="nasmdoci.html">Index</a><h2><a name="chapter-2">Chapter 2: Running NASM</a></h2><h3><a name="section-2.1">2.1 NASM Command-Line Syntax</a></h3><p>To assemble a file, you issue a command of the form<p><pre>nasm -f &lt;format&gt; &lt;filename&gt; [-o &lt;output&gt;]</pre><p>For example,<p><pre>nasm -f elf myfile.asm</pre><p>will assemble <code><nobr>myfile.asm</nobr></code> into an<code><nobr>ELF</nobr></code> object file<code><nobr>myfile.o</nobr></code>. And<p><pre>nasm -f bin myfile.asm -o myfile.com</pre><p>will assemble <code><nobr>myfile.asm</nobr></code> into a raw binaryfile <code><nobr>myfile.com</nobr></code>.<p>To produce a listing file, with the hex codes output from NASM displayedon the left of the original sources, use the <code><nobr>-l</nobr></code>option to give a listing file name, for example:<p><pre>nasm -f coff myfile.asm -l myfile.lst</pre><p>To get further usage instructions from NASM, try typing<p><pre>nasm -h</pre><p>As <code><nobr>-hf</nobr></code>, this will also list the availableoutput file formats, and what they are.<p>If you use Linux but aren't sure whether your system is<code><nobr>a.out</nobr></code> or <code><nobr>ELF</nobr></code>, type<p><pre>file nasm</pre><p>(in the directory in which you put the NASM binary when you installedit). If it says something like<p><pre>nasm: ELF 32-bit LSB executable i386 (386 and up) Version 1</pre><p>then your system is <code><nobr>ELF</nobr></code>, and you should usethe option <code><nobr>-f elf</nobr></code> when you want NASM to produceLinux object files. If it says<p><pre>nasm: Linux/i386 demand-paged executable (QMAGIC)</pre><p>or something similar, your system is <code><nobr>a.out</nobr></code>,and you should use <code><nobr>-f aout</nobr></code> instead (Linux<code><nobr>a.out</nobr></code> systems have long been obsolete, and arerare these days.)<p>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.<h4><a name="section-2.1.1">2.1.1 The <code><nobr>-o</nobr></code> Option: Specifying the Output File Name</a></h4><p>NASM will normally choose the name of your output file for you;precisely how it does this is dependent on the object file format. ForMicrosoft object file formats (<code><nobr>obj</nobr></code> and<code><nobr>win32</nobr></code>), it will remove the<code><nobr>.asm</nobr></code> extension (or whatever extension you like touse - NASM doesn't care) from your source file name and substitute<code><nobr>.obj</nobr></code>. For Unix object file formats(<code><nobr>aout</nobr></code>, <code><nobr>coff</nobr></code>,<code><nobr>elf</nobr></code> and <code><nobr>as86</nobr></code>) it willsubstitute <code><nobr>.o</nobr></code>. For <code><nobr>rdf</nobr></code>,it will use <code><nobr>.rdf</nobr></code>, and for the<code><nobr>bin</nobr></code> format it will simply remove the extension,so that <code><nobr>myfile.asm</nobr></code> produces the output file<code><nobr>myfile</nobr></code>.<p>If the output file already exists, NASM will overwrite it, unless it hasthe same name as the input file, in which case it will give a warning anduse <code><nobr>nasm.out</nobr></code> as the output file name instead.<p>For situations in which this behaviour is unacceptable, NASM providesthe <code><nobr>-o</nobr></code> command-line option, which allows you tospecify your desired output file name. You invoke<code><nobr>-o</nobr></code> by following it with the name you wish for theoutput file, either with or without an intervening space. For example:<p><pre>nasm -f bin program.asm -o program.com nasm -f bin driver.asm -odriver.sys</pre><p>Note that this is a small o, and is different from a capital O , whichis used to specify the number of optimisation passes required. See<a href="#section-2.1.16">section 2.1.16</a>.<h4><a name="section-2.1.2">2.1.2 The <code><nobr>-f</nobr></code> Option: Specifying the Output File Format</a></h4><p>If you do not supply the <code><nobr>-f</nobr></code> option to NASM, itwill choose an output file format for you itself. In the distributionversions of NASM, the default is always <code><nobr>bin</nobr></code>; ifyou've compiled your own copy of NASM, you can redefine<code><nobr>OF_DEFAULT</nobr></code> at compile time and choose what youwant the default to be.<p>Like <code><nobr>-o</nobr></code>, the intervening space between<code><nobr>-f</nobr></code> and the output file format is optional; so<code><nobr>-f elf</nobr></code> and <code><nobr>-felf</nobr></code> areboth valid.<p>A complete list of the available output file formats can be given byissuing the command <code><nobr>nasm -hf</nobr></code>.<h4><a name="section-2.1.3">2.1.3 The <code><nobr>-l</nobr></code> Option: Generating a Listing File</a></h4><p>If you supply the <code><nobr>-l</nobr></code> option to NASM, followed(with the usual optional space) by a file name, NASM will generate asource-listing file for you, in which addresses and generated code arelisted on the left, and the actual source code, with expansions ofmulti-line macros (except those which specifically request no expansion insource listings: see <a href="nasmdoc4.html#section-4.3.9">section4.3.9</a>) on the right. For example:<p><pre>nasm -f elf myfile.asm -l myfile.lst</pre><p>If a list file is selected, you may turn off listing for a section ofyour source with <code><nobr>[list -]</nobr></code>, and turn it back onwith <code><nobr>[list +]</nobr></code>, (the default, obviously). There isno "user form" (without the brackets). This can be used to list onlysections of interest, avoiding excessively long listings.<h4><a name="section-2.1.4">2.1.4 The <code><nobr>-M</nobr></code> Option: Generate Makefile Dependencies.</a></h4><p>This option can be used to generate makefile dependencies on stdout.This can be redirected to a file for further processing. For example:<p><pre>NASM -M myfile.asm &gt; myfile.dep</pre><h4><a name="section-2.1.5">2.1.5 The <code><nobr>-F</nobr></code> Option: Selecting a Debug Information Format</a></h4><p>This option is used to select the format of the debug informationemitted into the output file, to be used by a debugger (or <em>will</em>be). Use of this switch does <em>not</em> enable output of the selecteddebug info format. Use <code><nobr>-g</nobr></code>, see<a href="#section-2.1.6">section 2.1.6</a>, to enable output.<p>A complete list of the available debug file formats for an output formatcan be seen by issuing the command<code><nobr>nasm -f &lt;format&gt; -y</nobr></code>. (only "borland" in "-fobj", as of 0.98.35, but "watch this space") See:<a href="#section-2.1.20">section 2.1.20</a>.<p>This should not be confused with the "-f dbg" output format option whichis not built into NASM by default. For information on how to enable it whenbuilding from the sources, see <a href="nasmdoc6.html#section-6.10">section6.10</a><h4><a name="section-2.1.6">2.1.6 The <code><nobr>-g</nobr></code> Option: Enabling Debug Information.</a></h4><p>This option can be used to generate debugging information in thespecified format. See: <a href="#section-2.1.5">section 2.1.5</a>. Using<code><nobr>-g</nobr></code> without <code><nobr>-F</nobr></code> resultsin emitting debug info in the default format, if any, for the selectedoutput format. If no debug information is currently implemented in theselected output format, <code><nobr>-g</nobr></code> is <em>silentlyignored</em>.<h4><a name="section-2.1.7">2.1.7 The <code><nobr>-X</nobr></code> Option: Selecting an Error Reporting Format</a></h4><p>This option can be used to select an error reporting format for anyerror messages that might be produced by NASM.<p>Currently, two error reporting formats may be selected. They are the<code><nobr>-Xvc</nobr></code> option and the<code><nobr>-Xgnu</nobr></code> option. The GNU format is the default andlooks like this:<p><pre>filename.asm:65: error: specific error message </pre><p>where <code><nobr>filename.asm</nobr></code> is the name of the sourcefile in which the error was detected, <code><nobr>65</nobr></code> is thesource file line number on which the error was detected,<code><nobr>error</nobr></code> is the severity of the error (this could be<code><nobr>warning</nobr></code>), and<code><nobr>specific error message</nobr></code> is a more detailed textmessage which should help pinpoint the exact problem.<p>The other format, specified by <code><nobr>-Xvc</nobr></code> is thestyle used by Microsoft Visual C++ and some other programs. It looks likethis:<p><pre>filename.asm(65) : error: specific error message</pre><p>where the only difference is that the line number is in parenthesesinstead of being delimited by colons.<p>See also the <code><nobr>Visual C++</nobr></code> output format,<a href="nasmdoc6.html#section-6.3">section 6.3</a>.<h4><a name="section-2.1.8">2.1.8 The <code><nobr>-E</nobr></code> Option: Send Errors to a File</a></h4><p>Under <code><nobr>MS-DOS</nobr></code> it can be difficult (though thereare ways) to redirect the standard-error output of a program to a file.Since NASM usually produces its warning and error messages on<code><nobr>stderr</nobr></code>, this can make it hard to capture theerrors if (for example) you want to load them into an editor.<p>NASM therefore provides the <code><nobr>-E</nobr></code> option, takinga filename argument which causes errors to be sent to the specified filesrather than standard error. Therefore you can redirect the errors into afile by typing<p><pre>nasm -E myfile.err -f obj myfile.asm</pre><h4><a name="section-2.1.9">2.1.9 The <code><nobr>-s</nobr></code> Option: Send Errors to <code><nobr>stdout</nobr></code></a></h4><p>The <code><nobr>-s</nobr></code> option redirects error messages to<code><nobr>stdout</nobr></code> rather than<code><nobr>stderr</nobr></code>, so it can be redirected under

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -