0% found this document useful (0 votes)
25 views

Assembler Directives

Assembler Directives

Uploaded by

THIYAGARAJAN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Assembler Directives

Assembler Directives

Uploaded by

THIYAGARAJAN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

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:

The DB directive is used to reserve byte or bytes of memory locations


in the available memory. While preparing the EXE file, this directive directs the
assembler to allocate the specified number of memory bytes to the said data type that
may be a constant, variable, string, etc. Another option of this directive also initializes
the reserved memory bytes with the ASCII codes of the characters specified as a string.
The following examples show how the DB directive is used for different purposes.

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.

3. DD -Define Double word - used to declare a double word type variable or to


reserve memory locations that can be accessed as double word.

E.g.: ARRAY _POINTER DD 25629261H declares


a double word named
ARRAY_POINTER.

4. DQ -Define Quad word

This directive is used to direct the assembler to reserve 4 words (8 bytes) of


memory for the specified variable and may initialize it with the specified values.
5. DT -Define Ten Bytes:
The DT directive directs the assembler to define the specified
variable requiring 10-bytes for its storage and initialize the 10-bytes with the
specified values. The directive may be used in case of variables facing heavy
numerical calculations, generally processed by numerical processors.

E.g.: PACKED_BCD 11223344556677889900 declares an array that is 10 bytes in length.

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.

1) WORDS DW 1234H, 4567H, 78ABH, 045CH

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

This makes the assembler reserve one word in memory.

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.

E.g.: SQUARE_ROOT PROC: start of procedure

SQUARE_ROOT ENDP: End of 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

ASSUME CS: CODE, DS: DATA CODE

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.

E.g.: CORRECTION_FACTOR EQU

03H MOV AL,

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.

For example if a procedure in a program module assembled at a different time from


that which contains the CALL instruction ,this directive is used to tell the assembler
that the procedure is external

13. GLOBAL - Can be used in place of a PUBLIC directive or in place of an EXTRN


directive.

It is used to make a symbol defined in one module available to other modules.

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.

E.g.: SMALL_SYSTEM GROUP CODE, DATA, STACK_SEG

15. INCLUDE - Used to tell the assembler to insert a block of source code from the named file
into the current source module.

This will shorten the source code.


16. LABEL- Used to give a name to the current value in the location counter.

This directive is followed by a term that specifies the type you want associated with
that name.

E.g: ENTRY_POINT LABEL FAR NEXT:

MOV AL, BL

17. NAME- Used to give a specific name to each assembly module when
programs consisting of several modules are written.

E.g.: NAME PC_BOARD

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.

E.g.: MOV BX, OFFSET PRICES

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.: ORG 2000H

20. PROC- Used to identify the start of a procedure.

E.g. SMART_DIVIDE PROC FAR identifies the start of a procedure named


SMART_DIVIDE and tells the assembler that the procedure is far

21. PTR- Used to assign a specific type to a variable or to a label.

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.

E.g.: PUBLIC DIVISOR, DIVIDEND makes the two variables


DIVISOR and DIVIDEND available to other assembly modules.

23. SEGMENT- Used to indicate the start of a logical segment.

E.g.: CODE SEGMENT indicates to the assembler the start of a logical


segment called CODE

24. SHORT- Used to tell the assembler that only a 1 byte displacement is needed to code a
jump instruction.

E.g.: JMP SHORT NEARBY_LABEL

25. TYPE - Used to tell the assembler to determine the type of a specified variable.

E.g.: ADD BX, TYPE WORD_ARRAY is used where we want to increment BX


to point to the next word in an array of words.

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

Table-1: Relational operators used in WHILE statement.

You might also like