Skip to content
Related Articles

Related Articles

Improve Article

8085 program to exchange a block of bytes in memory

  • Last Updated : 22 May, 2018

Problem – Write an assembly level program in 8085 microprocessor to exchange a block of 4 bytes staring from address 2001 with data starting from address 3001.

Algorithm –

  1. Take a count equal to 4
  2. Store the starting address of both blocks in 2 different register pairs
  3. Now exchange the contents at the addresses in both register pairs
  4. Increment the values of both register pairs
  5. Decrements count by 1
  6. If count is not equal to 0 repeat steps 3 to 5

MEMORY ADDRESSMNEMONICSCOMMENTS
2500LXI D 2001D <= 20, E <= 01
2503LXI H 3001H <= 20, L <= 01
2506MVI C 04C <= 04
2508MOV B, MB <= M[ H-L ]
2509LDAX DA <= M[ D-E ]
250AMOV M, AM[ H-L ] <= A
250BMOV A, BA <= B
250CSTAX DM[ D-E ] <= A
250DINX H[ H-L ] <= [ H-L ] + 1
250EINX D[ D-E ] <= [ D-E ] + 1
250FDCR CC <= C – 1
2510JNZ 2508JUMP TO 2508 IF C NOT EQUAL TO 0
2513HLTSTOP THE PROGRAM



Explanation –

  1. LXI D 2001 – Loads register pair, that is in this case, D=20 and E=01
    LXI H 3001 – H=30 and L=01
  2. MVI C 04 – Assigns immediate data, eg.- here C=04
    MVI A 45 – assigns A(accumulator) with 45, A=45
  3. MOV B, M – Here M is the data in H – L register pair and it serves as an address. Copies content at address stored in M to register B
  4. LDAX D – Here Accumulator is loaded with the data stored at address formed by register pair D – E
  5. MOV M, A – Here A’s content is copied to address which is stored in M.
    MOV A, B – Copies content of register B to A
  6. STAX D – Stores the content of A (accumulator) in the address formed by register pair D – E.
  7. INX H – Increment the content of register pair H – L
  8. INX H – Increment the content of register pair D – E
  9. DCR C – Decrements the content of register C
  10. JNZ 2508 – If value of register C is not equal to 0 then jump to address 2508
  11. HLT – Stop execution of program

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

 

My Personal Notes arrow_drop_up