You are on page 1of 91

Edited with the trial version of

Foxit Advanced PDF Editor


To remove this notice, visit:
www.foxitsoftware.com/shopping

DECCAN COLLEGE OF ENGINEERING AND TECHNOLOGY


Dar-us-Salam, Hyderabad - 500 001

DEPARTMENT OF COMPUTER SCIENCE


B.E. (II / 1V) – IV SEMESTER

LAB MANUAL
Of

MICROPROCESSOR LAB
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
www.foxitsoftware.com/shopping

DECCAN COLLEGE OF ENGINEERING & TECHNOLOGY


Dar-us-Salam, Hyderabad -500 001

-----------------------------------------------------------------------------------------------------------

Lab Manual for the Academic Year 2018-2019

SUBJECT : MICROPROCESSOR LAB


CODE : PC452CS
SEMESTER : 2/4 SEM-IV
BRANCH : COMPUTER SCIENCE & ENGINEERING
COORDINATOR : MS. NEHA UNNISA
INDEX
CYCLE-1

S.NO NAME OF THE PROGRAMME PG.NO

1. Addition Of Two 8-Bit Numbers 19

2. Subtraction Of Two 8-Bit Numbers 21

3. Addition Of Two 8-Bit Numbers, Sum is 16-Bit 23

4. Decimal Addition Of Two 8-Bit Numbers, Sum is 16-Bit 26

5. Decimal Subtraction Of Two 8-Bit Numbers, Sum is 16-Bit 29

6. Addition Of Two 16-Bit Numbers 31

7. Subtraction Of Two 16-Bit Numbers 34

8. 1’s Complement Of 8-Bit Numbers 37

9. 2’s Complement Of 8-Bit Numbers 39

10. 1’s Complement Of 16-Bit Numbers 41

11. 2’s Complement Of 16-Bit Numbers 43

12. Exchange Contents Of Memory Location 45

13. Multiplication Of Two 8-Bit Numbers 47

14. Addition Of 5 Numbers In Array 50

15. Largest Between Two Numbers 52

16. Smallest Between Two Numbers 54

17. Multiplying A Number By 2 56

18. Multiplying A Number By 4 58

19. Dividing A Number By 2 60

20. Find Odd Or Even Number 62

21. Division Of 2 8-Bit Numbers 64

22. Traffic Light Interface 68


Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
www.foxitsoftware.com/shopping

INDEX
CYCLE-2

S.NO NAME OF THE PROGRAMME PG.NO

(A) Addition of two 8 Bit/ 16 Bit Numbers.


1. (B) Subtraction of two 8 Bit/ 16 Bit Num 77

program to find Average number.


2. 78

Program for finding the largest number in an Array.


3. . 79

4. Program for searching a number in an array. 80


CYCLE-1
INTRODUCTION

8085 MICROPROCESSOR
The Microprocessor is a programmable device that takes in numbers, performs on them
arithmetic or logical operations according to the program stored in memory and then produces
other numbers as a result (Silicon chip which includes ALU, register circuits & control circuits).
A Programmable Machine can be represented with 4 components:-
1. Microprocessor 3.Memory
2. Input 4.Output

Internal Architecture of 8085 Microprocessor:

1
Pin Diagram of 8085 Microprocessor

The main features of 8085 microprocessor are:


 It is an 8 bit microprocessor.
 It is manufactured with N-MOS technology.
 It has 16-bit address bus and hence can address up to 216 = 65536 bytes (64KB) memory
locations through A0-A15
 The first 8 lines of address bus and 8 lines of data bus are multiplexed AD0 – AD7
 Data bus is a group of 8 lines D0 – D7
 It supports external interrupt request.
 A 16 bit program counter (PC)
 A 16 bit stack pointer (SP)
 Six 8-bit general purpose register arranged in pairs: BC, DE, HL.
 It requires a signal +5V power supply and operates at 3.2 MHZ single phase clock.
 It is enclosed with 40 pins DIP (Dual in line package).

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
ES85 MICROPROCESSOR KIT
PROCEDURE OF EXECUTION
Commands and Keys
Reset
This key is located in the main 85 board. On depressing this key the program starts executing
from the beginning or reset address 0000. On power on reset it. Display ES - 85 in local LCD
display.
H (Help Menu)
This key is used go PS-85L help menu and it will display the following commands. Depressing
the space bar key increments to display the next command
KEY FUNCTIONS
A <BEG> ASSEMBLE
B BAUD RATE
D <BEG> DISASSEMBLE
E <BEG><END> EXAMINE
G <BEG> EXECUTE
H HELP COMMANDS
L <OFFSET> DOWN LOAD
M <ADDR> MODIFY
N NORMAL MODE
Q QUIT
R <REG> REGISTER DISPLAY
S SERIAL MODE
T <START><END><DS> BLOCK TRANSFER
U <BEG><END> UP LOAD

17
Steps to Execute the Program on 8085 Microprocessor Kit
Follow the steps given below in order to execute the program on 8085 Microprocessor Kit:
1. Enter Program
2. Enter Data
3. Execute Program
4. Check Result
Procedure:
Press RESET
Press A and Enter starting address of the program ex: 8000 and Press Enter
Ex: A8000
ES85 ------- 8000:
-A8000
Type the Program
 Press RESET
Enter G8000, 8000 which will set the program counter to the address
Give the inputs as example
PC: 8000
S8501H, 21-Value

Press spacebar to enter the next input values and Press enter after last input.
Press N and then press comma till restart is triggered (till change of address)
Check the output as
Press Output
S8503H, 21- value

18
PROGRAM NO. 1

ADDITION OF TWO 8-BIT NUMBERS


Aim: Program for addition of two 8-bit numbers and sum is 8 bit.
Apparatus required: 8085 Microprocessor Kit, +5V Power supply, keyboard
Theory:
Consider the first number 26H is stored in memory location 8501H and the second
number 62H is stored in memory location 8502H.The result after addition of two
numbers is to be stored in the memory location 8503 H. Assume program starts from
memory location 8000H.
Algorithm:
 Initialize the memory location of first number in HL register pair.
 Move first number/data into accumulator
 Increment the content of HL register pair to initialize the memory location of second data
 Add the second data with accumulator
 Store the result in memory location 8503H
Flow chart:

19
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
Address of first number
8000 21 LXI H, 8501 H
in H-L register pair.
Lower byte data is stored
8001 01
in memory
Higher byte data is stored
8002 85
in memory
Transfer first number in
8003 7E MOV A,M
accumulator.
Increment content of H-L
8004 23 INX H
register pair
Add first number and
8005 86 ADD M
second number
Increment content of H-L
8006 23 INX H
register pair
8007 77 MOV M,A Store sum in 8503 H
Terminate program.
8008 EF RST.5 (Memory points to
0028h)

