Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 19

Assembler Directives of 8085

What is an Assembler?

We know that assembly language is a less complex and programmer-friendly language used
to program the processors. In assembly language programming, the instructions are specified
in the form of mnemonics rather in the form of machine code i.e., 0 and 1. But the
microprocessor or microcontrollers are specifically designed in a way that they can only
understand machine language.
Thus assembler is used to convert assembly language into machine code so that it can be
understood and executed by the processor. Therefore, to control the generation of machine
codes from the assembly language, assembler directives are used. However, machine codes
are only generated for the program that must be provided to the processor and not for
assembler directives because they do not belong to the actual program.

Assembler Directives of 8085

The assembler directives given below are used by 8085 and 8086 assemblers:

DB: Define Byte
This directive is used for the purpose of allocating and initializing single or multiple data
bytes.

Memory name AREA has three consecutive locations where 30H, 52H and 35H are to be
stored.

DW: Define Word
It is used for initialising single or multiple data words (16-bit).
These two 16-bit data 1020H and 4216H are stored at 4 consecutive locations in the memory
MARK.

END: End of program
This directive is used at the time of program termination.

EQU: Equate
It is used to assign any numerical value or constant to the variable.

Variable name ‘DONE’ has value 10H

MACRO: Represents beginning
Shows the beginning of macro along with defining name and parameters.

ENDM: End of macro
ENDM indicates the termination of macro.

where macroname (STEP) is specified by the user.

ORG: Origin
This directive is used at the time of assigning starting address for a module or segment.
By this instruction, the assembler gets to know that the statements following this instruction,
must be stored in the memory location beginning with address 1050H.

Assembler Directives of 8086

These assembler directives are specifically used by 8086:

ASSUME: Shows the segment name to the assembler


It provides information to the assembler regarding the name of the program or data segment
for that particular segment.

This directive specifies that the instruction of the source program is stored in logical segment
_DONE.

DD: Define Double word


This directive allows the initialization of single or multiple data in the form of double words
(i.e., 4 bytes). The is used to inform the assembler that the stored data in memory is a double
word.

Thus memory stores the given data in the form:


DQ: Define Quad words
It is used to initialise quad words (8-bytes) either one or more than one. Thereby informing
the assembler that the data stored in memory is quad-word.

DT: Define ten bytes


It is used to allocate and initialize 10 bytes of a variable.

DUP: Duplicate
DUP allows initialization of multiple locations and assigning of values to them. This allows
storing of repeated characters or variables in different locations.

So this permits the storing of these data in memory and creating 8 identical sets in the
memory identified as Book.

DWORD: Double word
This directive is used to indicate that the operand is of double word size.

PROC: Procedure
It defines the starting of a procedure/subroutine.
FAR: This directive is a type specifier that is used by the assembler to declare intersegment
call (i.e., call from different segment).
Procedure is used outside the code segment
NEAR: This is used for intrasegment call i.e., a call within the same segment.
Procedure is used inside the code segment

ENDP: End of procedure
This directive shows the termination of a procedure.

SEGMENT: Beginning of a memory segment.


It is used to show the beginning of a memory segment with a specific name.

ENDS: End of segment
This directive defines the termination of a particular memory segment as it is specified by its
name.

The statements within the segment are nothing but the program code.

EVEN: It is used to inform the assembler to align the data beginning from an even address.
As data specified with an odd starting address requires 2 byte accessing. Thus using this
directive, data can be aligned with an even starting address.

PTR: Pointer
This directive shows information regarding the size of the operand.
This shows legal near jump to BX.

PUBLIC: This directive is used to provide a declaration to variables that are common for
different program modules.
STACK: This directive shows the presence of a stack segment.

SHORT: This is used in reference to jump instruction in order to assign a displacement of


one byte.
THIS: It is used along with EQU directive for setting the label to either, byte, word or
double-word.
So, these assembler directives are used by the processors for controlling the generation of
machine code and organization of the program.

8086 ASSEMBLY PROGRAM FOR ADDITION OF TWO 8 BIT


