📄 nasmdoc.src
字号:
\S{opt-d} The \i\c{-d}\I\c{-D} Option: \I{pre-defining macros}Pre-Define a Macro\I\c{%define}Just as the \c{-p} option gives an alternative to placing\c{%include} directives at the start of a source file, the \c{-d}option gives an alternative to placing a \c{%define} directive. Youcould code\c nasm myfile.asm -dFOO=100as an alternative to placing the directive\c %define FOO 100at the start of the file. You can miss off the macro value, as well:the option \c{-dFOO} is equivalent to coding \c{%define FOO}. Thisform of the directive may be useful for selecting \i{assembly-timeoptions} which are then tested using \c{%ifdef}, for example\c{-dDEBUG}.For Makefile compatibility with many C compilers, this option can alsobe specified as \c{-D}.\S{opt-u} The \i\c{-u}\I\c{-U} Option: \I{Undefining macros}Undefine a Macro\I\c{%undef}The \c{-u} option undefines a macro that would otherwisehave been pre-defined, either automatically or by a \c{-p} or \c{-d}option specified earlier on the command lines.For example, the following command line:\c nasm myfile.asm -dFOO=100 -uFOOwould result in \c{FOO} \e{not} being a predefined macro in theprogram. This is useful to override options specified at a differentpoint in a Makefile.For Makefile compatibility with many C compilers, this option can alsobe specified as \c{-U}.\S{opt-e} The \i\c{-e} Option: Preprocess OnlyNASM allows the \i{preprocessor} to be run on its own, up to apoint. Using the \c{-e} option (which requires no arguments) willcause NASM to preprocess its input file, expand all the macroreferences, remove all the comments and preprocessor directives, andprint the resulting file on standard output (or save it to a file,if the \c{-o} option is also used).This option cannot be applied to programs which require thepreprocessor to evaluate \I{preprocessor expressions}\i{expressions}which depend on the values of symbols: so code such as\c %assign tablesize ($-tablestart)will cause an error in \i{preprocess-only mode}.\S{opt-a} The \i\c{-a} Option: Don't Preprocess At AllIf NASM is being used as the back end to a compiler, it might bedesirable to \I{suppressing preprocessing}suppress preprocessingcompletely and assume the compiler has already done it, to save timeand increase compilation speeds. The \c{-a} option, requiring noargument, instructs NASM to replace its powerful \i{preprocessor}with a \i{stub preprocessor} which does nothing.\S{opt-On} The \i\c{-On} Option: Specifying \i{Multipass Optimization}.NASM defaults to being a two pass assembler. This means that if youhave a complex source file which needs more than 2 passes to assembleoptimally, you have to enable extra passes.Using the \c{-O} option, you can tell NASM to carry out multiple passes.The syntax is:\b \c{-O0} strict two-pass assembly, JMP and Jcc are handled 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.\b \c{-O1} strict two-pass assembly, but forward branches are assembled with code guaranteed to reach; may produce larger code than -O0, but will produce successful assembly more often if branch offset sizes are not specified. Additionally, immediate operands which will fit in a signed byte are optimised, unless the long form is specified.\b \c{-On} multi-pass optimization, minimize branch offsets; also will minimize signed immediate bytes, overriding size specification unless the \c{strict} keyword has been used (see \k{strict}). The number specifies the maximum number of passes. The more passes, the better the code, but the slower is the assembly.Note that this is a capital O, and is different from a small o, whichis used to specify the output format. See \k{opt-o}.\S{opt-t} The \i\c{-t} option: Enable TASM Compatibility ModeNASM includes a limited form of compatibility with Borland's \i\c{TASM}.When NASM's \c{-t} option is used, the following changes are made:\b local labels may be prefixed with \c{@@} instead of \c{.}\b TASM-style response files beginning with \c{@} may be specified onthe command line. This is different from the \c{-@resp} style that NASMnatively supports.\b size override is supported within brackets. In TASM compatible mode,a size override inside square brackets changes the size of the operand,and not the address type of the operand as it does in NASM syntax. E.g.\c{mov eax,[DWORD val]} is valid syntax in TASM compatibility mode.Note that you lose the ability to override the default address type forthe instruction.\b \c{%arg} preprocessor directive is supported which is similar toTASM's \c{ARG} directive.\b \c{%local} preprocessor directive\b \c{%stacksize} preprocessor directive\b unprefixed forms of some directives supported (\c{arg}, \c{elif},\c{else}, \c{endif}, \c{if}, \c{ifdef}, \c{ifdifi}, \c{ifndef},\c{include}, \c{local})\b more...For more information on the directives, see the section on TASMCompatiblity preprocessor directives in \k{tasmcompat}.\S{opt-w} The \i\c{-w} Option: Enable or Disable Assembly \i{Warnings}NASM can observe many conditions during the course of assembly whichare worth mentioning to the user, but not a sufficiently severeerror to justify NASM refusing to generate an output file. Theseconditions are reported like errors, but come up with the word`warning' before the message. Warnings do not prevent NASM fromgenerating an output file and returning a success status to theoperating system.Some conditions are even less severe than that: they are onlysometimes worth mentioning to the user. Therefore NASM supports the\c{-w} command-line option, which enables or disables certainclasses of assembly warning. Such warning classes are described by aname, for example \c{orphan-labels}; you can enable warnings ofthis class by the command-line option \c{-w+orphan-labels} anddisable it by \c{-w-orphan-labels}.The \i{suppressible warning} classes are:\b \i\c{macro-params} covers warnings about \i{multi-line macros}being invoked with the wrong number of parameters. This warningclass is enabled by default; see \k{mlmacover} for an example of whyyou might want to disable it.\b \i\c{macro-selfref} warns if a macro references itself. This warning class is enabled by default.\b \i\c{orphan-labels} covers warnings about source lines whichcontain no instruction but define a label without a trailing colon.NASM does not warn about this somewhat obscure condition by default;see \k{syntax} for an example of why you might want it to.\b \i\c{number-overflow} covers warnings about numeric constants whichdon't fit in 32 bits (for example, it's easy to type one too many Fsand produce \c{0x7ffffffff} by mistake). This warning class isenabled by default.\b \i\c{gnu-elf-extensions} warns if 8-bit or 16-bit relocations are used in \c{-f elf} format. The GNU extensions allow this. This warning class is enabled by default.\b In addition, warning classes may be enabled or disabled across sections of source code with \i\c{[warning +warning-name]} or \i\c{[warning -warning-name]}. No "user form" (without the brackets) exists. \S{opt-v} The \i\c{-v} Option: Display \i{Version} InfoTyping \c{NASM -v} will display the version of NASM which you are using,and the date on which it was compiled. This replaces the deprecated \c{-r}.You will need the version number if you report a bug.\S{opt-y} The \i\c{-y} Option: Display Available Debug Info FormatsTyping \c{nasm -f <option> -y} will display a list of the available debug info formats for the given output format. The default format is indicated by an asterisk. E.g. \c{nasm -f obj -y} yields \c{* borland}.(as of 0.98.35, the \e{only} debug info format implemented).\S{opt-pfix} The \i\c{--prefix} and \i\c{--postfix} Options.The \c{--prefix} and \c{--postfix} options prepend or append (respectively) the given argument to all \c{global} or\c{extern} variables. E.g. \c{--prefix_} will prepend the underscore to all global and external variables, as C sometimes (but not always) likes it.\S{nasmenv} The \c{NASMENV} \i{Environment} VariableIf you define an environment variable called \c{NASMENV}, the programwill interpret it as a list of extra command-line options, which areprocessed before the real command line. You can use this to definestandard search directories for include files, by putting \c{-i}options in the \c{NASMENV} variable.The value of the variable is split up at white space, so that thevalue \c{-s -ic:\\nasmlib} will be treated as two separate options.However, that means that the value \c{-dNAME="my name"} won't dowhat you might want, because it will be split at the space and theNASM command-line processing will get confused by the twononsensical words \c{-dNAME="my} and \c{name"}.To get round this, NASM provides a feature whereby, if you begin the\c{NASMENV} environment variable with some character that isn't a minussign, then NASM will treat this character as the \i{separatorcharacter} for options. So setting the \c{NASMENV} variable to thevalue \c{!-s!-ic:\\nasmlib} is equivalent to setting it to \c{-s-ic:\\nasmlib}, but \c{!-dNAME="my name"} will work.This environment variable was previously called \c{NASM}. This waschanged with version 0.98.31.\H{qstart} \i{Quick Start} for \i{MASM} UsersIf you're used to writing programs with MASM, or with \i{TASM} inMASM-compatible (non-Ideal) mode, or with \i\c{a86}, this sectionattempts to outline the major differences between MASM's syntax andNASM's. If you're not already used to MASM, it's probably worthskipping this section.\S{qscs} NASM Is \I{case sensitivity}Case-SensitiveOne simple difference is that NASM is case-sensitive. It makes adifference whether you call your label \c{foo}, \c{Foo} or \c{FOO}.If you're assembling to \c{DOS} or \c{OS/2} \c{.OBJ} files, you caninvoke the \i\c{UPPERCASE} directive (documented in \k{objfmt}) toensure that all symbols exported to other code modules are forcedto be upper case; but even then, \e{within} a single module, NASMwill distinguish between labels differing only in case.\S{qsbrackets} NASM Requires \i{Square Brackets} For \i{Memory References}NASM was designed with simplicity of syntax in mind. One of the\i{design goals} of NASM is that it should be possible, as far as ispractical, for the user to look at a single line of NASM codeand tell what opcode is generated by it. You can't do this in MASM:if you declare, for example,\c foo equ 1\c bar dw 2then the two lines of code\c mov ax,foo\c mov ax,bargenerate completely different opcodes, despite havingidentical-looking syntaxes.NASM avoids this undesirable situation by having a much simplersyntax for memory references. The rule is simply that any access tothe \e{contents} of a memory location requires square bracketsaround the address, and any access to the \e{address} of a variabledoesn't. So an instruction of the form \c{mov ax,foo} will\e{always} refer to a compile-time constant, whether it's an \c{EQU}or the address of a variable; and to access the \e{contents} of thevariable \c{bar}, you must code \c{mov ax,[bar]}.This also means that NASM has no need for MASM's \i\c{OFFSET}keyword, since the MASM code \c{mov ax,offset bar} means exactly thesame thing as NASM's \c{mov ax,bar}. If you're trying to getlarge amounts of MASM code to assemble sensibly under NASM, youcan always code \c{%idefine offset} to make the preprocessor treatthe \c{OFFSET} keyword as a no-op.This issue is even more confusing in \i\c{a86}, where declaring alabel with a trailing colon defines it to be a `label' as opposed toa `variable' and causes \c{a86} to adopt NASM-style semantics; so in\c{a86}, \c{mov ax,var} has different behaviour depending on whether\c{var} was declared as \c{var: dw 0} (a label) or \c{var dw 0} (aword-size variable). NASM is very simple by comparison:\e{everything} is a label.NASM, in the interests of simplicity, also does not support the\i{hybrid syntaxes} supported by MASM and its clones, such as\c{mov ax,table[bx]}, where a memory reference is denoted by oneportion outside square brackets and another portion inside. Thecorrect syntax for the above is \c{mov ax,[table+bx]}. Likewise,\c{mov ax,es:[di]} is wrong and \c{mov ax,[es:di]} is right.\S{qstypes} NASM Doesn't Store \i{Variable Types}NASM, by design, chooses not to remember the types of variables youdeclare. Whereas MASM will remember, on seeing \c{var dw 0}, thatyou declared \c{var} as a word-size variable, and will then be ableto fill in the \i{ambiguity} in the size of the instruction \c{movvar,2}, NASM will deliberately remember nothing about the symbol\c{var} except where it begins, and so you must explicitly code\c{mov word [var],2}.For this reason, NASM doesn't support the \c{LODS}, \c{MOVS},\c{STOS}, \c{SCAS}, \c{CMPS}, \c{INS}, or \c{OUTS} instructions,but only supports the forms such as \c{LODSB}, \c{MOVSW}, and\c{SCASD}, which explicitly specify the size of the components ofthe strings being manipulated.\S{qsassume} NASM Doesn't \i\c{ASSUME}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -