Program to Transfer block of N-bytes in reverse order from source to destination

Q. Write an 8085 program and draw a flowchart to Transfer block of N-bytes in reverse order from source to destination.(8085 Microprocessor Program)

Flowchart/Algorithm

 

Program

Address Mnemonics Operand Opcode Comments
2000 MVI C, 05H 0E Initialize reg. C to 05H, i.e. number of bytes.
2001 05
2002 LXI H, 3000H 21 Initialize H-L pair to source memory location.
2003 00
2004 30
2005 LXI D, 3504H 11 Initialize D-E pair to destination memory location.
2006 04
2007 35
2008 MOV A, M 7E Move the byte from source to accumulator.
2009 STAX D 12 Store the byte from the accumulator to the destination.
200A INX H 23 Increment the source pointer H-L pair.
200B DCX D 1B Decrement the destination pointer D-E pair.
200C DCR C 0D Decrement counter C.
200D JNZ 2008H C2 Jump to address 2008H if the counter is not zero.
200E 08
200F 20
2010 HLT 76 Halt

Output

Before Execution:

3000H: 05H
3001H: 02H
3002H: 04H
3003H: 03H
3004H: 02H

After Execution:

3500H: 02H
3501H: 03H
3502H: 04H
3503H: 02H
3504H: 05H

Program Explanation

  1. This program transfers a block of N-bytes in reverse order from source to destination. The source bytes start from memory location 3000H and needs to be transferred to memory locations 3504H in reverse order.
  2. In order to transfer these bytes, first, the counter must be initialized to the number of bytes to transfer.
  3. Then, H-L pair is initialized to point to the source memory location and D-E pair is initialized to point to destination memory location.
  4. The first byte is moved from source to accumulator and then from there to destination.
  5. The H-L pair is incremented and D-E pair is decremented to point to the next respective memory locations.
  6. The counter is decremented and checked whether it has become zero.
  7. If it hasn’t become zero, it means that there are bytes remaining to be transferred. In this case, the control jumps back to move the next byte from source to destination.
  8. This process continues until counter becomes zero, i.e. all the bytes have been transferred.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.