Assembler Directives


Data Directives

name EQU text name EQU expression
assigns name to the text string or the value of the expression permanently

name = numeric-expression
assigns name to the value of the expression - may be changed

[name] DB expression,...
allocates bytes for expression/s labelled as name
can be used to allocate a block using:
[name] DB size DUP (initial)
example: testdata DB 12 dup (?)
the above example defines 12 bytes of undefined data

[name] DW expression,...
allocates two-byte words for expression/s labelled as name

[name] DD expression
allocated four-byte double-words for expression/s labelled as name

PUBLIC symbol,...
makes defined symbols publicly accessible to other modules

EXTRN symbol:type,...
imports defined symbols from other modules

INCLUDE filespec
includes the contents of filespec into the source code at the point of the directive

seg-name SEGMENT [align-type] [combine-type] ['class'] seg-name ENDS
defines a segment
align-type (PARA/WORD/BYTE) states how to align the segment relative to its previous segment in memory
combine-type (PUBLIC/COMMON/STACK) indicates how other segments with the same name are to be combined (adjoining/overlapped/stacked)
'class' defines a name for a segment type - it is normally 'DATA', 'CODE' or 'STACK'
For a data segment, use SEGMENT PARA PUBLIC 'DATA'
For a code segment, use SEGMENT PARA PUBLIC 'CODE'
For a stack segment, use SEGMENT PARA STACK 'STACK'

ASSUME seg-reg:seg-name,...
associates segment registers with default segments

name PROC [NEAR|FAR] name ENDP
defines a procedure with label name

END
marks the end of the program source code

ORG
defines a starting address or the location counter

Operators

value1 + value2
adds value1 and value2

value1 - value2
subtracts value2 from value1

value1 * value2
multiplies value1 and value2

value1 / value2
divides value1 by value2 and returns the quotient

value1 MOD value2
divides value1 by value2 and returns the remainder

value1 SHL value2
shifts value1 left value2 places bitwise

value1 SHR value2
shifts value1 right value2 places bitwise

value1 AND value2
bitwise AND or value1 and value2

value1 OR value2
bitwise OR of value1 and value2

value1 XOR value2
bitwise XOR or value1 and value2

NOT value
bitwise NOT of value

operand1 EQ operand2
true if operands are identical

operand1 NE operand2
true if operands are not identical

operand1 LT operand2
true if operand1 less than operand2

operand1 GT operand2
true if operand1 greater than operand2

operand1 LE operand2
true if operand1 less than or equal to operand2

operand1 GE operand2
true if operand1 greater than or equal to operand2

$
returns the current value of the location counter

SEG [variable|label]
returns the segment of the operand

OFFSET [variable|label]
returns the offset of the operand

LENGTH variable
returns the length in bytes of the variable defined using DUP

type PTR expression
forces an expression to be either BYTE/WORD or NEAR/FAR

JMP SHORT label
forces a short jump (within 128 bytes) to produce smaller code

HIGH expression
returns the high-order byte of a 16-bit word

LOW expression
returns the low-order byte of a 16-bit word

Memory Model Directives

.MODEL
defines the memory model
TINY=all data and code in one 64k segment
SMALL=64k data and 64k code
LARGE=1M data and 1M code

DOSSEG
orders segments in a DOS fashion, using paragraph alignment

.CODE
defines the code segment

.DATA
defines the data segment using name _DATA

.STACK size
defines the stack segment to be of size bytes