Result:
INPUT DATA RESULT
Memory location Data Memory Data
location
8501 26H 8503 88H
8502 62H 8504 00H

Viva-Voice Questions:

1. What is the function of LXI H, 8000 H instruction?

2. How you can store a data in a memory location?

3. How you can read a data from a memory location?

4. What are flags available in 8085?

5. What is the function of RESET key of a 8085 microprocessor kit

20
PROGRAM NO. 2

SUBTRACTION OF TWO 8-BIT NUMBERS


Aim: Program for Subtraction of two 8-bit numbers and sum is 8 bit.
Apparatus required: 8085 Microprocessor Kit, +5V Power supply, keyboard
Theory:
Consider the first number 07H is stored in memory location 8501H and the second
number 03H is stored in memory location 8502H.The result after Subtraction of two
numbers is to be stored in the memory location 8503 H. Assume program starts from
memory location 8000H.
Algorithm:
 Initialize the memory location of first number in HL register pair.
 Move first number/data into accumulator
 Increment the content of HL register pair to initialize the memory location of second data
 Subtract the second data with accumulator
 Store the result in memory location 8503H
Flow chart:

21
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
Address of first number
8000 21 LXI H, 8501 H
in H-L register pair.
Lower byte data is stored
8001 01
in memory
Higher byte data is stored
8002 85
in memory
Transfer first number in
8003 7E MOV A,M
accumulator.
Increment content of H-L
8004 23 INX H
register pair
subtract first number and
8005 86 SUB M
second number
Increment content of H-L
8006 23 INX H
register pair
8007 77 MOV M,A Store result in 8503 H
Terminate program.
8008 EF RST.5 (Memory points to
0028h)

Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8501 07H 8503 04H
8502 03H 8504 00H

Viva-Voice Questions:
1. What is the function of LXI H, 8000 H instruction?

2. How you can store a data in a memory location?

3. How you can read a data from a memory location?

4. What are flags available in 8085?

5. What is the function of RESET key of a 8085 microprocessor kit

22
PROGRAM NO. 3

ADDITION OF TWO 8 BIT NUMBERS AND SUM IS 16-BIT


Aim: Program for Addition of Two 8-Bit Numbers and Sum is 16 Bit.
Apparatus required: 8085 Microprocessor Kit, +5V Power supply, keyboard
Theory:
The first number 34H is stored in memory location 8501H and the second number 26H is
stored in memory location 8502H. The result after addition will be stored in the memory
location 8503 H and 8504H. Consider program is written from memory location 8000H.
Algorithm:
st
 Initialize the memory location of 1 data in HL register pair.
 Store first data in the memory location
 Increment the content of HL register pair for entering next data in the next memory
location
 Store second data in the memory location
 Move second number in accumulator
 Decrease the content of HL register pair
 Add the content of memory (first data) with accumulator
 Store the results in memory location 8503H and 8504H.
Flow chart:

23
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
Address of first number
8000 21 LXI H, 8501 H
in H-L register pair.
Lower byte data is stored
8001 01
in memory
Higher byte data is stored
8002 85
in memory
Sum of msb’s & register
8003 0E MVI C,00H
value in 00h
8004 00
Transfer first number in
8005 7E MOV A,M
accumulator.
Increment content of H-L
8006 23 INX H
register pair
Add first number and
8007 86 ADD M
second number
Jump if no carry to
8008 D2 JNC 800CH
800Ch location
Lower byte data is stored
8009 0C
in memory
Higher byte data is stored
800A 80
in memory
800B 0C INR C Increment register C
Data of accumulator is
800C 32 AHEAD STA 8503H
stored into 8503h address
Lower byte data is stored
800D 03
in memory
Higher byte data is stored
800E 85
in memory
800F 79 MOV A,C MSB’S of sum in A
MSB’S of sum in A is
8010 32 STA 8504H transferred to 8504h
location
Lower byte data is stored
8011 04
in memory
Higher byte data is stored
8012 85
in memory
8013 EF RST.5 Terminate program

24
Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8501 34H 8503 5AH
8502 26H 8504 00H

Viva-Voice Questions:
1. What is the function of JNC instruction?
2. What is the difference between conditional and unconditional jump instruction?
3. What is the function of STA 2500$ instruction?
4. What is multi byte?

25
PROGRAM NO. 4

DECIMAL ADDITION OF TWO 8 BIT NUMBERS AND SUM IS 16-BIT


Aim: Program for Decimal Addition of Two 8-Bit Numbers and Sum is 16 Bit.
Apparatus required: 8085 Microprocessor Kit, +5V Power supply, keyboard
Theory:
Two decimal numbers are stored in 8501H and 8502H. The result is to be stored in
8503H location. Consider program starts from memory location 8000H
Algorithm:
 Initialize the memory location of first number in HL register pair.
 Load the first number in accumulator
 Increment the content of HL register pair to initialize the memory location of second data
 Addition of the content of second memory location with first data
 Decimal adjustment of result
 Store the result in memory location 8002H

26
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
Address of first number
8000 21 LXI H, 8501 H
in H-L register pair.
Lower byte data is stored
8001 01
in memory
Higher byte data is stored
8002 85
in memory
Sum of msb’s & register
8003 0E MVI C,00H
value in 00h
8004 00
Transfer first number in
8005 7E MOV A,M
accumulator.
Increment content of H-L
8006 23 INX H
register pair
Add first number and
8007 86 ADD M
second number
8008 27 DAA
Jump if no carry to
8009 D2 JNC 800CH
800Ch location
Lower byte data is stored
800A 0C
in memory
Higher byte data is stored
800B 80
in memory
800C 0C INR C Increment register C
Data of accumulator is
800D 32 AHEAD STA 8503H
stored into 8503h address
Lower byte data is stored
800E 03
in memory
Higher byte data is stored
800F 85
in memory
8010 79 MOV A,C MSB’S of sum in A
MSB’S of sum in A is
8011 32 STA 8504H transferred to 8504h
location
Lower byte data is stored
8012 04
in memory
Higher byte data is stored
8013 85
in memory
EF RST.5 Terminate program

27
Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8501 34H 8503 5AH
8502 26H 8504 00H

Viva-Voice Questions:
1. What is the function of DAA instruction?
2. What is the difference between the MOV & MVI opcodes?
3. What is the function of JNC instruction?

28
PROGRAM NO. 5

DECIMAL SUBTRACTION OF TWO 8 BIT NUMBERS


