# 8085 program to transfer a block in reverse order

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.

Data

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

## Program

HEX Codes
Labels
Mnemonics
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
F007
7D

MOV A,L
F008
81

F009
6F

MOV L,A
Store A to L again
F00A
7E
LOOP
MOV A,M
F00B
12

STAX D
Store A into destination pointed by DE
F00C
13

INX D
F00D
2B

DCX H
F00E
0D

DCR C
Decrease C by 1
F00F
C2, 0A, F0

JNZ LOOP
F012
76

HLT
Terminate the program

Data

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