NUMBERS
data segment
a db 09h
b db 02h
c dw ?
data ends
 
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov al,a
mov bl,b
add al,bl
mov c,ax
int 3
code ends
end start
Output
AX = 0BH

8086 ASSEMBLY PROGRAM FOR SUBTRACTION OF TWO 8 BIT


NUMBERS
data segment
a db 09h
b db 04h
c dw ?
data ends
 
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov al,a
mov bl,b
sub al,bl
mov c,ax
int 3
code ends
end start
Output
AX = 07H

8086 ASSEMBLY PROGRAM FOR MULTIPLICATION OF TWO 8 BIT


NUMBERS
data segment
a db 04h
b db 02h
c dw ?
data ends
 
code segment
assume cs:code, ds:data
start:
mov ax,data
mov ds,ax
mov ax,0000h
mov bx,0000h
mov al,a
mov bl,b
mul b
mov c,ax
int 3
code ends
end start
Output
AX = 08H

8086 ASSEMBLY PROGRAM FOR DIVISION OF TWO 8 BIT


NUMBERS
data segment
a db 28h
b db 02h
c dw ?
data ends
 
code segment
assume cs:code, ds:data
start:
mov ax,data
mov ds,ax
mov ax,0000h
mov bx,0000h
mov al,a
mov bl,b
div b
mov c,ax
int 3
code ends
end start
Output
AX 14H

8086 ASSEMBLY PROGRAM TO ADD TWO 16 BIT NUMBERS


data segment
a dw 0202h
b dw 0408h
c dw ?
data ends
 
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov ax,a
mov bx,b
add ax,bx
mov c,ax
int 3
code ends
end start
Output
AX=060A  BX=0408  CX=0022  DX=0000 

8086 ASSEMBLY PROGRAM TO SUBTRACT TWO 16 BIT NUMBERS


data segment
a dw 9A88h
b dw 8765h
c dw ?
data ends
 
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov ax,a
mov bx,b
sub ax,bx
mov c,ax
int 3
code ends
end start
Output
AX=1323  BX=8765  CX=0022  DX=0000

8086 ASSEMBLY PROGRAM TO MULTIPLY TWO 16 BIT NUMBERS


data segment
a dw 1234h
b dw 5678h
c dd ?
data ends
 
code segment
assume ds:data, cs:code
start:
mov ax,data
mov ds,ax
mov ax,a
mov bx,b
mul bx
mov word ptr c,ax
mov word ptr c+2,dx
int 3
code ends
end start
Output
AX=0060  BX=5678  CX=0026  DX=0626

8086 ASSEMBLY PROGRAM TO DIVIDE TWO 16 BIT NUMBERS


data segment
a dw 4444h
b dw 0002h
c dw ?
data ends
 
code segment
assume ds:data, cs:code
start:
mov ax,data
mov ds,ax
mov ax,a
mov bx,b
div bx
mov c,ax
int 3
code ends
end start
Output
AX=2222  BX=0002  CX=0022  DX=0000 
Factorial of a number
Data segment
X1 db 4
Fact dw ?
Data ends
Code segment
ASSUME CS: code, DS: data
Start: MOV AX,data
Mov DS,AX
MOV AX,0001H
MOV CL,AL
CALL FACTO
JUMP EXIT
FACTO PROC NEAR
Mul cl
Dec cl
Cmp cl,01H
JZ label1
CALL Facto
Label1 :ret
Facto endp
Exit: Mov fact, ax
Mov ah,4ch
Int 21H
Code ends
End start

PERFORMING BLOCK TRANSFER USING ASSEMBLY LANGUAGE


DATA SEGMENT
STRING1 DB 01H,02H,03H,04H,05H
STRING2 DB 4 DUP(0)
DATA ENDS
 
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV ES,AX
LEA SI,STRING1
LEA DI,STRING2
MOV CX,05H
CLD
REP MOVSB
INT 3
CODE ENDS
END START
Output
AX=0B97  BX=0000  CX=0000  DX=0000 

0B97:0000  01 02 03 04 05

Program to check whether a number is Even or Odd using Macro > Assembly
Language

Microprocessor

