Sunday, 18 September 2016

Assembler Directives

Assembler

- An assembler is a program used to convert an assembly language program into the equivalent machine code modules which may further be converted to executable codes.

- The assembler decides the address of each label and substitutes the values for each of the constants and variables,

- It then forms the machine code for the mnemonics and data in the assembly language program.

- While doing these things, the assembler may find out syntax errors.


Assembler Directives

- For completing all these tasks(mentioned above), an assembler needs some hints from the programmer, i.e. the required storage for a particular constant or variable, logical names of the segments, types of the different routines and modules, end of file, etc.

- These types of hints are given to the assembler using some predefined alphabetical strings called assembler directives.

_________________________________________________________________________________

Assembler Directives help the assembler to correctly understand the assembly language programs to prepare the codes.
_________________________________________________________________________________

Now, lets learn about some of these directives;

1. Define Byte (DB):
- The DB directive is used to reserve byte or bytes of memory locations in the available memory.
   Example:
                  LIST DB 01H, 02H, 03H, 04H
   This statement directs the assembler to reserve four memory locations for a list named LIST and          initialize them with the above specified values.

                  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 initialize those locations by the ASCII equivalent of these            characters.

                  VALUE DB 50H
   This statement directs the assembler to reserve 50H memory bytes and leave them uninitialised for      the variable named VALUE. 

2. Define Word (DW):
- Used to reserve the number of memory words (16-bit) in the available memory.
   Example:
                  WORDS DW 1234H, 4567H, 78ABH, 045CH
                   WDATA DW 5 DUP (6666H)
   Reserve five words i.e. 10 bytes of memory for a word label WDATA and initialise all the word          locations with 6666H.

3. Define Quad Word (DQ):
- This directive is used to direct the assembler to reserve four words (8 bytes) of memory for the            specified variable and may initialize it with the specified values.

4. Define Ten Bytes (DT)

5. Double Word (DD)

6. Assume logical segment name (ASSUME):
- Used to inform the assembler the names of the logical segments to be assumed for different                  segments used in the program.
   Example:
                  ASSUME DS:DATA

7. End of Program (END):
- Marks the end of assembly language program.
- When the assembler comes across this END directive, it ignores the source lines available later on.

8. End of Procedure (ENDP):
- To mark end of a particular procedure, the name of procedure may appear as a prefix with the              directive ENDP.
   Example: PROCEDURE STAR
                             .
                             .
                             .
                    STAR ENDP

9. End of Segment (ENDS):
- Marks end of a logical segment.
   Example: DATA SEGMENT
                          .
                          .
                          .
                    DATA ENDS

- The SEGMENT and ENDS directives are used to identify a group of data items or group of instructions that you want to be put together in a particular segment.

- A group of data statements or a group of instruction statements contained between SEGMENT and ENDS directives is called a LOGICAL SEGMENT.

- A logical is not usually given a physical starting address when it is declared. After the program is assembled and perhaps linked with other assembled program modules, it is then assigned the physical address where it will be loaded in memory to be run.