8085 program to swap two 8-bit numbers

MicrocontrollerMicroprocessor8085

In this program we will see how to swap two numbers.

Problem Statement

Write 8085 Assembly language program to swap two 8-bit number stored at location 8000Hand 8001H.

Discussion

In 8085, there is an instruction XCHG. Using this we can swap the contents of DE and HL values. We are taking the numbers and storing them into H and D, then using XCHG the contents are swapped.

Input

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


Flow Diagram

Program

Address
HEX Codes
Mnemonics
Comments
F000
3A, 00, 80
LDA 8000H
Load the first number into A
F003
67
MOV H, A
Store the number into H
F004
3A, 01, 80
LDA 8001H
Load the second number into A
F007
57
MOV D, A
Store the number into D
F008
EB
XCHG
Exchange DE and HL
F009
7C
MOV A, H
Take H content to A
F00A
32, 00, 80
STA 8000H
Store the first number after swap
F00D
7A
MOV A, D
Take D content to A
F00E
32, 01, 80
STA 8001H
Store the second number after swap
F011
76
HLT
Terminate the program


Output

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