📄 nasmdoc5.htm
字号:
<code><nobr>__SECT__</nobr></code> macro when it is invoked.<p><code><nobr>STRUC</nobr></code> and <code><nobr>ENDSTRUC</nobr></code>are defined as macros which use <code><nobr>ABSOLUTE</nobr></code> (andalso <code><nobr>__SECT__</nobr></code>).<p><code><nobr>ABSOLUTE</nobr></code> doesn't have to take an absoluteconstant as an argument: it can take an expression (actually, a criticalexpression: see <a href="nasmdoc3.html#section-3.8">section 3.8</a>) and itcan be a value in a segment. For example, a TSR can re-use its setup codeas run-time BSS like this:<p><pre> org 100h ; it's a .COM program jmp setup ; setup code comes last ; the resident part of the TSR goes here setup: ; now write the code that installs the TSR here absolute setup runtimevar1 resw 1 runtimevar2 resd 20 tsr_end:</pre><p>This defines some variables `on top of' the setup code, so that afterthe setup has finished running, the space it took up can be re-used as datastorage for the running TSR. The symbol `tsr_end' can be used to calculatethe total size of the part of the TSR that needs to be made resident.<h3><a name="section-5.4">5.4 <code><nobr>EXTERN</nobr></code>: Importing Symbols from Other Modules</a></h3><p><code><nobr>EXTERN</nobr></code> is similar to the MASM directive<code><nobr>EXTRN</nobr></code> and the C keyword<code><nobr>extern</nobr></code>: it is used to declare a symbol which isnot defined anywhere in the module being assembled, but is assumed to bedefined in some other module and needs to be referred to by this one. Notevery object-file format can support external variables: the<code><nobr>bin</nobr></code> format cannot.<p>The <code><nobr>EXTERN</nobr></code> directive takes as many argumentsas you like. Each argument is the name of a symbol:<p><pre>extern _printf extern _sscanf,_fscanf</pre><p>Some object-file formats provide extra features to the<code><nobr>EXTERN</nobr></code> directive. In all cases, the extrafeatures are used by suffixing a colon to the symbol name followed byobject-format specific text. For example, the <code><nobr>obj</nobr></code>format allows you to declare that the default segment base of an externalshould be the group <code><nobr>dgroup</nobr></code> by means of thedirective<p><pre>extern _variable:wrt dgroup</pre><p>The primitive form of <code><nobr>EXTERN</nobr></code> differs from theuser-level form only in that it can take only one argument at a time: thesupport for multiple arguments is implemented at the preprocessor level.<p>You can declare the same variable as <code><nobr>EXTERN</nobr></code>more than once: NASM will quietly ignore the second and laterredeclarations. You can't declare a variable as<code><nobr>EXTERN</nobr></code> as well as something else, though.<h3><a name="section-5.5">5.5 <code><nobr>GLOBAL</nobr></code>: Exporting Symbols to Other Modules</a></h3><p><code><nobr>GLOBAL</nobr></code> is the other end of<code><nobr>EXTERN</nobr></code>: if one module declares a symbol as<code><nobr>EXTERN</nobr></code> and refers to it, then in order to preventlinker errors, some other module must actually <em>define</em> the symboland declare it as <code><nobr>GLOBAL</nobr></code>. Some assemblers use thename <code><nobr>PUBLIC</nobr></code> for this purpose.<p>The <code><nobr>GLOBAL</nobr></code> directive applying to a symbol mustappear <em>before</em> the definition of the symbol.<p><code><nobr>GLOBAL</nobr></code> uses the same syntax as<code><nobr>EXTERN</nobr></code>, except that it must refer to symbolswhich <em>are</em> defined in the same module as the<code><nobr>GLOBAL</nobr></code> directive. For example:<p><pre>global _main _main: ; some code</pre><p><code><nobr>GLOBAL</nobr></code>, like <code><nobr>EXTERN</nobr></code>,allows object formats to define private extensions by means of a colon. The<code><nobr>elf</nobr></code> object format, for example, lets you specifywhether global data items are functions or data:<p><pre>global hashlookup:function, hashtable:data</pre><p>Like <code><nobr>EXTERN</nobr></code>, the primitive form of<code><nobr>GLOBAL</nobr></code> differs from the user-level form only inthat it can take only one argument at a time.<h3><a name="section-5.6">5.6 <code><nobr>COMMON</nobr></code>: Defining Common Data Areas</a></h3><p>The <code><nobr>COMMON</nobr></code> directive is used to declare<em>common variables</em>. A common variable is much like a global variabledeclared in the uninitialised data section, so that<p><pre>common intvar 4</pre><p>is similar in function to<p><pre>global intvar section .bss intvar resd 1</pre><p>The difference is that if more than one module defines the same commonvariable, then at link time those variables will be <em>merged</em>, andreferences to <code><nobr>intvar</nobr></code> in all modules will point atthe same piece of memory.<p>Like <code><nobr>GLOBAL</nobr></code> and<code><nobr>EXTERN</nobr></code>, <code><nobr>COMMON</nobr></code> supportsobject-format specific extensions. For example, the<code><nobr>obj</nobr></code> format allows common variables to be NEAR orFAR, and the <code><nobr>elf</nobr></code> format allows you to specify thealignment requirements of a common variable:<p><pre>common commvar 4:near ; works in OBJ common intarray 100:4 ; works in ELF: 4 byte aligned</pre><p>Once again, like <code><nobr>EXTERN</nobr></code> and<code><nobr>GLOBAL</nobr></code>, the primitive form of<code><nobr>COMMON</nobr></code> differs from the user-level form only inthat it can take only one argument at a time.<h3><a name="section-5.7">5.7 <code><nobr>CPU</nobr></code>: Defining CPU Dependencies</a></h3><p>The <code><nobr>CPU</nobr></code> directive restricts assembly to thoseinstructions which are available on the specified CPU.<p>Options are:<ul><li><code><nobr>CPU 8086</nobr></code> Assemble only 8086 instruction set<li><code><nobr>CPU 186</nobr></code> Assemble instructions up to the 80186instruction set<li><code><nobr>CPU 286</nobr></code> Assemble instructions up to the 286instruction set<li><code><nobr>CPU 386</nobr></code> Assemble instructions up to the 386instruction set<li><code><nobr>CPU 486</nobr></code> 486 instruction set<li><code><nobr>CPU 586</nobr></code> Pentium instruction set<li><code><nobr>CPU PENTIUM</nobr></code> Same as 586<li><code><nobr>CPU 686</nobr></code> P6 instruction set<li><code><nobr>CPU PPRO</nobr></code> Same as 686<li><code><nobr>CPU P2</nobr></code> Same as 686<li><code><nobr>CPU P3</nobr></code> Pentium III (Katmai) instruction sets<li><code><nobr>CPU KATMAI</nobr></code> Same as P3<li><code><nobr>CPU P4</nobr></code> Pentium 4 (Willamette) instruction set<li><code><nobr>CPU WILLAMETTE</nobr></code> Same as P4<li><code><nobr>CPU PRESCOTT</nobr></code> Prescott instruction set<li><code><nobr>CPU IA64</nobr></code> IA64 CPU (in x86 mode) instructionset</ul><p>All options are case insensitive. All instructions will be selected onlyif they apply to the selected CPU or lower. By default, all instructionsare available.<p align=center><a href="nasmdoc6.html">Next Chapter</a> |<a href="nasmdoc4.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 + -