0% found this document useful (0 votes)
57 views

Assembler Directives

The document describes various assembler directives used in 8086 assembly language. It discusses data declaration directives like DB, DW, DD, DQ, DT which are used to declare variables of different data types. Other directives described include ASSUME to define logical segments, END to mark the end of a program, PROC/ENDP to define procedures, EQU to assign names to values, ORG to set the location counter, SEGMENT to define segments, GROUP to group segments, EXTRN/PUBLIC for external references, TYPE to determine variable sizes, PTR to define pointer types, LENGTH to get array lengths, OFFSET to get variable offsets, NAME to name modules, LABEL for labels, SHORT for short

Uploaded by

Murali Krishna
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views

Assembler Directives

The document describes various assembler directives used in 8086 assembly language. It discusses data declaration directives like DB, DW, DD, DQ, DT which are used to declare variables of different data types. Other directives described include ASSUME to define logical segments, END to mark the end of a program, PROC/ENDP to define procedures, EQU to assign names to values, ORG to set the location counter, SEGMENT to define segments, GROUP to group segments, EXTRN/PUBLIC for external references, TYPE to determine variable sizes, PTR to define pointer types, LENGTH to get array lengths, OFFSET to get variable offsets, NAME to name modules, LABEL for labels, SHORT for short

Uploaded by

Murali Krishna
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

Assembler directives

of 8086
ASSEMBLER DIRECTIVES

● It is a statement to give direction to the


assembler to perform task of the assembly
process.
Data declaration directives

1. DB - The DB directive is used to declare a


BYTE -2-BYTE variable - A BYTE is made up
of 8 bits.

● examples:
 PRICES DB 49H, 98H, 29H; Declare array of 3 bytes
named PRICES and initialize them with specified
values
 TEMP DB 100 DUP (?); Set aside 100 bytes of
storage in memory and give it the name TEMP. But
leave the 100 bytes un-initialized
Data declaration directives

2. DW - The DW directive is used to declare a


WORD type variable - A WORD occupies 16 bits or
(2 BYTE).

● examples:
WORDS DW 1234H, 3456H;
Declares an array of 2 words and initialize them with
the specified values
Data declaration directives

3. 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.

● examples:
ARRAY DD 25629261H;
This will define a double word named ARRAY and
initialize the double word with the specified value when
the program is loaded into memory to be run. The low
word, 9261H, will be put in memory at a lower address
than the high word.
Data declaration directives (cont.)

● DQ (DEFINE QUADWORD)
The DQ directive is used to tell the assembler to declare a
variable 4 words in length or to reserve 4 words of storage
in memory.

Example:

BIG_NUMBER DQ 243598740192A92BH
; This will declare a variable named BIG_NUMBER and
initialize the 4 words set aside with the specified number when
the program is loaded into memory to be run.
Data declaration directives (cont.)

● DT (DEFINE TEN BYTES)


The DT directive is used to tell the assembler to declare a
variable, which is 10 bytes in length or to reserve 10 bytes
of storage in memory.

Example:
PACKED_BCD DT 11223344556677889900
This will declare an array named PACKED_BCD, which is
10 bytes in length. It will initialize the 10 bytes with the
values 11, 22, 33, 44, 55, 66, 77, 88, 99, and 00 when the
program is loaded into memory to be run. The statement
RESULT DT 20H DUP (0) will declare an array of 20H
blocks of 10 bytes each and initialize all 320 bytes to 00
when the program is loaded into memory to be run.
ASSUME DIRECTIVE

● ASSUME Directive - The ASSUME directive is used to tell the


assembler that the name of the logical segment should be used
for a specified segment. The 8086 works directly with only 4
physical segments: a Code segment, a data segment, a stack
segment, and an extra segment.

Example:
● ASSUME CS:CODE ;This tells the assembler that the logical
segment named CODE contains the instruction statements for
the program and should be treated as a code segment.

● ASSUME DS:DATA ;This tells the assembler that for any


instruction which refers to a data in the data segment, data
will found in the logical segment DATA.
End directive

● END – it signifies the end of the program


module
 The assembler will ignore any statement
after an END directive
● ENDP - indicates the end of a procedure
 Syntax: Procedure_name ENDP
● ENDS - indicates the end of a logical
segment
 Syntax: Segment_name ENDS
Equate (EQU) Directive

● EQU – It is used to give a name to some value (or) to a