Aim: Program for Decimal Subtraction of Two 8-Bit Numbers
Apparatus required: 8085 Microprocessor Kit, +5V Power supply, keyboard
Theory:
Two decimal numbers are stored in 8501H and 8502H. The result is to be stored in
8503H location. Consider program starts from memory location 8000H
Algorithm:
 Initialize the memory location of first number in HL register pair.
 Load the 99h number in accumulator
 Perform 9’s complement of the first number
 Increment the content in Accumulator to perform 10’s complement
 decrement the content of HL register pair to initialize the memory location of second data
 Addition of the content of second memory location with first data
 Decimal adjustment of result
 Store the result in memory location 8503H

Viva-Voice Questions:
1. What is the function of DAA instruction?
2. What is the difference between the MOV & MVI opcodes?
3. What is the function of JNC instruction?

29
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
Address of first number
8000 21 LXI H, 8501 H
in H-L register pair.
Lower byte data is stored
8001 01
in memory
Higher byte data is stored
8002 85
in memory
Copy immediate data 99
8003 3E MVI A,99H
in A
8004 99
8005 96 SUB M 9’s complement
Increment content of A
8006 3C INR A
register
Decrement content of H-
8007 2B DCX H
L register pair
Addition of
8008 86 ADD M complemented data and
the second number
Decimal Accumulator
8009 27 DAA
Adjust
Data of accumulator is
800A 32 STA 8503H
stored into 8503h address
800B 03
800C 85
800D EF RST.5 Terminate program

Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8501 34H 8503 5AH
8502 26H 8504 00H

30
PROGRAM NO. 6

ADDITION OF TWO 16-BIT NUMBERS


Aim: Program for addition of two 16-bit numbers.
Apparatus required: 8085 Microprocessor Kit, +5V Power supply, keyboard
Theory:
Consider the first 16-bit number 02H & 03H is stored in memory location 8501H &
8502h, the second 16-bit number 05H & 04H is stored in memory location 8503H &
8504h.The result after addition of two numbers is to be stored in the memory location
8505 H(LSB’s sum) & 8506H(MSB’s sum). Assume program starts from memory
location 8000H.
Algorithm:
 Start the program by loading HL register pair with address of 1st number.
 Copy the data to DE register pair.
 Load the second number to HL pair.
 Add the two register pair contents and check for carry.
 Store the value of sum and carry in memory locations.
 Terminate the program.
Flow chart:

31
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
Get first 16-bit number in
8000 2A LHLD 8501 H
HL
Lower byte data is stored
8001 01
in memory
Higher byte data is stored
8002 85
in memory
Save first 16-bit number
8003 EB XCHG
in de
Get second 16-bit
8004 2A LHLD 8503 H
number in HL
Lower byte data is stored
8005 03
in memory
Higher byte data is stored
8006 85
in memory
Get lower byte of the
8007 7B MOV A,E
first number
Add lower byte of the
8008 95 ADD L second number

Store the result in l


8009 6F MOV L,A
register
Get higher byte of the
800A 7A MOV A,D
first number
Add higher byte of
800B 9C ADD H
second number
Store l6-bit result in
800C 67 MOV H,A
memory locations
Store l6-bit result in
800D 22 SHLD 8505H
memory locations
800E 05

800F 85

8010 76 HLT Terminate program

32
Result:
INPUT DATA RESULT
Memory location Data Memory Data
location
8501 02H 8505 07H
8502 03H 8506 07H
8503 05H
8504 04H

Viva-Voice Questions:

1. What is the function of LHLD 8501H instruction?

2. How you can store a data in a memory location?

3. How you can read a data from a memory location?

4. What are flags available in 8085?

5. What is the function of HLT key of a 8085 microprocessor kit

33
PROGRAM NO. 7

SUBTRACTION OF TWO 16
16-BIT NUMBERS
Aim: Program for Subtraction of two 16
16-bit numbers.
Apparatus required: 8085 Microprocessor Kit
Kit, +5V Power supply, keyboard
Theory:
Consider the first 16-bit
bit number 09H & 05H is stored in memory location 8501H
8 &
8502h, the second 16-bit
bit number 05H & 04H is stored in memory location 8503H
8 &
8504h.The result after Subtraction of two numbers is to be stored in the memory location
8505 H(LSB’s difference
difference) & 8506H(MSB’s difference).. Assume program
progra starts from
memory location 8000H.
Algorithm:
 Start the program by loading HL register pair with address of 1st number.
 Copy the data to DE register pair.
 Load the second number to HL pair.
 Subtract the two register pair contents and check for carry.
 Store the value of difference and borrow in memory locations.
 Terminate the program.
Flow chart:

34
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
Get first 16-bit number in
8000 2A LHLD 8501 H
HL
Lower byte data is stored
8001 01
in memory
Higher byte data is stored
8002 85
in memory
Save first 16-bit number
8003 EB XCHG
in de
Get second 16-bit
8004 2A LHLD 8503 H
number in HL
Lower byte data is stored
8005 03
in memory
Higher byte data is stored
8006 85
in memory
Get lower byte of the
8007 7B MOV A,E
first number
Subtract lower byte of
8008 95 SUB L the second number

Store the result in l


8009 6F MOV L,A
register
Get higher byte of the
800A 7A MOV A,D
first number
Subtract higher byte of
800B 9C SBB H second number with
borrow
Store l6-bit result in
800C 67 MOV H,A
memory locations
Store l6-bit result in
800D 22 SHLD 8505H
memory locations
800E 05
800F 85
8010 76 HLT Terminate program

35
Result:
INPUT DATA RESULT
Memory location Data Memory Data
location
8501 09H 8505 04H
8502 05H 8506 01H
8503 05H
8504 04H

Viva-Voice Questions:

1. What is the function of LXI H, 8000 H instruction?

2. How you can store a data in a memory location?

3. How you can read a data from a memory location?

4. What are flags available in 8085?

5. What is the function of RESET key of a 8085 microprocessor kit

36
PROGRAM NO. 8

ONE’S COMPLEMENT OF AN 8-BIT NUMBER


Aim: program for one’s complement of an 8-bit numbers
Apparatus required: 8085 Microprocessor Kit, +5V Power supply, keyboard
Theory:
The number is stored in memory location 8100H and one’s complement of number will
be stored in location 8101H. Assume the program memory starts from 8000H.
Algorithm:
 Load memory location of data 8100H in H-L registers pair.
 Move data into accumulator
 Complement accumulator
 Store the result in memory location 8101H
Flow chart:

37
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
Load Address Of
8000 3A LDA 8100 H Number In H-L Register
Pair
Lower Byte Data Is
8001 00
Stored In Memory
8002 81
Complement
8003 2F CMA
Accumulator
8004 32 STA 8101H Store The Result

