8085 program to transfer a block in reverse order

MicroprocessorMicrocontroller8085

Here we will see how we transfer a block of data in reverse order using 8085.

Problem Statement

Write 8085 program to transfer a block of N-bytes in reverse order. The block is stored at location 8001 onwards, the size of the block is stored at 8000. The block will be moved at location 9000 onwards.

Discussion

To solve this problem, we are taking the size of the block at first. The DE register pair is set to point at destination address 9000H. The HL pair is set to point to the last element of the block. If the block size is 0A, then the last block will be at 800A. At first HL is pointing to 8000, and took the block size from there and store to C. Now add C with the L register to get the last block address. Now take each element from memory pointed by HL, and store it back to the memory pointed by the DE. Then increase the DE, and decrease the HL. Thus the entire block will be moved in reverse direction.

Input

Address
Data


8000
0A
8001
11
8002
22
8003
33
8004
44
8005
55
8006
66
8007
77
8008
88
8009
99
800A
AA


 

Flow Diagram

 

Program

Address
HEX Codes
Labels
Mnemonics
Comments
F000
21, 00, 80
 
LXI H,8000
Point to 8000 to get block size
F003
4E
 
MOV C,M
Take the block size into C
F004
11, 00 90
 
LXI D,9000
Point to the destination address
F007
7D
 
MOV A,L
Load L into A
F008
81
 
ADD C
Add C to point to last address of block
F009
6F
 
MOV L,A
Store A to L again
F00A
7E
LOOP
MOV A,M
Load memory to A
F00B
12
 
STAX D
Store A into destination pointed by DE
F00C
13
 
INX D
Point destination to next address
F00D
2B
 
DCX H
Point source to previous address
F00E
0D
 
DCR C
Decrease C by 1
F00F
C2, 0A, F0
 
JNZ LOOP
if Z is not set jump to LOOP
F012
76
 
HLT
Terminate the program

 

Output

Address
Data


9000
AA
9001
99
9002
88
9003
77
9004
66
9005
55
9006
44
9007
33
9008
22
9009
11


 

 

 

raja
Published on 17-Jun-2019 15:41:22
Advertisements