symbol. Each time the assembler finds the name in the
program, it will replace the name with the value or
symbol you given to that name.
● Example:
 FACTOR EQU 03H ; you has to write this statement at the starting
ofyour program
 later in the program you can use this as follows :
 ADD AL, FACTOR ; When it codes this instruction the assembler wil
code it as ADDAL, 03H ;The advantage of using EQU in this manner
is, if FACTOR is used many no of times in a program and you want to
change the value, all you had to do is change the EQU statement at
beginning, it will changes the rest of all.
PROC (Procedure) Directive

● PROC – It is used to identify the start of a procedure.


The term near (or) far is used to specify the type of
the procedure.
● Example:
 SMART PROC FAR ; This identifies that the start of a
procedure named as SMART and instructs the assembler that
the procedure is far .
 SMART ENDP ; This PROC is used with ENDP to indicate the
break of the procedure.
ORG (ORIGIN)

● ORG Changes the starting offset address of the data in the


data segment.

● The location counter is automatically set to 0000 when


assembler starts reading a segment.

● The ORG directive allows you to set the location counter to


a desired value at any point in the program.
Example:
 ORG 2000H tells the assembler to set the location
counter to2000H.
SEGMENT

● SEGMENT directive : It is to indicate the start of a


logical segment
● Syntax: Segment_name SEGMENT
● Additional terms are often added to a SEGMENT
directive statement to indicate some special way
in which we want the assembler to treat the
segment.
GROUP directive

● GROUP – It is used to group the logical segments


named after the directive into one logical group
segment.

Eg:

PROGRAM GROUP CODE, DATA, STACK

ASSUME CS:PROGRAM, DS:PROGRAM, SS:PROGRAM


EXTRN, PUBLIC

● External (EXTRN) informs the assembler that the


names, procedures and labels declared after this
directive have already been defined in some other
assembly language modules
● While in the other modules, where the names,
procedures and labels actually appear, they must
declared public, using PUBLIC directive
● PUBLIC - The PUBLIC directive is used to instruct
the assembler that a specified name or label will be
accessed from other modules.
EXTRN, PUBLIC

● Example:
MODULE1 SEGMENT
PUBLIC FACTORIAL FAR
MODULE1 ENDS

MODULE2 SEGMENT
EXTRN FACTORIAL FAR
MODULE2 ENDS
TYPE (POINTER)

● TYPE - instructs the assembler to


determine the type of a variable and
determines the number of bytes specified
to that variable.
Example:
• Byte type variable – assembler will give a value 1
• Word type variable – assembler will give a value
2
• Double word type variable – assembler will give
a value 4
MOV AX, TYPE WORD_ ARRAY
; It moves the value 0002H to AX
PTR(POINTER)

● PTR (POINTER) : used to declare the type of a


label, variable (or) memory operand.
● PTR is prefixed by either BYTE OR WORD
Example:
 INC [BX]; It will not know whether to increment the byte
pointed to by BX. We use the PTR operator to clarify how we want
the assembler to code the instruction.

 INC BYTE PTR [BX] ; This statement tells the assembler that
we want to increment the byte pointed to by BX.

 INC WORD PTR [BX] ; This statement tells the assembler that
we want to increment the word pointed to by BX. The PTR operator
assigns the type specified before PTR to the variable specified after
PTR.
LENGTH

LENGTH : Byte Length of a label


● It tells the assembler to determine the number
of elements in a string (or) data array.
● Example:
MOV CX, LENGTH STRING1
; This will determine the number of elements in
STRING1 and load it into CX.
If the string was declared as a string of bytes,
LENGTH will produce the number of bytes in the
string.
If the string was declared as a word string, LENGTH
will produce the number of words in the string.
OFFSET

● OFFSET : tells the assembler to determine


the offset or displacement of a named data
item (variable)
● Example:
MOV BX, OFFSET PRICES
; It will determine the offset of the variable
PRICES from the start of the segment in which
PRICES is defined and will load this value into
BX.
NAME, LABEL, SHORT, GLOBAL

● NAME : Logical Name of a Module


It is used to give a specific name to each assembly
module when programs consisting of several
modules are written.


LABEL

● LABEL: Label
As an assembler assembles a section of a data
declarations (or) instruction statements, it uses a
location counter to be keep track of how many bytes
it is from the start of a segment at any time.
 If the label is going to be used as the
destination for a jump or a call, then the label
must bespecified as type near or type far.


NAME, LABEL, SHORT, GLOBAL

