0
10kviews
Explain the directives

Explain the following directives CODE, ASSUME, ALINE, EQU, EVEN. Various Data & Model directives.

1 Answer
0
129views

1) .CODE-

  • This assembler directive indicates the beginning of the code segment. Its format is as follows: .CODE [name]
  • The name in this format is optional.
  • For tiny, small and compact models the segment name is –TEXT always.
  • The medium and large memory models use more than one code segments which can be distinguished by name.

2) ASSUME-

  • The directive is used for telling the assembler the name of the logical segment which should be used.
  • The format of the assume directive is as follows:

    ASSUME segment register: segment-name:

  • The segment register can be CS, DS, SS and ES.
  • The example of assume directive is as follows:

    ASSUME CS: Code, DS: Data, SS: Stack:

  • ASSUME statement can assign up to 4 segment registers in any sequences.
  • In this example, DS: Data means that the assembler is to associate the name of data segment with DS register.
  • Similarly CS: Code tells the assembler to associate the name of code segment with CS register and so on.

3) ALIGN-

  • This directive will tell the assembler to align the next instruction on an address which corresponds to the given value.
  • Such an alignment will allow the processor to access words and double words.

    ALIGN number

    This number should be 2, 4, 8, 16…. i.e. it should be a power of 2.

  • The example of align directive are ALIGN 2 and ALIGN 4.
  • ALIGN 2 is used for starting the data segment on a word boundary whereas

    ALIGN 4 will start the data segment on a double boundary word.

4) EQU-

  • It is used to give a name to some value or symbol in the program.
  • Each time when the assembler finds that name in the program, it replaces that name with the value assigned to that variable.
  • Its format is [name] EQU initial value

    E.g. FACTORIAL EQU 05H

  • This statement is written during the beginning of the program and whenever now FACTORIAL appears in an instruction or another directive, the assembler substitutes the value 5.
  • The advantage of using EQU in this manner is that if FACTOPRIAL is used several times in a program and the value has to be changed, all that has to change the EQU statement and reassemble the program.
  • The assembler will automatically put the new value each time it finds the name FACTORIAL.

5) EVEN-

  • It tells the assembler to increment its location counter if required, so that the next defined data item is aligned on an even storage boundary.
  • The 8086 can read a word from memory in one bus cycle if the word is at an even address.
  • If the word starts at an odd address, the microprocessor must do two read cycles to get 2 bytes of the word. In the first cycle it will read the LSB and in the second it will read MSB.
  • Therefore, a series of even words can be read more quickly if they are at an even address.

    $\text{E.g. EVEN TABLE DB 10 DUP (0)} \hspace{1cm} \text{; It declares an array named TABLE} \\ \hspace{7.3cm} \text{; of 10 bytes which are starting from} \\ \hspace{7.3cm} \text{; an even address}$

6) Various data directives-

  • .DATA- This directive indicates the beginning of the data segment.
  • Define Byte [DB]- This directive defines the byte type variable.
  • Define Word [DW]- The DW directive defines items that are one word (two bytes) in length.
  • Define Double word [DD]- It defines the data items that are a double word (four bytes) in length.
  • Define Quad word [DQ]- This directive is used to tell the assembler to declare variable 4 words in length or to reserve 4 words of storage in memory.
  • Define Ten bytes [DT]- It is used to define the data items that are 10 bytes long.

7) Model directives-

  • .MODEL
    • This directive is used for selecting a standard memory model for the assembly language program.
    • Each memory model has various limitations depending on the maximum space available for code and data.
    • The general format for defining the model directive is as follows: .MODEL [memory model]:
    • The size of a memory model can be anything from small to huge.
    • The tiny model is meant for the .COM programs because they have their code, data and stack in only one 64 kB segment of memory.
    • On the other hand the flat model is the biggest which define one area up to 4GB for code and data.
    • The small model is useful for the student level programs because for this model the assembler assumes that the addresses are within a span of 64 kB and hence generates 16 kB offset addresses.
    • In the compact model, the assembler can use 32 bit addresses. So the execution time for this model is longer.
    • The huge model contains variables such as arrays which need a larger space than 64kB.
    • The memory model is chosen based on the user’s requirement by referring to the following table
Model Number of code segments Number of data segments
Small One code segment and of size < = 64 Kbytes One of size < = 64 Kbytes
Medium Code segment may be of any number and any size One of size < = 64 Kbytes
Compact One of size < = 64 Kbytes Data segment of any number and any size.
Large Any number, any size Any number, any size
Huge Any number, any size Any number, any size
Please log in to add an answer.