-
Installation notes are given in Chapter 1 of NASM.
-
It's as simple as unpacking a gzipped tar file in a directory of your choice, e.g. /usr/local/src.
-
cd /usr/local/src
-
(You will have to be root to do this.)
-
Then type:
-
tar -xzvf nasm-0.98.tar.gz
-
Note it creates a subdirectory nasm-X.XX (with X replaced with version and minor revision numbers).
-
Then
cd nasm-0.98
and type
.configure
-
Type
make
to compile the source and then
make install
to install binaries into /usr/local/bin and man pages into /usr/local/man/man1
-
To get command line help, type:
-
To compile into an ELF object file .o, type:
-
To create a listing file, type:
-
nasm -f elf myfile.asm -l myfile.lst
-
To send errors to a file, type:
-
nasm -E myfile.err -f elf myfile.asm
-
To include other search paths such as /usr/include, type:
-
nasm -I/usr/include -f elf myfile.asm
-
To include other files in a source file, use:
-
To define constants, use either of the equivalent forms:
-
-dFOO=100
on the compile command line.
-
%define FOO 100
in the source file.
-
In order to refer to the
contents
of a memory location, use square brackets.
-
In order to refer to the address of a variable, leave them out, e.g.,
-
No need for the OFFSET directive.
-
NASM does not support the hybrid syntaxes such as:
-
NASM does NOT remember variable types:
-
NASM does NOT remember variable types
-
Therefore, un-typed operations are not supported, e.g.
-
LODS, MOVS, STOS, SCAS, CMPS, INS, and OUTS.
-
You must use instead:
-
LODSB, MOVSW, and SCASD, etc.
-
NASM does not support ASSUME.
-
It will not keep track of what values you choose to put in your segment registers.
-
NASM does not support memory models.
-
The programmer is responsible for coding CALL FAR instructions where necessary when calling external functions.
-
seg
returns the segment base of procedure
proc
.
-
NASM does not support memory models.
-
The programmer has to keep track of which functions are supposed to be called with a
far call
and which with a
near call
, and is responsible for putting the correct form of RET instruction (RETN or RETF).
-
NASM uses the names
st0
,
st1
, etc. to refer to floating point registers.
-
NASM's declaration syntax for un-initialized storage is different.
-
Macros and directives work differently than they do in MASM.
-
The `:' is optional, which can cause problems if, for example, you misspell an instruction, e.g.
lodab
instead of
lodsb
.
-
Use -w+orphan-labels as a command line option to the compiler to identify these!
-
Valid characters in labels are letters, numbers, _, $, #, @, ~, ., and ?.
-
Identifier valid starting characters include letters, . , _ and ?.
-
Instruction prefixes supported:
-
LOCK,
-
REP,
-
REPE/REPZ
-
REPNE/REPNZ
-
Floating point instructions can take on two-operand forms or a single operand form:
-
Almost any float-point instruction that references memory
must use one of the prefixes DWORD, QWORD or TWORD to indicate what size of memory operand it refers to.
-
Storage directives:
-
DB, DW, DD, DQ and DT are used for initialized data only.
-
RESB, RESW, RESD, RESQ and REST are used for uninitialized.
-
EQU defines a symbol to a constant:
-
Constants:
-
Suffixes H, Q and B are used hex, octal and binary. 0x also works for hex.
-
The SEG operator returns the preferred segment base of a symbol:
-
Will load ES:EBX with a valid pointer to symbol.
-
(Probably wont need unless you are writing 16-bit code which has multiple segments).
-
To declare a far pointer to a data item in a data segment:
-
Local Labels
begin with a `.' and are associated with previous non-local label.
-
Note that expansion occurs at invocation time, not at definition time, e.g.
-
Overloading macros is allowed.
-
Conditional assembly:
-
Given the macro (21h is a DOS interrupt):
-
Using the command-line option -dDEBUG, expands the macro otherwise it is left out (similar to C).
-
Note that "I'm here", 13, 10 is substituted in for %2 in the above code.
-
mytype_size is also defined as the total size, and is 39 in this example.
-
To declare instances:
-
To reference, you must use:
-
The align (and alignb) directive can be used to align the data.
-
To produce hello.o object file:
-
To produce hello ELF executable:
-
A program to process command line args:
-
A program to process command line args (cont):