8005 01

8006 81

8007 76 HLT Terminate Program

Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8100 03 8101 FC

Viva-Voice Questions:
1. What is the function of LDA instruction?
2. What is the function of CMA?
3. What is the function of STA?

38
PROGRAM NO. 9

2’S COMPLEMENT OF AN 8-BIT NUMBER


Aim: program for 2’s complement of an 8-bit numbers
Apparatus required: 8085 Microprocessor Kit, +5V Power supply, keyboard
Theory:
The number is stored in memory location 8100H and 2’s complement of number will be
stored in location 8101H. Assume the program memory starts from 8000H.
Algorithm:
 Load memory location of data 8100H in H-L registers pair.
 Move data into accumulator
 Complement accumulator
 Store the result in memory location 8101H
Flow chart:

39
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
Load Address Of
8000 3A LDA 8100 H Number In H-L Register
Pair
Lower Byte Data Is
8001 00
Stored In Memory
8002 81
Complement
8003 2F CMA
Accumulator
8004 3C INR A Increment

8005 32 STA 8101H Store The Result

8006 01

8007 81

8008 76 HLT Terminate Program

Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8100 02 8101 FE

Viva-Voice Questions:
1. What is the function of LDA instruction?
2. What is the function of CMA?
3. What is the function of STA?
4. Explain the working of 2’s complement
5. What is the function of INR & INX opcodes?

40
PROGRAM NO. 10

ONE’S COMPLEMENT OF A 16-BIT NUMBER


Aim: program for one’s complement of a 16-bit numbers
Apparatus required: 8085 Microprocessor Kit, +5V Power supply, keyboard
Theory:
The number is stored in memory location 8100H and one’s complement of number will
be stored in location 8103H. Assume the program memory starts from 8000H.
Algorithm:
 Load memory location of data 8100H in H-L registers pair.
 Move lower data into accumulator
 Complement accumulator
 Store the result in memory location 8102H
 Increment H-L registers pair.
 Move higher data into accumulator
 Complement accumulator
 Store the result in memory location 8103H
Flow chart:

41
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
Load Address Of
8000 3A LDA 8100 H Number In H-L Register
Pair
8001 00

8002 81
Move The Number Into
8003 7E MOV A,M
Accumulator
Complement
8004 2F CMA
Accumulator
8005 32 STA 8102H Store The Result

8006 02

8007 81

8008 23 INX H Increment HL Reg.Pair


Move The Number Into
8009 7E MOV A,M
Accumulator
Complement
800A 2F CMA
Accumulator
800B 32 STA 8103H Store The Result

800C 03

800D 81

800E 76 HLT Terminate

Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8100 11 8102 6E
8101 11 8103 EE

42
PROGRAM NO. 11

2’S COMPLEMENT OF AN 16-BIT NUMBER


Aim: program for 2’s complement of an 8-bit numbers
Apparatus required: 8085 Microprocessor Kit, +5V Power supply, keyboard
Theory:
The number is stored in memory location 8100H and 2’s complement of number will be
stored in location 8103H. Assume the program memory starts from 8000H.
Algorithm:
 Load memory location of data 8100H in H-L registers pair.
 Move data into accumulator
 Complement accumulator
 Store the result in memory location 8101H
Flow chart:

43
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
8000 3A LDA 8100 H Load Accumulator
8001 00
8002 81
Move The Number Into
8003 7E MOV A,M
Accumulator
Complement
8004 2F CMA
Accumulator
8005 3C INR A Increment Accumulator
8006 32 STA 8102H Store The Result
8007 02
8008 81
8009 23 INX H Increment HL Reg.Pair
Move The Number Into
800A 7E MOV A,M
Accumulator
Complement
800B 2F CMA
Accumulator
800C 3C INR A Increment Accumulator
800D 32 STA 8103H Store The Result
800E 03
800F 81
8010 76 HLT Terminate

Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8100 19 8102 E7
8101 23 8103 DD

44
PROGRAM NO. 12

EXCHANGE CONTENTS OF MEMORY LOCATIONS


Aim: program for exchanging contents of memory locations
Apparatus required: 8085 Microprocessor Kit, +5V Power supply, keyboard
Theory:
The first number is stored in memory location 8501H and second number will be stored
in location 8502H. The two memory locations will exchange the data. Assume the
program memory starts from 8000H.
Algorithm:
 Load memory location of data 8501H in accumulator.
 Move data of accumulator into B register
 Load memory location of data 8502H in accumulator.
 Store the contents of accumulator at address 8501H
 Move data of B register into accumulator
 Store the contents of accumulator at address 8502H

Flow chart:
START

Load Data into


Accumulator

Copy Data from


A to B Register

Store Data

Copy Data from


B to A Register

Store Data

STOP
45
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
8000 3A LDA 8501 H Load Accumulator
8001 01
8002 85
Move Accumulator Data
8003 47 MOV B,A
Into A
8004 3A LDA 8502 H Load Accumulator
8005 02
8006 85
8007 32
8008 01
8009 85
Move Data Into
800A 78 MOV A, B
Accumulator
800B 32 STA 8502H Store The Result
800C 02
800D 85
800E 76 HLT

Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8501 12 8501 13
8502 13 8502 12

Viva-Voice Questions:
1. Write A Simple Code To Exchange Data Using XCHG Opcode
2. Difference between LDA & STA opcodes

46
PROGRAM NO. 13

MULTIPLICATION OF TWO 8-BIT NUMBERS


Aim: program to perform 8-bit multiplication of two 8-bit data and store the result in memory.
Apparatus required: 8085 Microprocessor Kit, +5V Power supply, keyboard
Theory:
The HL register pair is first initialized to the start address of memory at which the data is
stored. Then data is brought to accumulator A and the other one is multiplied from
memory itself. The result from A is then stored into memory again using the HL register.
Algorithm:
 Load Accumulator.
 Move the data to a register (E register).
 Get the second data and load into Accumulator.
 Add the two register contents
 Check for carry.
 Increment the value of carry.
 Check whether repeated addition is over and store the value of product and carry in
memory location.
 Terminate the program.
Flow chart:

47
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
8000 3A LDA 8500 H Load Accumulator
8001 00
8002 85
Move Accumulator into
8003 5F MOV E, A
E
8004 3A LDA 8501 H Load Accumulator
8005 01
8006 85
Move Accumulator into
8007 4F MOV C, A
C
8008 21 LXI H,0000H Load Data Into HL
8009
800A
Data Of D Register Pair
800B 19 DAD D
With HL Register Pair
800C 0D DCR C Decrement C register
800D C2 JNZ
800E 0B
800F 80
Store HL Register Pair
8010 22 SHLD 8600H Data Into Memory
Location
8011 00
8012 86
8013 76 HLT Terminate

