Uploaded by Gopal Sonune

Assembler Directives

advertisement
ASSEMBLER DIRECTIVES AND OPERATORS
The words defined in this section are directions to the assembler, notinstructions for the 8086.
The assembler directives described here are those forthe Intel 8086 macro-assembler (ASM86),
the Borland Turbo Assembler (TASM),and the IBM macro assembler (MASM).
Assembler: is a program that accepts an assembly language program as input and
converts it into an object module and prepares for loading the program into memory for
execution.
Loader (linker) further converts the object module prepared by the assembler into
executable form, by linking it with other object modules and library modules.
The final executable map of the assembly language program is prepared by the loader at
the time of loading into the primary memory for actual execution.
The assembler prepares the relocation and linkages information (subroutine, ISR) for
loader.
The operating system that actually has the control of the memory, which is to be allotted
to the program for execution, passes the memory address at which the program is to be
loaded for execution and the map of the available memory to the loader.
Based on this information and the information generated by the assembler, the loader
generates an executable map of the program and further physically loads it into the
memory and transfers control to for execution.
Thus the basic task of an assembler is to generate the object module and prepare the
loading and linking information.
Directives
Also called as pseudo operations that control the assembly process.
They indicate how an operand or section of a program to be processed by the assembler.
They generate and store information in the memory.
ASSUME
The ASSUME directive is used to tell the assembler the name of the logicalsegment it should use
for a specified segment. The statement ASSUME CS:CODE, for example, tells the assembler
that the instructions for a program are ina logical segment named CODE. The statement
ASSUME DS: DATA tells theassembler that for any program instruction, which refers to the
data segment, itshould use the logical segment called DATA. If, for example, the assembler
readsthe statement MOV AX,[BX] after it reads this ASSUME, it will know that thememory
location referred to by [BX] is in the logical segment DATA. We musttell the assembler what to
assume for any segment we use in a program. If weuse a stack in our program, we must tell the
assembler the name of the logicalsegment we have set up as a stack with a statement such as
ASSUME SS:STACK_HERE. For a program with string Instructions which use DI,
EQU:
Equates a numeric, ASCII(American Standard Code for Information Interchange) or
label to another label.
Example
Data SEGMENT
Num1 EQU 50H
Num2 EQU 66H
Data ENDS
Numeric value 50H and 66H are assigned to Num1 and Num2
ORG: Changes the starting offset address of the data in the data segment
Example
ORG 100H
100 data1 DB 10H
it can be used for code too.
PROC & ENDP: indicate the start and end of the procedure. They require a label to
indicate
the name of the procedure.
NEAR: the procedure resides in the same code segment. (Local)
FAR: resides at any location in the memory.
Example
Add PROC NEAR
ADD AX,BX
MOV CX,AX
RET
Add ENDP
PROC directive stores the contents of the register in the stack.
EXTRN, PUBLIC informs the assembler that the names of procedures and labels
declared after this directive have been already defined in some other assembly language
modules.
DB define byte
DW define word
DD define double word
DQ define 10 bytes
Example
Data1 DB 10H,11H,12H
Data2 DW 1234H
SEGMENT: statement to indicate the start of the program and its symbolic name.
Example
Name SEGMENT
Variable_name DB …….
Variable_name DW …….
Name ENDS
Data SEGMENT
Data1 DB …….
Data2 DW …….
Data ENDS
Code SEGMENT
START: MOV AX,BX
Example
If you want to call a Factorial procedure of Module1 from Module2 it must be declared as
PUBLIC in Module1.
Example
A sample for full segment definition
Data SEGMENT
Num1 DB 10H
Num2 DB 20H
Num3 EQU 30H
Data ENDS
ASSUME CS:Code,DS:Data
Code SEGMENT
START: MOV AX,Data
MOV DS,AX
MOV AX,Num1
MOV CX,Num2
ADD AX,CX
Code ENDS
Example
A sample for small model
. MODEL SMALL
.Data
Num1 DB 10H
Num2 DB 20H
Num3 EQU 30H
.
Code
HERE:MOV AX,@Data
MOV DS,AX
MOV AX,Num1
MOV CX,Num2
ADD AX,CX
Code ENDS
Similarly the stack segment is also declared.
For small models
.DATA
…
…
ENDS
The ENDS directive indicates the end of the segment.
Memory is reserved for use in the future by using a ? as an operand for DB DW or DD
directive. The assembler sets aside a location and does not initialize it to any specific
value(usually stores a zero). The DUP (duplicate) directive creates an array and stores a
zero.
Example
Data1 DB 5 DUP(?)
This reserves 5 bytes of memory for a array data1 and initializes each location with 05H
ALIGN: memory array is stored in word boundaries.
Example
ALIGN 2 means storing from an even address
The data XX is aligned to the even address
-----------------------------------------------------------------------------------------------------
Download