● NAME : used to give a specific name to each assembly module when programs consisting of
several modules are written.
● LABEL : As an assembler assembles a section of a data declarations or instruction statements,
it uses a location counter to be keep track of how many bytes it is from the start of a segment at
any time.
 If the label is going to be used as the destination for a jump or a call, then the label must be
specified as type near or type far.

● SHORT
The SHORT operator is used to tell the assembler that only a 1 byte displacement is
needed to code a jump instruction in the program. The destination must in the range of –
128 bytes to +127 bytes from the address of the instruction after the jump.
Example: JMP SHORT NEARBY_LABEL

● GLOBAL (DECLARE SYMBOLS AS PUBLIC OR EXTRN) : can be used in place of a


PUBLIC directive or in place of an EXTRN directive. For a name or symbol defined in the
current assembly module, the GLOBAL directive is used to make the symbol available to other
modules.
 Example:
GLOBAL DIVISOR
This statement makes the variable DIVISOR public so that it can be accessed from
other assembly modules.

NAME, LABEL, SHORT, GLOBAL

● NAME : used to give a specific name to each assembly module when programs consisting of
several modules are written.
● LABEL : As an assembler assembles a section of a data declarations or instruction statements,
it uses a location counter to be keep track of how many bytes it is from the start of a segment at
any time.
 If the label is going to be used as the destination for a jump or a call, then the label must be
specified as type near or type far.

● SHORT
The SHORT operator is used to tell the assembler that only a 1 byte displacement is
needed to code a jump instruction in the program. The destination must in the range of –
128 bytes to +127 bytes from the address of the instruction after the jump.
Example: JMP SHORT NEARBY_LABEL

● GLOBAL (DECLARE SYMBOLS AS PUBLIC OR EXTRN) : can be used in place of a


PUBLIC directive or in place of an EXTRN directive. For a name or symbol defined in the
current assembly module, the GLOBAL directive is used to make the symbol available to other
modules.
 Example:
GLOBAL DIVISOR
This statement makes the variable DIVISOR public so that it can be accessed from
other assembly modules.

EVEN

● EVEN - instructs the assembler to increment


the location of the counter to the next even
address if it is not already in the even address.
 If the word is at even address 8086 can read a memory in
1 bus cycle. If the word starts at an odd address, the 8086 will take 2
bus cycles to get the data.
 A series of words can be read much more quickly if they are at
even address.
When EVEN is used the location counter will simply incremented to
next address and NOP instruction is inserted in that incremented
location.
EVEN

● GROUP - used to group the logical segments named after the


directive into one logical group segment.
● INCLUDE - used to insert a block of source code from the named
file into the current source module.
● EVEN - instructs the assembler to increment the location of the
counter to the next even address if it is not already in the even
address.
 If the word is at even address 8086 can read a memory in 1 bus
cycle. If the word starts at an odd address, the 8086 will take 2 bus cycles to get
the data.
 A series of words can be read much more quickly if they are at even address.
When EVEN is used the location counter will simply incremented to next address
and NOP instruction is inserted in that incremented location.

● ALIGN: Memory array is stored in word boundaries.


Example:
 ALIGN 2 means storing from an even address
8086 Programming using Assembler Directives

●Basic structure of a program:


Name_data segment SEGMENT
Data declaration statement 1
:
:
Data declaration statement n
DATA ENDS
Name_codeseg SEGMENT
ASSUME CS:CODE, DS:DATA, ES:EXTRA, SS: STACK
START:
Program line 1
:
:
Program line n
Name_codeseg ENDS
END START
example

● Program to multiply 2 16-bit words in memory locations called MULTIPLICAND


and MULTIPLIER. Result is stored in memory location PRODUCT.
DATA SEGMENT
MULTIPLICAND DW 204A H; 1ST Word
MULTIPLIER DW 3B2A H; 2nd word
PRODUCT DW 2 DUP(0); sets aside storage for 2 words in memory and gives starting address of 1st word
the name PRODUCT. The DUP(0) part of the statement tells assembler to initialize 2 words to all zeros.
DATA ENDS
CODE SEGMENT
ASSUMER CS:CODE, DS:DATA;
START:
MOV AX, DATA
MOV DS, AX
MOV AX, MULTIPLICAND;
MUL MULTIPLIER;
MOV PRODUCT, AX;
MOV PRODUCT+2, DX;
INT3
CODE ENDS
END START
Thank you

You might also like