48
Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8500 03 8600 03
8501 01

Viva-Voice Questions:
1. Explain the opcode DAD
2. What is the operands of DAD opcode
3. Explain the SHLD opcode

49
PROGRAM NO. 14
ADDITION OF 5 NUMBERS IN ARRAY
Aim: program to perform addition of 5 numbers in array.
Apparatus required: 8085 Microprocessor Kit, +5V Power supply, keyboard
Theory:
The counter is set for 5 values. The HL register pair is loaded with the 5 numbers
simultaneously by incrementing the HL register pair and decrementing the counter till
zero. The result is stored in the last memory address. Assume that program starts at
8000h address location.
Algorithm:
 C register is used as counter and loaded with 05h and accumulator with 00h numbers.
 Load HL register pair with 8200h
 The accumulator 00h value and the first number is added and stored in A
 HL register pair is incremented and the counter is decremented till counter =00h
 The result is stored in memory
Flow chart:

50
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
8000 0E MVI C,05H Counter Set to 05h
8001 05
8002 3E MVI A,00H Accumulator Set to 00h
8003 00
Load HL register pair
8004 LXI H,8200H
with immediate data
8005 00
8006 82
8007 86 BACK ADD M Add to memory
Increment HL Register
8008 23 INX H
Pair
8009 0D DCR C Decrement Counter
800A C2 JNZ BACK Jump if no zero
800B 07
800C 80
Copy Data Of A To
800D 77 MOV M,A
Memory
800E 76 HLT Halt

Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8200 05
8201 10
8202 15 8205 75
8203 20
8204 25
Viva Questions:
1. What is the function of JNZ opcode
2. Difference between HALT and RST instructions

51
PROGRAM NO. 15
LARGEST BETWEEN TWO NUMBERS
Aim: Program to find largest between two numbers.
Apparatus required: 8085 Microprocessor Kit, +5V Power supply, keyboard
Theory:
The first number is stored in 8200h and the HL reg.pair is incremented and the second
number is compared with the first. Depending on the sign flag (if positive) first number is
stored in memory.
Algorithm:
 Load HL register pair with 8200h
 Copy first number into A.
 HL register pair is incremented.
 First and second number are compared and result is stored in memory
Flow chart:

52
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
Load data into HL
8000 21 LXI H, 8200 H
register pair
8001 00
8002 82
8003 7E MOV A, M Copy data into A
Increment HL register
8004 D3 INX H
pair
8005 BE CMP M Compare
8006 F2 JP 800AH Jump on Plus
8007 0A
8008 80
8009 7E MOV A, M Copy data into A
Store The Result In
800A 32 STA 8400H
Memory
800B 00
800C 84
800D 76 HLT Halt

Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8200 03 8400 03
8201 01

Viva-Voice Questions:
1. Explain the 8085 FLAGS.
2. Explain the instruction JP.
3. Explain about CMP instruction.

53
PROGRAM NO. 16
SMALLEST BETWEEN TWO NUMBERS
Aim: Program to find smallest between two numbers.
Apparatus required: 8085 Microprocessor Kit, +5V Power supply, keyboard
Theory:
The first number is stored in 8200h and the HL reg.pair is incremented and the second
number is compared with the first. Depending on the sign flag number is stored in
memory.
Algorithm:
 Load HL register pair with 8200h
 Copy first number into A.
 HL register pair is incremented.
 First and second number are compared and result is stored in memory
Flow chart:

54
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
Load data into HL
8000 21 LXI H, 8200 H
register pair
8001 00
8002 82
8003 7E MOV A, M Copy data into A
Increment HL register
8004 D3 INX H
pair
8005 BE CMP M Compare
8006 F2 JM 800AH Jump on Minus
8007 0A
8008 80
8009 7E MOV A, M Copy data into A
Store The Result In
800A 32 FW STA 8400H
Memory
800B 00
800C 84
800D 76 HLT Halt

Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8200 01 8400 01
8201 03

Viva-Voice Questions:
1. Explain the 8085 FLAGS.
2. Explain the instruction JM.
3. Explain about CMP instruction.

55
PROGRAM NO. 17
MULTIPLYING A NUMBER BY 2
Aim: Program to Perform Multiplication.
Apparatus required: 8085 Microprocessor Kit, +5V Power supply, keyboard
Theory:
The number is stored in accumulator and rotated left is performed and the result is stored
in memory.
Algorithm:
 Load A with 8200h.
 The Number Is Rotated Left
 Result Is Stored In Memory
Flow chart:

START

LOAD NUMBER
INTO
ACCUMULATOR

ROTATE LEFT

STORE
RESULT
FROM A TO
MEMORY

STOP

56
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
8000 3A LDA 8200H Load Accumulator
8001 00
8002 82
8003 07 RLC Rotate Left
Store The Result In
8004 32 STA 8400H
Memory
8005 00
8006 84
8007 76 HLT Halt

Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8200 06 8400 0C

Viva-Voice Questions:
1. Explain rotate left with example.
2. Differentiate different rotate operations.

57
PROGRAM NO. 18
MULTIPLYING A NUMBER BY 4
Aim: Program to Perform Multiplication.
Apparatus required: 8085 Microprocessor Kit, +5V Power supply, keyboard
Theory:
The number is stored in accumulator and rotate left is performed twice and the result is
stored in memory.
Algorithm:
 Load A with 8200h.
 The Number Is Rotated Left twice.
 Result Is Stored In Memory
Flow chart:

START

LOAD NUMBER
INTO
ACCUMULATOR

ROTATE LEFT

STORE
RESULT
FROM A TO
MEMORY

STOP

58
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
8000 3A LDA 8200H Load Accumulator
8001 00
8002 82
8003 07 RLC Rotate Left
8004 07 RLC Rotate Left
Store The Result In
8005 32 STA 8400H
Memory
8006 00
8007 84
8008 76 HLT Halt

Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8200 02 8400 08

Viva-Voice Questions:
1. Explain rotate left with example.
2. Differentiate different rotate operations.

59
PROGRAM NO. 19
DIVIDING A NUMBER BY 2
Aim: Program to Perform Division.
Apparatus required: 8085 Microprocessor Kit, +5V Power supply, keyboard
Theory:
The number is stored in accumulator and rotate right is performed and the result is stored
in memory.
Algorithm:
 Load A with 8200h.
 The Number Is Rotate right
 Result Is Stored In Memory
Flow chart:

START

