Here we will see how we transfer a block of data in reverse order using 8085.
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.
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.
|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|