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

📄 nasmdoc6.htm

📁 nasm手册 大家可以看看 对要写汇编程序的帮助很大
💻 HTM
📖 第 1 页 / 共 4 页
字号:
global  hashtable:data (hashtable.end - hashtable) hashtable:         db this,that,theother  ; some data here .end:</pre><p>This makes NASM automatically calculate the length of the table andplace that information into the <code><nobr>ELF</nobr></code> symbol table.<p>Declaring the type and size of global symbols is necessary when writingshared library code. For more information, see<a href="nasmdoc8.html#section-8.2.4">section 8.2.4</a>.<h4><a name="section-6.5.4">6.5.4 <code><nobr>elf</nobr></code> Extensions to the <code><nobr>COMMON</nobr></code> Directive </a></h4><p><code><nobr>ELF</nobr></code> also allows you to specify alignmentrequirements on common variables. This is done by putting a number (whichmust be a power of two) after the name and size of the common variable,separated (as usual) by a colon. For example, an array of doublewords wouldbenefit from 4-byte alignment:<p><pre>common  dwordarray 128:4</pre><p>This declares the total size of the array to be 128 bytes, and requiresthat it be aligned on a 4-byte boundary.<h4><a name="section-6.5.5">6.5.5 16-bit code and ELF </a></h4><p>The <code><nobr>ELF32</nobr></code> specification doesn't providerelocations for 8- and 16-bit values, but the GNU<code><nobr>ld</nobr></code> linker adds these as an extension. NASM cangenerate GNU-compatible relocations, to allow 16-bit code to be linked asELF using GNU <code><nobr>ld</nobr></code>. If NASM is used with the<code><nobr>-w+gnu-elf-extensions</nobr></code> option, a warning is issuedwhen one of these relocations is generated.<h3><a name="section-6.6">6.6 <code><nobr>aout</nobr></code>: Linux <code><nobr>a.out</nobr></code> Object Files</a></h3><p>The <code><nobr>aout</nobr></code> format generates<code><nobr>a.out</nobr></code> object files, in the form used by earlyLinux systems (current Linux systems use ELF, see<a href="#section-6.5">section 6.5</a>.) These differ from other<code><nobr>a.out</nobr></code> object files in that the magic number inthe first four bytes of the file is different; also, some implementationsof <code><nobr>a.out</nobr></code>, for example NetBSD's, supportposition-independent code, which Linux's implementation does not.<p><code><nobr>a.out</nobr></code> provides a default output file-nameextension of <code><nobr>.o</nobr></code>.<p><code><nobr>a.out</nobr></code> is a very simple object format. Itsupports no special directives, no special symbols, no use of<code><nobr>SEG</nobr></code> or <code><nobr>WRT</nobr></code>, and noextensions to any standard directives. It supports only the three standardsection names <code><nobr>.text</nobr></code>,<code><nobr>.data</nobr></code> and <code><nobr>.bss</nobr></code>.<h3><a name="section-6.7">6.7 <code><nobr>aoutb</nobr></code>: NetBSD/FreeBSD/OpenBSD <code><nobr>a.out</nobr></code> Object Files</a></h3><p>The <code><nobr>aoutb</nobr></code> format generates<code><nobr>a.out</nobr></code> object files, in the form used by thevarious free <code><nobr>BSD Unix</nobr></code> clones,<code><nobr>NetBSD</nobr></code>, <code><nobr>FreeBSD</nobr></code> and<code><nobr>OpenBSD</nobr></code>. For simple object files, this objectformat is exactly the same as <code><nobr>aout</nobr></code> except for themagic number in the first four bytes of the file. However, the<code><nobr>aoutb</nobr></code> format supports position-independent codein the same way as the <code><nobr>elf</nobr></code> format, so you can useit to write <code><nobr>BSD</nobr></code> shared libraries.<p><code><nobr>aoutb</nobr></code> provides a default output file-nameextension of <code><nobr>.o</nobr></code>.<p><code><nobr>aoutb</nobr></code> supports no special directives, nospecial symbols, and only the three standard section names<code><nobr>.text</nobr></code>, <code><nobr>.data</nobr></code> and<code><nobr>.bss</nobr></code>. However, it also supports the same use of<code><nobr>WRT</nobr></code> as <code><nobr>elf</nobr></code> does, toprovide position-independent code relocation types. See<a href="#section-6.5.2">section 6.5.2</a> for full documentation of thisfeature.<p><code><nobr>aoutb</nobr></code> also supports the same extensions to the<code><nobr>GLOBAL</nobr></code> directive as <code><nobr>elf</nobr></code>does: see <a href="#section-6.5.3">section 6.5.3</a> for documentation ofthis.<h3><a name="section-6.8">6.8 <code><nobr>as86</nobr></code>: Minix/Linux <code><nobr>as86</nobr></code> Object Files</a></h3><p>The Minix/Linux 16-bit assembler <code><nobr>as86</nobr></code> has itsown non-standard object file format. Although its companion linker<code><nobr>ld86</nobr></code> produces something close to ordinary<code><nobr>a.out</nobr></code> binaries as output, the object file formatused to communicate between <code><nobr>as86</nobr></code> and<code><nobr>ld86</nobr></code> is not itself<code><nobr>a.out</nobr></code>.<p>NASM supports this format, just in case it is useful, as<code><nobr>as86</nobr></code>. <code><nobr>as86</nobr></code> provides adefault output file-name extension of <code><nobr>.o</nobr></code>.<p><code><nobr>as86</nobr></code> is a very simple object format (from theNASM user's point of view). It supports no special directives, no specialsymbols, no use of <code><nobr>SEG</nobr></code> or<code><nobr>WRT</nobr></code>, and no extensions to any standarddirectives. It supports only the three standard section names<code><nobr>.text</nobr></code>, <code><nobr>.data</nobr></code> and<code><nobr>.bss</nobr></code>.<h3><a name="section-6.9">6.9 <code><nobr>rdf</nobr></code>: Relocatable Dynamic Object File Format</a></h3><p>The <code><nobr>rdf</nobr></code> output format produces<code><nobr>RDOFF</nobr></code> object files.<code><nobr>RDOFF</nobr></code> (Relocatable Dynamic Object File Format) isa home-grown object-file format, designed alongside NASM itself andreflecting in its file format the internal structure of the assembler.<p><code><nobr>RDOFF</nobr></code> is not used by any well-known operatingsystems. Those writing their own systems, however, may well wish to use<code><nobr>RDOFF</nobr></code> as their object format, on the grounds thatit is designed primarily for simplicity and contains very littlefile-header bureaucracy.<p>The Unix NASM archive, and the DOS archive which includes sources, bothcontain an <code><nobr>rdoff</nobr></code> subdirectory holding a set ofRDOFF utilities: an RDF linker, an <code><nobr>RDF</nobr></code>static-library manager, an RDF file dump utility, and a program which willload and execute an RDF executable under Linux.<p><code><nobr>rdf</nobr></code> supports only the standard section names<code><nobr>.text</nobr></code>, <code><nobr>.data</nobr></code> and<code><nobr>.bss</nobr></code>.<h4><a name="section-6.9.1">6.9.1 Requiring a Library: The <code><nobr>LIBRARY</nobr></code> Directive</a></h4><p><code><nobr>RDOFF</nobr></code> contains a mechanism for an object fileto demand a given library to be linked to the module, either at load timeor run time. This is done by the <code><nobr>LIBRARY</nobr></code>directive, which takes one argument which is the name of the module:<p><pre>    library  mylib.rdl</pre><h4><a name="section-6.9.2">6.9.2 Specifying a Module Name: The <code><nobr>MODULE</nobr></code> Directive</a></h4><p>Special <code><nobr>RDOFF</nobr></code> header record is used to storethe name of the module. It can be used, for example, by run-time loader toperform dynamic linking. <code><nobr>MODULE</nobr></code> directive takesone argument which is the name of current module:<p><pre>    module  mymodname</pre><p>Note that when you statically link modules and tell linker to strip thesymbols from output file, all module names will be stripped too. To avoidit, you should start module names with <code><nobr>$</nobr></code>, like:<p><pre>    module  $kernel.core</pre><h4><a name="section-6.9.3">6.9.3 <code><nobr>rdf</nobr></code> Extensions to the <code><nobr>GLOBAL</nobr></code> directive</a></h4><p><code><nobr>RDOFF</nobr></code> global symbols can contain additionalinformation needed by the static linker. You can mark a global symbol asexported, thus telling the linker do not strip it from target executable orlibrary file. Like in <code><nobr>ELF</nobr></code>, you can also specifywhether an exported symbol is a procedure (function) or data object.<p>Suffixing the name with a colon and the word<code><nobr>export</nobr></code> you make the symbol exported:<p><pre>    global  sys_open:export</pre><p>To specify that exported symbol is a procedure (function), you add theword <code><nobr>proc</nobr></code> or <code><nobr>function</nobr></code>after declaration:<p><pre>    global  sys_open:export proc</pre><p>Similarly, to specify exported data object, add the word<code><nobr>data</nobr></code> or <code><nobr>object</nobr></code> to thedirective:<p><pre>    global  kernel_ticks:export data</pre><h3><a name="section-6.10">6.10 <code><nobr>dbg</nobr></code>: Debugging Format</a></h3><p>The <code><nobr>dbg</nobr></code> output format is not built into NASMin the default configuration. If you are building your own NASM executablefrom the sources, you can define <code><nobr>OF_DBG</nobr></code> in<code><nobr>outform.h</nobr></code> or on the compiler command line, andobtain the <code><nobr>dbg</nobr></code> output format.<p>The <code><nobr>dbg</nobr></code> format does not output an object fileas such; instead, it outputs a text file which contains a complete list ofall the transactions between the main body of NASM and the output-formatback end module. It is primarily intended to aid people who want to writetheir own output drivers, so that they can get a clearer idea of thevarious requests the main program makes of the output driver, and in whatorder they happen.<p>For simple files, one can easily use the <code><nobr>dbg</nobr></code>format like this:<p><pre>nasm -f dbg filename.asm</pre><p>which will generate a diagnostic file called<code><nobr>filename.dbg</nobr></code>. However, this will not work well onfiles which were designed for a different object format, because eachobject format defines its own macros (usually user-level forms ofdirectives), and those macros will not be defined in the<code><nobr>dbg</nobr></code> format. Therefore it can be useful to runNASM twice, in order to do the preprocessing with the native object formatselected:<p><pre>nasm -e -f rdf -o rdfprog.i rdfprog.asm nasm -a -f dbg rdfprog.i</pre><p>This preprocesses <code><nobr>rdfprog.asm</nobr></code> into<code><nobr>rdfprog.i</nobr></code>, keeping the<code><nobr>rdf</nobr></code> object format selected in order to make sureRDF special directives are converted into primitive form correctly. Thenthe preprocessed source is fed through the <code><nobr>dbg</nobr></code>format to generate the final diagnostic output.<p>This workaround will still typically not work for programs intended for<code><nobr>obj</nobr></code> format, because the<code><nobr>obj</nobr></code> <code><nobr>SEGMENT</nobr></code> and<code><nobr>GROUP</nobr></code> directives have side effects of definingthe segment and group names as symbols; <code><nobr>dbg</nobr></code> willnot do this, so the program will not assemble. You will have to work aroundthat by defining the symbols yourself (using<code><nobr>EXTERN</nobr></code>, for example) if you really need to get a<code><nobr>dbg</nobr></code> trace of an<code><nobr>obj</nobr></code>-specific source file.<p><code><nobr>dbg</nobr></code> accepts any section name and anydirectives at all, and logs them all to its output file.<p align=center><a href="nasmdoc7.html">Next Chapter</a> |<a href="nasmdoc5.html">Previous Chapter</a> |<a href="nasmdoc0.html">Contents</a> |<a href="nasmdoci.html">Index</a></body></html>

⌨️ 快捷键说明

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