Next Chapter | Previous Chapter | Contents | Index
NASM is a portable assembler, designed to be able to compile on any ANSI
C-supporting platform and produce output to run on a variety of Intel x86
operating systems. For this reason, it has a large number of available
output formats, selected using the option on
the NASM command line. Each of these formats, along with its function t ; 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:
This defines some variables `on top of' the setup code, so that after the setup has finished running, the space it took up can be re-used as data storage for the running TSR. The symbol `tsr_end' can be used to calculate the total size of the part of the TSR that needs to be made resident.
EXTERN : Importing Symbols from Other Modules is similar to the MASM directive
and the C keyword
: it is used to declare a symbol which is
not defined anywhere in the module being assembled, but is assumed to be
defined in some other module and needs to be referred to by this one. Not
every object-file format can support external variables: the
format cannot.
The directive takes as many arguments
as you like. Each argument is the name of a symbol:
extern _printf
extern _sscanf,_fscanf
Some object-file formats provide extra features to the
directive. In all cases, the extra
features are used by suffixing a colon to the symbol name followed by
object-format specific text. For example, the
format allows you to declare that the default segment base of an external
should be the group by means of the
directive
extern _variable:wrt dgroup
The primitive form of differs from the
user-level form only in that it can take only one argument at a time: the
support for multiple arguments is implemented at the preprocessor level.
You can declare the same variable as
more than once: NASM will quietly ignore the second and later
redeclarations. You can't declare a variable as
as well as something else, though.
GLOBAL : Exporting Symbols to Other Modules is the other end of
: if one module declares a symbol as
and refers to it, then in order to prevent
linker errors, some other module must actually define the symbol
and declare it as . Some assemblers use the
name for this purpose.
The directive applying to a symbol must
appear before the definition of the symbol.
uses the same syntax as
, except that it must refer to symbols
which are defined in the same module as the
directive. For example:
global _main
_main: ; some code
, like ,
allows object formats to define private extensions by means of a colon. The
object format, for example, lets you specify
whether global data items are functions or data:
global hashlookup:function, hashtable:data
Like , the primitive form of
differs from the user-level form only in
that it can take only one argument at a time.
COMMON : Defining Common Data AreasThe directive is used to declare
common variables. A common variable is much like a global variable
declared in the uninitialised data section, so that
common intvar 4
is similar in function to
global intvar
section .bss
intvar resd 1
The difference is that if more than one module defines the same common
variable, then at link time those variables will be merged, and
references to in all modules will point at
the same piece of memory.
Like and
, supports
object-format specific extensions. For example, the
format allows common variables to be NEAR or
FAR, and the format allows you to specify the
alignment requirements of a common variable:
common commvar 4:near ; works in OBJ
common intarray 100:4 ; works in ELF: 4 byte aligned
Once again, like and
, the primitive form of
differs from the user-level form only in
that it can take only one argument at a time.
CPU XXX : Defining CPU DependenciesThe directive restricts assembly to those
instructions which are available on the specified CPU.
Options are:
CPU 8086 Assemble only 8086 instruction set
CPU 186 Assemble instructions up to the 80186
instruction set
CPU 286 Assemble instructions up to the 286
instruction set
CPU 386 Assemble instructions up to the 386
instruction set
CPU 486 486 instruction set
CPU 586 Pentium instruction set
CPU PENTIUM Same as 586
CPU 686 Pentium Pro instruction set
CPU PPRO Same as 686
CPU P2 Pentium II instruction set
CPU P3 Pentium III and Katmai instruction
sets
CPU KATMAI Same as P3
CPU P4 Pentium 4 (Willamette) instruction set
CPU WILLAMETTE Same as P4
All options are case insensitive. All instructions will be selected only if they apply to the selected cpu or lower.