LOAD NUMBER
INTO
ACCUMULATOR

ROTATE RIGHT

STORE
RESULT
FROM A TO
MEMORY

STOP

60
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
8000 3A LDA 8200H Load Accumulator
8001 00
8002 82
8003 07 RRC Rotate Right
Store The Result In
8004 32 STA 8201H
Memory
8005 00
8006 84
8007 76 HLT Halt

Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8200 03 8201 FC

Viva-Voice Questions:
1. Explain rotate right with example.
2. Differentiate different rotate operations.

61
PROGRAM NO. 20
FIND ODD OR EVEN NUMBER
Aim: Program to find even or odd number.
Apparatus required: 8085 Microprocessor Kit, +5V Power supply, keyboard
Theory:
The number is stored in accumulator and rotated right is performed. If the number is even
EE is printed and if the number is odd 00 is printed.
Algorithm:
 Store the input data bytes in consecutive memory locations.
 Rotate right.
 Fetch each data byte and check it D0 bit.
 If D0 bit=0 then even, else odd.
 Store odd in memory locations. Store even in some other consecutive memory location.
Flow chart:

START

LOAD NUMBER
INTO
ACCUMULATOR

ROTATE right and


if even print EEH
and if odd print 00h

STORE
RESULT
FROM A TO
MEMORY

STOP

62
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
8000 3A LDA 8200H Load Accumulator
8001 00
8002 82
8003 07 RRC Rotate Right
8004 32 MVI A,00H Print 00 if odd
8005 00
8006 0A JC FN Jump on carry
8007 0B
8008 80
8009 3E MVI A,EEH Print EE if EVEN
800A EE
Store The Result In
800B 32 FN STA 8400H
Memory
800C 00
800D 84
800E 76 HLT Halt

Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8200 03 8400 00

Viva-Voice Questions:
1. Explain the load operations.
2. Explain jump instructions.
3. Explain store operations.

63
PROGRAM NO. 21

DIVISION OF TWO 8-BIT NUMBERS


Aim: program to perform division of two 8-bit data and store the result in memory.
Apparatus required: 8085 Microprocessor Kit, +5V Power supply, keyboard
Theory:
The HL register pair is first initialized to the start address of memory at which the data is
stored. Then data is brought to accumulator A. DAD & subtraction is used to perform
division. The result from A is then stored into memory again using the HL register.
Algorithm:
 Start the program by loading HL register pair with address of memory location.
 Move the data to a register (B register).
 Get the second data and load into Accumulator.
 Compare the two numbers to check for carry.
 Subtract the two numbers.
 Increment the value of carry.
 Check whether repeated subtraction is over and store the value of product and carry in
memory location.
 Terminate the program.

64
Flow chart:

65
Program:
Machine
Memory
Codes Labels Mnemonics Operands Comments
Address
(Data)
8000 2A LHLD 8501H Load into HL
8001 01
8002 85
8003 3A LDA 8503 H Load Accumulator
8004 03
8005 85
Move Accumulator into
8006 47 MOV B, A
B
8007 0E MVI C,08H Initialize Counter
8008 08
Data Of D Register Pair
8009 29 LOOP DAD D
With HL Register Pair
800A 7C MOV A,H Move H data into A
800B 90 SUB B Subtract B
800C 0A JC AHEAD Jump on carry
800D 11
800E 80
800F 67 MOV H,A Move A data into H
8010 2C INR L Increment L
8011 0D DCR C Decrement C
8012 C2 JNZ LOOP Jump on no zero
8013 09
8014 80
8015 22 SHLD 8504H Store Result
8016 04
8017 85
8018 EF HLT Terminate

66
Result:
INPUT DATA RESULT
Memory location Data Memory location Data
8501 54 8504 09
8502 00 8505 03
8503 09

Viva-Voice Questions:
1. Explain Branch Instructions.
2. Explain jump instructions.
3. Explain DAD instruction.

67
PROGRAM NO. 22

TRAFFIC LIGHT INTERFACE


Aim: Program for Interfacing Traffic Light Controller with 8085 Microprocessor trainer kit and
simulating the sequence of traffic light states.
Apparatus Required: 8085 Microprocessor Kit, +5v Power Supply, Keyboard, Traffic Light
Controller, Flat Ribbon Cable.
Theory:
Combination of Red, Amber and Green LEDs are provided to indicate Halt, Wait and Go
states for vehicles. Combination of Red and Green LEDs are provided for pedestrian
crossing. 36 LEDs are arranged in the form of an intersection. At the left corner of each
road, a group of 5 LEDs (Red, Amber and Green) are arranged in the form of a T section
to control the traffic of that road. Each road is named as North N, South S, East E and
West W. L1,L10, L19 and L28 (Red) are for stop signal for the vehicles on the road
N,S,W and E respectively. L2, L11, L20 and L29 (Amber) indicate wait state for the
vehicles on the road N, S, E and W respectively.
L3, L4 and L5 (Green) are for left, straight and right turn for the vehicles on the road S.
Similarly L12 - L13 - L14, L23 - L22 - L21 and L32 - L31 - L30 simulates same function
for the Roads E, N & W respectively. A total of 16 LEDs (2 Red & 2 Green at each road)
are provided for pedestrian crossing. L7 - L9, L16 - L18, L25 - L27 & L34 - L36 (Green)
when on allows pedestrians to cross and L6 - L8, L15 - L17, L24 - L26 & L33 - L35
(Red) when on alarms the pedestrians to wait. To minimize the hardware pedestrians
indicator LEDs (both Green and Red) are connected to some port lines (PC4 to PC7) with
Red inverted. Red LED’s L10 and L28 are connected to port lines PC2 to PC3 while L1
and L19 are connected to lines PC0 and PC1 after inversion. All other LEDs (Amber and
Green) are connected to Port A and port B.

68
69
Program:

70
CYCLE-2
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
www.foxitsoftware.com/shopping

Introduction to MASM
The Microsoft macro assembler is an x86 high level assembler for DOS and Microsoft
windows. It supports wide varieties of macro facilities and structured programming
idioms including high level functions for looping and procedures
A program called assembler used to convert the mnemonics of instructions along with
the data into the equivalent object code modules, these object code may further
converted into executable code using linked and loader programs. This type of program
is called as ASSEMBLY LANGUAGE PROGRAMMING. The assembler converts and
Assembly language source file to machine code the binary equivalent of the assembly
language program. In this respect, the assembler reads an ASCII source file from the
disk and program as output. The major different between compilers for a high level
language like PASCAL and an Assembler is that the compiler usually emits several
machine instructions for each PASCAL statement. The assembler generally emits a
single machine instruction for each assembler language statement.
Attempting to write a program in machine language is not particularly bright. This
process is very tedious, mistakes, and offers almost no advantages over programming in
assembly language. The major disadvantages over programming in assembly language
over pure machine code are that you must first assemble and link a program before you
can execute it. However attempting to assemble the code by hand would take for longer
than the small amount of time that the assembler takes the perform conversion for you.
An assembler like Microsoft Macro Assembler (MASM) provides a large number of
features for assembly language programmers. Although learning about these features
take a fair amount of time. They are so useful that it is well worth the effort.

Microsoft MASM version 6.11 contains updated software capable of processing


printing instructions. Machine codes and instruction cycle counts are generated by
MASM for all instructions on each processor beginning with 8086. To assemble the
file PROG.ASM use this command: (better to use DOS command line)

MASM PROG.ASM
The MASM program will assemble the PROG.ASM file. (To create PROG.OBJ
from PROG.ASM)

To create PROG.EXE from PROG.OBJ, use this LINK command:


LINK PROG.OBJ
It converts the contents of PROG.OBJ into PROG.EXE.

To link more than one object file use + signs between their file names as in:
LINK PROGA+PROGB+PROGC

71
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
www.foxitsoftware.com/shopping

The following is a list of MASM reserved words:

ASSUME assume definition


CODE begin code segment
DATA begin data segment DB define byte
DD define double word
DQ define quad word
DS define storage
DUP duplicate
DW define word
ELSE else statement
END end program
ENDM end macro
ENDIF end if statement
ENDP end procedure
ENDS end segment
EQU equate
IF if statement
FAR far reference
MACRO define macro
.MODEL model type
NEAR near reference
OFFSET offset
ORQ origin
PARA paragraph
PROC define procedure
.EXIT generate exit code
PUBLIC public reference
SEG locate segment
SEGMENT define segment
PTR pointer

USING DEBUG TO EXECUTE THE 80x86 PROGRAM:


DEBUG is a utility program that allows a user to load an 80x 86 programs into memory and execute it
step by step. DEBUG displays the contents of all processor registers after each instruction execute,
allowing the user to determine if the code is performing the desired task. DEBUG only displays the 16-
bit portion of the general purpose registers. Code view is capable of displaying the entire 32 bits.
DEBUG is a very useful debugging tool. We will use DEBUG to step through a number of simple
programs, gaining familiarity with Debug’s commands as we do so. DEBUG contains commands that
can display and modify memory, assemble instructions, disassemble code already placed into memory,
trace single or multiple instructions, load registers with data and do much more.

72
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
DEBUG loads into memory like any other program, in the first available slot. The memory space used by
www.foxitsoftware.com/shopping

DEBUG for the user program begins after the end of Debug’s code. If an .EXE or .COM file were
specified, DEBUG would load the program according to accepted DOS conventions.

To execute the program file PROG.EXE use this command


DEBUG PROG.EXE

DEBUG uses a minus sign as its command prompt, so should see a “-“ appear on display.

To get a list of some commands available with DEBUG is :


T -- trace (step by step execution)
U -- un assemble
D -- dump
G -- go (complete execution)
H -- Hex

To execute the program file PROG.ASM use the following procedure:


.MASM PROG.ASM
.LINK PROG.OBJ
.DEBUG PROG.EXE

ASSEMBLER DIRECTIVES: The limits are given to the assembler using some pre defined alphabetical
strings called Assembler Directives which help assembler to correctly understand. The assembly
language programs to prepare the codes.

DB GROUP EXTRN
DW LABEL TYPE
DQ LENGTH EVEN
DT LOCAL SEGMENT
ASSUME NAME
END OFFSET
ENDP ORG
ENDS PROC
EQU PTR
73
DB-Define Byte: The DB drive is used to reserve byte of memory locations in the available on memory.
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
www.foxitsoftware.com/shopping

USING DEBUG TO EXECUTE THE 80x86 PROGRAM:


DEBUG is a utility program that allows a user to load an 80x 86 programs into memory and execute
it step by step. DEBUG displays the contents of all processor registers after each instruction execute,
allowing the user to determine if the code is performing the desired task. DEBUG only displays the
16-bit portion of the general purpose registers. Code view is capable of displaying the entire 32 bits.
DEBUG is a very useful debugging tool. We will use DEBUG to step through a number of simple
programs, gaining familiarity with Debug’s commands as we do so. DEBUG contains commands
that can display and modify memory, assemble instructions, disassemble code already placed into
memory, trace single or multiple instructions, load registers with data and do much more.

DEBUG loads into memory like any other program, in the first available slot. The memory space
used by DEBUG for the user program begins after the end of Debug’s code. If an .EXE or .COM file
were specified, DEBUG would load the program according to accepted DOS conventions.

To execute the program file PROG.EXE use this command


DEBUG PROG.EXE

DEBUG uses a minus sign as its command prompt, so should see a “-“ appear on display.
To get a list of some commands available with DEBUG is:
T -- trace (step by step execution)
U -- un assemble
D -- dump
G -- go (complete execution)
H -- Hex

To execute the program file PROG.ASM use the following procedure:


.MASM PROG.ASM
.LINK PROG.OBJ
.DEBUG PROG.EXE

74
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
www.foxitsoftware.com/shopping
ASSEMBLER DIRECTIVES: The limits are given to the assembler using some pre defined alphabet-
ical strings called Assembler Directives which help assembler to correctly understand. The assembly
language programs to prepare the codes.

DB GROUP EXTRN
DW LABEL TYPE
DQ LENGTH EVEN
DT LOCAL SEGMENT
ASSUME NAME
END OFFSET
ENDP ORG
ENDS PROC
EQU PTR

DB-Define Byte: The DB drive is used to reserve byte of memory locations in the available on
memory.

DW-Define Word: The DW drive is used to reserve 16 byte of memory location available on memory.

DQ-Define Quad Word (4 words): The DB directives is used to reserve 8 bytes of memory locations
in the memory available.

DT-Define Ten Byte: The DT directive is used to reserve 10 byte of memory locations in the available
memory.

ASSUME: Assume local segment name the Assume directive is used to inform the assembler. The
name of the logical segments to be assumed for different segment used in programs.

END: End of the program the END directive marks the end of an ALP.

ENDP: End of the procedure.

ENDS: End of the segment.

EQU: The directive is used to assign a label with a variable or symbol. The directive is just to reduce
recurrence of the numerical values or constants in the program.

OFFSET: Specifies offset address.

SEGMENT: The segment directive marks the starting of the logical segment.

EXECUTION OF ASSEMBLY LANGUAGE PROGRAMMING IN MASM SOFTWARE:


