Assembler Directives
Assembler Directives
There are some instructions in the assembly language program which are not a part of
processor instruction set. These instructions are instructions to the assembler, linker and
loader. These are referred to as pseudo-operations or as assembler directives. The assembler
directives enable us to control the way in which a program assembles and lists. They act
during the assembly of a program and do not generate any executable machine code.
There are many specialized assembler directives. Let us see the commonly used
assembler directive in 8086 assembly language programming.
1. ASSUME :
It is used to tell the name of the logical segment the assembler to use for a
specified segment.
E.g.: ASSUME CS: CODE tells that the instructions for a program are in a logical
segment named CODE.
2. DB -Define Byte:
1) RANKS DB 01H,02H,03H,04H
This statement directs the assembler to reserve four memory locations for a list
named RANKS and initialize them with the above specified four values.
2) MESSAGE DB „GOOD MORNING‟
This makes the assembler reserve the number of bytes of memory equal to the number of
characters in the string named MESSAGE and initializes those locations by the ASCII
equivalent of these characters.
3) VALUE DB 50H
This statement directs the assembler to reserve 50H memory bytes and leave them
uninitialized for the variable named VALUE.
6. DW -Define Word:
The DW directives serves the same purposes as the DB directive, but it now
makes the assembler reserve the number of memory words (16-bit) instead of bytes.
Some examples are given to explain this directive.
This makes the assembler reserve four words in memory (8 bytes), and initialize the words
with the specified values in the statements. During initialization, the lower bytes are
stored at the lower memory addresses, while the upper bytes are stored at the higher
addresses.
2) NUMBER1 DW 1245H
7. END-End of Program:
The END directive marks the end of an assembly language program. When the
assembler comes across this END directive, it ignores the source lines available later
on. Hence, it should be ensured that the END statement should be the last statement
in the file and should not appear in between. Also, no useful program statement
should lie in the file, after the END statement.
8. ENDP-End Procedure - Used along with the name of the procedure to indicate the end of a
procedure.
9. ENDS-End of Segment:
This directive marks the end of a logical segment. The logical segments are
assigned with the names using the ASSUME directive. The names appear with the
ENDS directive as prefixes to mark the end of those particular segments. Whatever are
the contents of the segments, they should appear in the program before ENDS. Any
statement appearing after ENDS will be neglected from the segment. The structure
shown below explains the fact more clearly.
DATA SEGMENT
--------------------
---------------------
DATA ENDS
SEGMENT
---------------------
---------------------
CODE ENDS
ENDS
10. EQU-Equate - Used to give a name to some value or symbol. Each time the assembler finds
the given name in the program, it will replace the name with the vale.
CORRECTION_FACTOR
11. EVEN - Tells the assembler to increment the location counter to the next even address if it
is not already at an even address.
Used because the processor can read even addressed data in one clock cycle
12. EXTRN - Tells the assembler that the names or labels following the directive are in some
other assembly module.
E.g.: GLOBAL DIVISOR makes the variable DIVISOR public so that it can be
accessed from other modules.
14. GROUP-Used to tell the assembler to group the logical statements named after the
directive into one logical group segment, allowing the contents of all the segments to be
accessed from the same group segment base.
15. INCLUDE - Used to tell the assembler to insert a block of source code from the named file
into the current source module.
This directive is followed by a term that specifies the type you want associated with
that name.
MOV AL, BL
17. NAME- Used to give a specific name to each assembly module when
programs consisting of several modules are written.
18. OFFSET- Used to determine the offset or displacement of a named data item or
procedure from the start of the segment which contains it.
19. ORG- The location counter is set to 0000 when the assembler starts reading a
segment. The ORG directive allows setting a desired value at any point in the program.
E.g.: INC BYTE PTR[BX] tells the assembler that we want to increment the byte
pointed to by BX
22. PUBLIC- Used to tell the assembler that a specified name or label will be
accessed from other modules.
24. SHORT- Used to tell the assembler that only a 1 byte displacement is needed to code a
jump instruction.
25. TYPE - Used to tell the assembler to determine the type of a specified variable.
Macros:
Macro is a group of instruction. The macro assembler generates the code in the
program each time where the macro is “called”. Macros can be defined by
MACROP and ENDM assembler directives. Creating macro is very similar to creating a new
opcode that can used in the program, as shown below.
Example:
INIT MACRO
MOV AX,@DATA
MOV DS,AX
MOV ES, AX
ENDM
It is important to note that macro sequences execute faster than procedures because there is
no CALL and RET instructions to execute. The assembler places the macro instructions in
the program each time when it is invoked. This procedure is known as Macro expansion.
WHILE:
In Macro, the WHILE statement is used to repeat macro sequence until the
expression specified with it is true. Like REPEAT, end of loop is specified by ENDM
statement. The WHILE statement allows to use relational operators in its expressions.
The table-1 shows the relational operators used with WHILE statements.
PERATOR FUNCTION
EQ Equal
NE Not equal
LE Less than or equal
LT Less than
GE Greater than or equal
GT Greater than
NOT Logical inversion
AND Logical AND
OR Logical OR