ASSUME CS:CODE,DS:DATA

DATA SEGMENT
MSG DB 10,13,'ENTER A NUMBER = $'
MSG1 DB 10,13,'NUMBER IS EVEN $'
MSG2 DB 10,13,'NUMBER IS ODD $'
DATA ENDS

CODE SEGMENT
START:
MOV BX,DATA
MOV DS,BX

PRINT MACRO MESSAGE


LEA DX,MESSAGE
MOV AH,09H
INT 21H
ENDM

PRINT MSG

MOV AH,01H
INT 21H

SAR AL,01
JC ODD

PRINT MSG1

JMP TERMINATE

ODD:
PRINT MSG2

TERMINATE:
MOV AH,4CH
INT 21H

CODE ENDS 
END START

/*
OUTPUT-------------
C:\Users\student>CD C:\Tasm 1.4\Tasm

C:\Tasm 1.4\Tasm>TASM ODDEVE


Turbo Assembler  Version 3.0  Copyright (c) 1988, 1991 Borland Internationa

Assembling file:   ODDEVE.ASM


Error messages:    None
Warning messages:  None
Passes:            1
Remaining memory:  460k

C:\TASM1~1.4\Tasm>TLINK ODDEVE
Turbo Link  Version 2.0  Copyright (c) 1987, 1988 Borland International
Warning: no stack

C:\TASM1~1.4\Tasm>ODDEVE
ENTER A NUMBER = 2
NUMBER IS EVEN
C:\TASM1~1.4\Tasm>ODDEVE

ENTER A NUMBER = 1
NUMBER IS ODD
C:\TASM1~1.4\Tasm>

*/

8086 ASSEMBLY PROGRAM TO CONVERT BINARY NUMBER INTO


BCD FORMAT
DATA SEGMENT
NO1 DB "1001000000110110"
D1 DW 4 DUP (?)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
LEA SI, NO1
LEA DI, D1
MOV CX, 04H
TOP:
MOV BX, 00H
MOV AX, [SI]
ROR AX, 1
JNC P2
ADD BX, 08H
P2:
INC SI
MOV AX, [SI]
ROR AX, 1
JNC P3
ADD BX, 04H
P3:
INC SI
MOV AX, [SI]
ROR AX, 1
JNC P4
ADD BX, 02H
P4:
INC SI
MOV AX, [SI]
ROR AX, 1
JNC P5
ADD BX, 01H
P5:
MOV [DI], BX
INC DI
INC SI
DEC CX
JNZ TOP
INT 3
CODE ENDS
END START
Output
AX=0498 BX=0006 CX=0000 DX=0000
8086 ASSEMBLY PROGRAM TO COUNT NUMBER OF 0’S AND 1’S
FROM A NUMBER
DATA SEGMENT
NO DW 5648H
Z DW ?
O DW ?
DATA ENDS
 
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
MOV AX, NO
MOV BX, 00H
MOV CX, 10H
MOV DX, 00H
 
UP:
ROL AX,1
JC ONE
INC BX
JMP NXT
 
ONE:
INC DX
 
NXT:
DEC CX
JNZ UP
 
MOV Z, BX
MOV O, DX
 
INT 3
CODE ENDS
END START
Output
AX=5648  BX=000A  CX=0000  DX=0006  SP=0000  BP=0000  SI=0000  DI=0000
DS=0B97  ES=0B87  SS=0B97  CS=0B98  IP=0025   NV UP EI PL ZR NA PE NC
0B98:0025 CC            INT     3
-d 0b97:0000
0B97:0000  48 56 0A 00 06 00 00 00-00 00 00 00 00 00 00 00   HV..............
0B97:0010  B8 97 0B 8E D8 A1 00 00-BB 00 00 B9 10 00 BA 00   ................
0B97:0020  00 D1 C0 72 04 43 EB 02-90 42 49 75 F4 89 1E 02   ...r.C...BIu....
0B97:0030  00 89 16 04 00 CC E8 77-63 83 C4 06 FF 36 24 21   .......wc....6$!
0B97:0040  B8 0A 00 50 E8 47 5E 83-C4 04 5E 8B E5 5D C3 90   ...P.G^...^..]..
0B97:0050  55 8B EC 81 EC 84 00 C4-5E 04 26 80 7F 0A 00 74   U.......^.&....t
0B97:0060  3E 8B 46 08 8B 56 0A 89-46 FC 89 56 FE C4 5E FC   >.F..V..F..V..^.
0B97:0070  26 8A 47 0C 2A E4 40 50-8B C3 05 0C 00 52 50 E8   &.G.*.@P.....RP.
-q
8086 ASSEMBLY PROGRAM TO FIND SMALLEST NUMBER FROM
GIVEN NUMBERS
data segment
STRING1 DB 08h,14h,05h,0Fh,09h
res db ?
data ends
 
