Home »
Embedded Systems
Swap Two 16-bit Numbers using Direct Addressing Mode
In this tutorial, we will learn how to swap two 16-bit numbers using direct addressing mode in 8085 Microprocessor?
By Akash Kumar Last updated : May 13, 2023
Swap Two 16-bit Numbers using Direct Addressing Mode in 8085 Microprocessor
Given two 16-bits numbers, we have to swap them using direct addressing mode in 8085 Microprocessor.
Algorithm
- Load the first 16bit number in HL pair register.
- Exchange the content of HL pair with DE register.
- Now load the second 16bit number in HL pair register.
- Exchange the content of HL pair register with DE register.
- Now store the content of HL pair at memory location of first number.
- Exchange the content of HL pair register with DE register.
- Now store the content of HL pair at memory location of second number.
- Terminate the program.
Program
LHLD 2050
XCHG
LHLD 2052
XCHG
SHLD 2050
XCHG
SHLD 2052
HLT
Observation
INPUT:
2050:07
2051:04
2052:05
2053:06
OUTPUT:
2050:05
2051:06
2052:07
2053:04
Hence we successfully swapped two 16 bits numbers using direct addressing mode on 8085 microprocessor.