8085 program to swap two 8 bit numbers using Direct addressing mode

MicrocontrollerMicroprocessor8085

In this program we will see how to swap two numbers in direct addressing mode.

Problem Statement

Write 8085 Assembly language program to swap two 8-bit number stored at location 8000H and 8001H using direct addressing mode. 

Discussion

In this case we are taking the number from memory by using the HL pair. The HL pair is storing the address of the data item. We are taking the first number into B register, and the second number to A register, then storing the content of B to the next position, and storing the value of A into first position.

Input

Address
Data
.
.
.
.
.
.
8000
CD
8001
34
.
.
.
.
.
.


Flow Diagram

Program

Address
HEX Codes
Mnemonics
Comments
F000
21, 00, 80
LXI H,8000H
Point to the first number
F003
46
MOV B,M
Load the first number to B
F004
23
INX H
Point to the next number
F005
7E
MOV A,M
Load the second number into A
F006
70
MOV M,B
Store first number to second position
F007
2B
DCX H
Point to previous location
F008
77
MOV M,A
Store second number to first position
F009
76
HLT
Terminate the program


Output

Address
Data
.
.
.
.
.
.
8000
34
8001
CD
.
.
.
.
.
.
raja
Published on 22-Jan-2019 15:27:40
Advertisements