code segment
assume cs:code, ds:data
start: mov ax, data
mov ds, ax
mov cx, 04h
 
mov bl, 79h
LEA SI, STRING1
up:
mov al, [SI]
cmp al, bl
jge nxt
mov bl, al
nxt:
inc si
dec cx
jnz up
 
mov res,bl
int 3
code ends
end start
Output
AX=0B0F  BX=0005  CX=0000  DX=0000  SP=0000  BP=0000  SI=0004  DI=0000
DS=0B37  ES=0B27  SS=0B37  CS=0B38  IP=001E   NV UP EI PL ZR NA PE NC
0B38:001E CC            INT     3
-d 0b37:0000
0B37:0000  08 14 05 0F 09 05 00 00-00 00 00 00 00 00 00 00   ................
0B37:0010  B8 37 0B 8E D8 B9 04 00-B3 79 8D 36 00 00 8A 04   .7.......y.6....
0B37:0020  3A C3 7D 02 8A D8 46 49-75 F4 88 1E 05 00 CC FC   :.}...FIu.......
0B37:0030  FE C4 9E FA FE 26 8A 47-0C 2A E4 40 50 8B C3 05   .....&.G.*.@P...
0B37:0040  0C 00 52 50 E8 19 46 83-C4 04 50 8D 86 00 FF 50   ..RP..F...P....P
0B37:0050  E8 6F 70 83 C4 06 B8 CD-05 50 8D 86 00 FF 50 E8   .op......P....P.
0B37:0060  CA 0C 83 C4 04 B8 FF FF-50 8D 86 00 FF 50 8D 46   ........P....P.F
0B37:0070  80 50 E8 4D FA 83 C4 06-0A C0 75 03 E9 7B FF 5E   .P.M......u..{.^
-q
8086 ASSEMBLY PROGRAM TO FIND LARGEST NUMBER FROM
GIVEN NUMBERS
data segment
STRING1 DB 08h,14h,05h,0Fh,09h
res db ?
data ends
 
code segment
assume cs:code, ds:data
start: mov ax, data
mov ds, ax
mov cx, 04h
 
mov bl, 00h
LEA SI, STRING1
up:
mov al, [SI]
cmp al, bl
jl nxt
mov bl, al
nxt:
inc si
dec cx
jnz up
 
mov res,bl
int 3
code ends
end start
Output
AX=0B0F  BX=0014  CX=0000  DX=0000  SP=0000  BP=0000  SI=0004  DI=0000
DS=0B37  ES=0B27  SS=0B37  CS=0B38  IP=001E   NV UP EI PL ZR NA PE CY
0B38:001E CC            INT     3
-d 0b37:0000
0B37:0000  08 14 05 0F 09 14 00 00-00 00 00 00 00 00 00 00   ................
0B37:0010  B8 37 0B 8E D8 B9 04 00-B3 00 8D 36 00 00 8A 04   .7.........6....
0B37:0020  3A C3 7C 02 8A D8 46 49-75 F4 88 1E 05 00 CC FC   :.|...FIu.......
0B37:0030  FE C4 9E FA FE 26 8A 47-0C 2A E4 40 50 8B C3 05   .....&.G.*.@P...
0B37:0040  0C 00 52 50 E8 19 46 83-C4 04 50 8D 86 00 FF 50   ..RP..F...P....P
0B37:0050  E8 6F 70 83 C4 06 B8 CD-05 50 8D 86 00 FF 50 E8   .op......P....P.
0B37:0060  CA 0C 83 C4 04 B8 FF FF-50 8D 86 00 FF 50 8D 46   ........P....P.F
0B37:0070  80 50 E8 4D FA 83 C4 06-0A C0 75 03 E9 7B FF 5E   .P.M......u..{.^
-q

PROGRAMS (using register addressing mode):


A. 16 BIT ADDITION
1 assume cs:code,ds:data
2
3 0000 data segment
4 0000 1243 n1 dw 1243h
5 0002 4567 n2 dw 4567h
6 0004 ???? n3 dw ?
7 0006 data ends
8
9 0000 code segment
10
11 0000 start:
12 0000 B8 0000s mov ax,data
13 0003 8E D8 mov ds,ax
14
15 0005 A1 0000r mov ax,n1
16 0008 8B 1E 0002r mov bx,n2
17 000C 03 C3 add ax,bx
18 000E A3 0004r mov n3,ax
19 0011 BE 0004r lea si,n3
20 0014 CC int 3
21
22 0015 code ends
23 end start
4/1 EEE- Microprocessors and Microcontrollers Lab Manual Aurora’s Engineering College
2
B. 16 BIT SUBTRACTION
1 assume cs:code,ds:data
2
3 0000 data segment
4 0000 FFFF n1 dw 0ffffh
5 0002 4567 n2 dw 4567h
6 0004 ???? n3 dw ?
7 0006 data ends
8
9 0000 code segment
10
11 0000 start:
12 0000 B8 0000s mov ax,data
13 0003 8E D8 mov ds,ax
14
15 0005 A1 0000r mov ax,n1
16 0008 8B 1E 0002r mov bx,n2
17 000C 2B C3 sub ax,bx
18 000E A3 0004r mov n3,ax
19 0011 BE 0004r lea si,n3
20 0014 CC int 3
21
22 0015 code ends
23 end start
C. 16 BIT MULTIPLICATION
1 assume cs:code,ds:data
2
3 0000 data segment
4 0000 4444 n1 dw 4444h
5 0002 4567 n2 dw 4567h
6 0004 ???????? n3 dd ?
7 0008 data ends
8
9 0000 code segment
10
11 0000 start:
12 0000 B8 0000s mov ax,data
13 0003 8E D8 mov ds,ax
14
15 0005 A1 0000r mov ax,n1
16 0008 8B 1E 0002r mov bx,n2
17 000C F7 E3 mul bx
18 000E BE 0004r lea si,n3
19 0011 89 04 mov [si],ax
20 0013 89 54 02 mov [si+2],dx
4/1 EEE- Microprocessors and Microcontrollers Lab Manual Aurora’s Engineering College
3
21
22 0016 CC int 3
23
24 0017 code ends
25 end start
D. WORD BY BYTE DIVISION
1 assume cs:code,ds:data
2
3 0000 data segment
4 0000 0444 n1 dw 0444h
5 0002 45 n2 db 45h
6 0003 ???? n3 dw ?
7 0005 data ends
8
9 0000 code segment
10
11 0000 start:
12 0000 B8 0000s mov ax,data
13 0003 8E D8 mov ds,ax
14
15 0005 A1 0000r mov ax,n1
16 0008 8A 1E 0002r mov bl,n2
17 000C F6 F3 div bl
18
19 000E A3 0003r mov n3,ax
20 0011 BE 0003r lea si,n3
21
22 0014 CC int 3
23
24 0015 code ends
25 end start
RESULT:
A. 16 BIT ADDITION
AX= 57AA & SI=0004 ; D 0004 0005 AA 57
B. 16 BIT SUBTRACTION
AX= BA98 & SI=0004 ; D 0004 0005 98 BA
C. 16 BIT MULTIPLICATION
AX= CB5C & SI=0004 ; D 0000 0005 44 44 67 45 5C CB
4/1 EEE- Microprocessors and Microcontrollers Lab Manual Aurora’s Engineering College

You might also like