Assembly language programming has 4 steps.
1. Entering Program
2. Compile Program
3. Linking a Program
4. Debugging a Program

75
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
www.foxitsoftware.com/shopping

76
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
www.foxitsoftware.com/shopping

1. To implement assembly language program for addition of two 16-bit numbers.

PROGRAM:
DATA SEGMENT
N1 DW 0005H
N2 DW 0002H
RES DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA START: MOV AX,
DATA
MOV DS, AX
MOV AX, N1
MOV BX, N2
ADD AX, BX
MOV RES, AX
INT 21H
CODE ENDS
END START

RESULT:
AX = 0007h

2. To implement assembly language program for subtraction of two 16-bit numbers.

PROGRAM:
DATA SEGMENT
N1 DW 0005H
N2 DW 0003H
RES DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AX,N1
MOV BX,N2
SUB AX,BX
MOV RES,AX
INT 21H
CODE ENDS
END START

RESULT:
AX = 0002h

77
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
www.foxitsoftware.com/shopping

3. To implement ALP to find average of 8-bit numbers in array.

ALGORITHM:
1. Start.
2. Initialize counter = 10.
3. Initialize array pointer.
4. Sum = 0.
5. Get the array element pointed by array pointer.
6. Add array element in the Sum.
7. Increment array pointer decrement counter.
8. Repeat steps 4, 5 & 6 until counter = 0.
9. Display Sum.
10. Stop.

PROGRAM:
DATA SEGMENT
ARRAY DB 12H, 24H, 26H, 63H, 25H, 86H, 2FH, 33H, 10H, 35H
SUM DW 0
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA

START: MOV AX, DATA


MOV DS, AX
MOV CL, 10
XOR DI, DI
LEA BX, ARRAY
BACK: MOV AL, [BX+DI]
MOV AH, 00H
MOV SUM, AX
INC DI
DEC CL
JNZ BACK
INT 21
CODE ENDS
END START

RESULT:
AX = 0211h

78
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
4 implement ALP to find the maximum number in the array. www.foxitsoftware.com/shopping

ALGORITHM:
1. Start.
2. Initialize data segment.
3. Initialize the pointer.
4. Initialize counter = 0.
5. Initialize the array base pointer.
6. Get the maximum number.
7. Compare the number with maximum number.
8. If num> MAX, Max = num & increment pointer.
9. Decrement the counter.
10. If count = 0 stop or else repeat steps 6, 7, 8, 9.
11. Store maximum number.
12. Stop.
PROGRAM:
DATA SEGMENT
N DB 05H
LIST DB 12H,34H,41H,
10H,15H
DATA ENDS
CODE SEGMENT

ASSUME CS:CODE,DS:DATA
START:MOV AX,DATA
MOV DS,AX
MOV AX,0000H
LEA SI,LIST
MOV AL,[SI]
INC SI
MOV CL,N
DEC CL
BACK:
CMP AL,[SI]
JNC MAX
MOV AL,[SI]
MAX:
INC SI
DEC CL
JNZ BACK
INT 03H

CODE ENDS
END START

RESULT:
79
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
www.foxitsoftware.com/shopping
5. To implement ALP to search a number in an array.

PROGARM:
DATA SEGMENT
N DB 05H
LIST DB 12H,34H,41H,10H,15H
ITEM DB 34H
DATA ENDS CODE
SEGMENT

ASSUME CS: CODE, DS: DATA


START:
MOV DS,AX
MOV AX,0000H
LEA SI,LIST
MOV CL,05
MOV AL,[SI]
INC SI
BACK:
CMP AL,ITEM
JZ DISPLAY
MOV AL,[SI]
INC SI
DEC CL
JNZ BACK MOV AX,
0000H DISPLAY:
INT 03H
CODE ENDS
END START

80
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
www.foxitsoftware.com/shopping

6. program to perform multiplication of two 16bits numbers

DATA SEGMENT
N1 DW 0005H
N2 DW 0002H
RES1 DW ?
RES2 DW ?
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE, DS: DATA
START:
MOV AX,DATA
MOV DS,AX
MOV DX , 0000H
MOV AX ,N1
MOV BX, N2
MUL BX
MOV RES1 , AX
MOV RES2 , BX
INT 03H
CODE ENDS
END START
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
www.foxitsoftware.com/shopping

7. WRITE AN ALP TO PERFORM DIVISION OF TWO 16BIT NUMBERS USING 8086

DATA SEGMENT
N1 DW 4444H
N2 DW 2222H
RES1 DW ?
RES2 DW ?
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX,DATA
MOV DS,AX
MOV AX,N1
MOV DX,0000H
MOV BX,N2
DIV BX
MOV RES1,AX
MOV RES2,DX
INT 03H
CODE ENDS
END START
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
www.foxitsoftware.com/shopping

8. ADDITION OF (N numbers) USING 8086

DATA SEGMENT
ARRAY DB 12H,14H,21H,10H,15H
SUM DW 0
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX,DATA
MOV DS,AX
MOV CL,05H
XOR DI,DI
LEA BX,ARRAY
BACK:
MOV AL,[BX+DI]
MOV AH,00
ADD SUM,AX
MOV AX,SUM
INC DI
JNZ BACK
INT 03H
CODE ENDS
END START
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
www.foxitsoftware.com/shopping

9. WRITE AN ALP TO FIND SMALLEST OF (N numbers) USING 8086

DATA SEGMENT
N DB 05H
LIST DB 12H,34H,41H,10H,15H
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE , DS:DATA
START:
MOV AX,DATA
MOV DS,AX
MOV AX,0000H
LEA SI,LIST
MOV AL,[SI]
INC SI
MOV CL,N
DEC CL
BACK:
CMP AL,[SI]
JC MIN
MOV AL,[SI]
MAX:
INC SI
DEC CL
JNZ BACK
INT 03H
CODE ENDS
END START
Edited with the trial version of
Foxit Advanced PDF Editor
To remove this notice, visit:
www.foxitsoftware.com/shopping
10. program to perform ASCENDING SORT numbers

DATA SEGMENT
STRING1 DB 99H,12H,56H,45H,36H
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX,DATA
MOV DS,AX
MOV CH,04H

UP2:
MOV CL,04H
LEA SI,STRING1

UP1:
MOV AL,[SI]
MOV BL,[SI+1]
CMP AL,BL
JC DOWN
MOV DL,[SI+1]
XCHG [SI],DL
MOV [SI+1],DL
DOWN:
INC SI
DRC CL
JNZ UP1
DEC CH
JNZ UP2
INT 03
CODE ENDS
END START

You might also like