BTECH MTECH ECE
This term paper includes study about the statements that direct the assembler to do something or to do a specific task. Directives do many things some tell the assembler to set aside the space for variables, others tell the assembler to include additional source files , and others establish the start address of your program.
Assembly languages are a family of low-level languages for programming computers, microprocessors, microcontrollers, and other (usually) integrated circuits. They implement a symbolic representation of the numeric machine codes and other constants needed to program a particular CPU architecture. This representation is usually defined by the hardware manufacturer, and is based on abbreviations (called mnemonics) that help the programmer remember individual instructions, registers, etc. An assembly language is thus specific to a certain physical or virtual computer architecture (as opposed to most high-level languages, which are usually portable).
A utility program called an assembler is used to translate assembly language statements into the target computer's machine code. The assembler performs a more or less isomorphic translation (a one-to-one mapping) from mnemonic statements into machine instructions and data. This is in contrast with high-level languages, in which a single statement generally results in many machine instructions
Assembly language consists oftwo type of statements viz.
1. Executable statements:-these are the statements to be executed by the processor. It consists of the entire instruction set of 8086
2. Assembler directives:-these are the statements that direct the assembler t do something. As the name says, it direct the assembler to do a task.
The specialty of these statements is that they are effective only during the assembly of program but they do not generate any code that is machine executable. We can divide the assembler directive into two categories namely the general purpose directives and the special directives. They are classified into thefollowing categories based on the functions performed by them
1. Simplified segment directives
2. Data allocation directives.
3. Segment directives.
4. Macro related directives.
5. Code label directives
6. Scope directives
7. Listing controldirectives
8. Miscellaneous directives.
This directive indicates the beginning of the data segment.
- This directive is used for selecting a standard memory model for the assembly language program.
- Each memory hasvarious limitation depending on the maximum space available for code and data.
- The general format for defining the MODEL directiveis as follows: .MODEL[memory model]
- The size of a memory 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 64kB segment of memory.
- On the other hand the flat model is the biggest which defines one are a upto 4GB for the code and data.
- The small model is useful for the student level programsbecause for this model the assembler assumes that the address are within a span of 64kB and hense generates 16kB offset address.
- In 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
- This directive is used for defining the stack. Its format is as follows .STACK[size]
- The size of the stack is 1024 bytes by default but the size can be overwritten.
- We can omit the .stack command if the stack segment is not to be used in a program.
- Example of stack directive is STACK 100. Which reserves 100 bytes for the stack segment.
- It is used to give name to some value or symbol in the program.
- Each time when the assembler finds the name in the program, it replacesthat name with the value assigned to that r variable.
- The advantage of using EQU in this manner is that if factorial is used several times in a program and the value has to be changed, all that has to change the EQU statement andthe reassemble the program.
- The assembler will automatically put the new value each time it finds the name factorial.
5. Define Byte[DB]
- This directive defines the byte per variable.
- It is also useful to set one or more storage locations aside.
- The format of this directive is as follows: [name] DB initial value
- The initial value can be a numerical value ( 8- bit long) or more than one 8 bit numeric values.
- It can be a constant expression, or a string constant or even a question mark.
- The initial value can be signed or unsigned number. Its range is from -128 to +127 if the unsigned and 0 to 255 if it is unsigned.
6. Define Word or Word[DW]
- The DW directive defines items that are one word( 2 bytes) in length.
- For unsigned numeric data the range of values is 0 to 65,535.
- For signed data the range of values is -32,768 to +32,767.
- Its format is [name] DW initial value
7. Define Double word or DWORD[DD]
- It defines the data items that are double word in length.
- It creates storage for 32 bit double words. The format is [name] DD initial value
8. Define Quad word or QWORD [DQ]
- This directive is used to tell the assembler to declare variable 4 words in length or to reverse 4 words of storage in memory.
- It may define one or more constants each with a maximum 8 bytes or 16 hex digits
- Its format is: [name] DQ initial value,[initial value]
9. DefineTen bytes or TBYTE[DT]
- It is used to definethe data items that are 10 bytes long.
- Its format is: [name] DT initial value,[initial value]
- Unlike the other data directives which store hexadecimal numbers, DT will directly store the data in decimal form.
10. ORG- Originate
- The ORG directive allows us to set the location counter to any desired value at any point in the program.
- The location counter is automatically set to 0000h when the assembler reads a segment.
- Its format is ORG expression.
- A $ is used to representthe current value LC.
- The $ represents the next available byte location where assembler can put a data or code byte.
- The 4 is often used in ORG statements to inform the assembler to make change in location counter relative to its current value.
- 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.
- ASSUME statement can assign upto 4 segment registers in any sequence.
- This is placed at the end of a source and it acts as the last statement of a program.
- This is because the END directive terminate the entire program.
- The assmembler will neglect any statement after an END directive.
14. SEGMENT and ENDS
- The SEGMENT directive is used to indicate the start of a logical statement.
- ENDS directive is used with the segment directive.
- ENDS directive indicates the end segment.
- Its format is Name SEGMENT ; Begin Segment
- This directive collects the segment to the same type under one name.
- It does it so that the segments that are grouped will decide within one segment uaually data segment.
- Its format is [name] GROUP seg-name,[seg-name]
14.MACRO AND ENDM
- The macros in the program can be defined by MACRO directive.
- The ENDM directive is used within the macro directive
- ENDM defines the end of macro.
- Its format is
Statement inside macro ENDM
- This directive will tell the assembler to align 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 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.
16. EVEN(Align on even memory address)
- It tells the assembler to increment its location counter if required , so thet the next define data item is aligned on an even storage boundary.
- 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 to read cycles to get two bytes of the word.
In the first cycle it will readto the LSB& in the second it will read MSB.
- This directive assigns name to the current value of the location counter.
- The LABEL directive must be followed by a term which specifies the type associated with that with that symbolic name.
- If label is going to be used to reference a data item , then the label must be specified as type byte, word or double word.
18. PROC- Procedure
- This directive is used to indicate the start of a procedur.
- The procedures are of two typesNEAR nadFAR.
- If the procedure is within the same segment then the label NEAR should be given after procedure.
- If the procedure is in other module the the label FAR should be given after procedure.
- It indicates that the names or labels that follow the EXTRN directive are in some other assembly module.
- To call a procedure that is in a program module assembled at a different time from that which contains the CALL instruction, the assembler ha sto be told that the procedure is external.
- Assembler will then put information in the object code file so that linker can connects the two module together.
- The names or labels that are external in one module must be declared public with the PUBLIC directive in the module were they are defined.
- It informs the assembler and linker that the identified variables in a program are to be reference by other module link with the current one.
- The variable can be a number ora label or a symbol.
- This directive is used to specify the maximum number of lines on a page and maximum number of character on a line.
- The number of lines per page typically ranges from 10 to 255 and the number of characters per line will range from 60 to 132.
- It helps the user for controlling theformat of listing of an assembled program.
- It is used to give a title to program and print the title on the second line on each page of the program.
- The maximum number of characters allowed as a title is 60.
This directive is used to tell the assembler to insert a block of source code from the named file into the current source module.this shortens the source code.
24. DUP Operator
- Whenever we want to allocate a space for a table or an array the DUP directive can be used. The DUP operator it will be used after the storage allocationdirective like (DB,DW,DQ,DT,DD).
- With DUP, we can repeat one or more values while assigning the storage values.
- It is an operator.
- It informs the assembler to determine the offset or displacement of a name data item or next.
- It may also determine the offset of a procedure from the start of the segment which contain it.
- It is an operator.
- It informs the assembler to find the number of elements in named data item like a string or an array.
- The length of a string always storeh Hex by the 8086.
27.ENDp- End Procedure
- This directive is used along with theprocedure to indicate the end of procedure.
- ENDP defines the end of procedure.
- Is an operator.
- It is used to tell the assembler that only one - byte displacement is needed to code a jump instruction.
- If the jump destination is after the jump instruction in the program, the assembler will automatically reserve two bytes for the displacement.
- The type is an operator.
- It informs the assembler to find the type of a specified variable.
- The assembler actually find the number of bytes in the type of variable.
- For a byte variable the assembler gives a value 1.
- For word type variable the assembler gives a value 2 and for double word 4.
U.S.Shah, microprocessor and its applications,Tech-Max publications,pune.
B.Ram, fundamentals of microprocessor and computers,dhanpat rai publications.