Sie sind auf Seite 1von 34

Assembler Directives

Assembly Language
Programming
Low level programming language for
computers, microprocessors,
microcontrollers and other
programming devices
It includes symbolic representation of
machine code and other constants
needed for programming the CPU

Components of an Assembly
language Instruction
Typical assembly language consists
of 3 type of instruction statements
that are used to define program
operations
1.Opcode mneumonics
2.Assembler directives
3.Pseudo Opcodes

Opcode mneumonicssymbolic name for


a single executable machine language
instruction Eg:- MOV, ADD, SUB etc
Assembler Directives are instructions
that are executed by an assembler at
assembly time not by a CPU at run time.
Pseudo Code--a notation resembling a
simplified programming language, used in
program design.

Assembler Directives
Instructions that are executed by an
assembler at assembly time, not by a
CPU at run time
It is actually directives to the assembler,
not translated to machine instructions
by the assembler but are executed by it
An assembler directive is a statement to
give direction to the assembler to
perform task of the assembly process.

Assembler Directives
It control the organization if the program and provide
necessary information to the assembler to understand
the assembly language programs to generate
necessary machine codes. They indicate how an
operand or a section of the program is to be processed
by the assembler.
An assembler supports directives to define data, to
organize segments to control procedure, to define
macros. It consists of two types of statements:
instructions and directives. The instructions are
translated to the machine code by the assembler
whereas directives are not translated to the machine
codes

Assembler Directives
The set of assembler directives supported by an assembler
vary from assembler to assembler, they include
1.Data definition and storage directives and operators
2.Program organization directives
3.Alignment directives
4.Programs directives
5.Value returning attribute directives
6.Procedure definition directives
7.Macro definition directives
8.Data control directives
9.Branch displacement directives
10.
Header file inclusion directives
11.
Target machine code generation control directives

Data definition directives and


Operators
Data definition directives are used to
define the program variables and
allocate a specified amount of
memory
to them Size
Variable Type
BYTE

WORD

DWORD

QWORD

TBYTE

10

Data definition directives and


Operators
Data definition directives include
1. DB
2. DW
3. DD
4. DQ
5. DT
6. STRUCT
7. RECORD

DB(define BYTE)
Used to define a byte type variable
It can be used to declare single or multiple
BYTE variables
Syntax
name DB initialization value(s)
Where namename of variable to be defined
Initialization valuehex, dec or binary
number
or ? Symbol for variables that re not initialized

DB Declaration examples:
Byte1 DB 10h
MEM DB 35H,0FH,6DH

DW(Define Word)
DW - The DW directive is used to
declare a WORD type variable - A
WORD occupies 16 bits or (2 BYTE).
Syntax
name DW initialization value(s)
Declaration examples:
Word DW 1234h
Word2 DW 65535

DD(Define Double Word)


DD - The DD directive is used to
declare a DWORD - A DWORD double
word is made up of 32 bits =2 Word's
or 4 BYTE.
Syntax
name DD initialization value(s)
Declaration examples:
Dword1 DW 12345678h
Dword2 DW 4294967295 ;
0FFFFFFFFh.

DQ(Define Quad Words)


Used to define a QWORD
type(8bytes)
QWORD=64 bits
Syntax
name DQ initialization value(s)
Declaration examples:
BIG_NUMBER DQ
243895740192A92BH

DT(Define Ten Bytes)


Used to define a TBYTE type
QWORD=64 bits
Syntax
name DT initialization value(s)
Declaration examples:
PACKED_BCD DT
1122334455667788990H

STRUCT (Structure
Declaration)
STRUCT and ENDS directives to define a
structure template for grouping data items.
The STRUCT directive tells the assembler
that a user defined uninitialized data
structure follows. The uninitialized data
structure consists of a combination of the
three supported data types. DB, DW, and
DD.
A Structure ends by using the ENDS
directive meaning END of Structure.

Syntax
structurename STRUCT
..sequence of DB,DW,DD declarations for defining
fields
Structurename ENDS
Example
STUDENT STRUCT
ROLLNO DW ?
NAME DB 10 DUP(?)
CLASS DB ?
CORE DB 10 DUP(?)
STUDENT ENDS

? (uninitialized value)
? Operator is used as for initialializing
in data declarations
Example
MEM1 DW ?
MEM2 DB ?,?,? ; allocates three
uninitialized bytes

DUP(Duplicate)
This can be used to initialize several
locations and to assign values to
these locations
Syntax
Name_Data_Type Num DUP(value)
Example
Table DW 10 DUP (0)

Program Segment Structure


Data Segments
Storage for
variables
Variable addresses
are computed as
offsets from start of
this segment

Code Segment
contains executable
instructions

Stack Segment
used to set aside
storage for the
stack
Stack addresses are
computed as offsets
into this segment

Segment directives
.data
.code
.stack size

Program Organization
Directives
In 8086 programs are organized as a
collection of logical segments.
The program organization directives
are used to define memory
segments
These include
SEGMENT
ENDS
ASSUME

SEGMENT
This is used to indicate the start of a logical
segment
The syntax of the SEGMENT directive
segmentname SEGMENT
statements
Example
CODE SEGMENT
To indicate the assembler the start of a logical
segment called CODE
The SEGMENT and ENDS directives are used to
bracket a logical segment containing code or data

ENDS
To indicate the end of a logical
segment
Syntax
segment ENDS
Example
CODE SEGMENT
statements
CODE ENDS

ASSUME
The 8086 can address only for
segments at a homecode,data,stack,extra
Assembly language program contain
multiple segments of each type
Only one of each type can active at a
time
The ASSUME directive is used to tell
the assembler the name of the ogical
segment it should use for a specified

ASSUME
Syntax
ASSUME
segmentregister:segmentname
ASSUME CS:CODE
ASSUME DS:DATA

GROUP
Used to tell the assembler to group
the logical segments named after the
directive into one logical group
segment
Example
SMALL_SYSTEM GROUP
CODE,DATA,STACK_SEG
ASSUME CS:SMALL_SYSTEM,
DS:SMALL_SYSTEM,SS:SMALL_SYSTE
M

Alignment Directive
The alignment are used control the
location counter used by the
assembler during the machine code
generation
ORG
EVEN

Program End Directive


To inform the physical end of the
program
END directive is put after the last
statement of a program to tell the
assembler that this is the end of the
program module
The assembler will ignore any
statement after END statement
Syntax
END[start-address]

Value returning attribute


Directives
Used to compute the size of the data
item
This include
LENGTH
SIZE
OFFSET
TYPE

LENGTH
Used to inform the number of elements in a data item
such as array
Syntax
LENGTH variable-name
Example
DATA SEGMENT
NAME DB 100 DUP(?)
A DW 50 DUP(?)
DATA ENDS
The following statements return values as illustrated below
MOV AX, LENGTH NAME ; AX=100
MOV BX, LENGTH A ; BX=50

SIZE
The directive SIZE is same as
LENGTH except that it returns the
number of bytes allocted to the data
item, instead of number of elements
in it
Syntax
SIZE variablename

OFFSET
Used to determine the offset or
displacement of a named data item
or procedure from the start of the
segment which contains in it
Used to load the offset of a variable
into a register so that the variable
can be accessed with one of the
indexed addressing modes
Syntax
OFFSET variablename

SEG-segment
Used to determine the segment in
which the specified data item defined
Syntax
SEG variablename

TYPE
Type of the data item
It determines the number of bytes
allocated to the data type
Syntax
TYPE variablename