8085 program to swap two 16-bit numbers using Direct addressing mode


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

Problem Statement

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

Discussion

Here we are swapping the values using XCHG instruction. This instruction swaps the contents of DE and HL pair contents. We are taking the first number into DE register pair, then the second number into HL pair, then by XCHG we are swapping them.

Input

Address
Data
.
.
.
.
.
.
8000
CD
8001
AB
8002
34
8003
12
.
.
.
.
.
.


Flow Diagram

Program

Address
HEX Codes
Mnemonics
Comments
F000
2A, 00, 80
LHLD 8000H
Load the first number into HL
F003
EB
XCHG
Exchange DE and HL
F004
2A, 02, 80
LHLD 8002H
Load the second number into DE
F007
22, 00, 80
SHLD 8000H
Store the second number at first position
F00A
EB
XCHG
Exchange the DE and HL
F00B
22, 02, 80
SHLD 8002H
Store the first number at second position
F00E
76
HLT
Terminate the program


Output

Address
Data
.
.
.
.
.
.
8000
34
8001
12
8002
CD
8003
AB
.
.
.
.
.
.

Updated on: 30-Jul-2019

743 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements