Skip to content
Related Articles

Related Articles

Improve Article
8085 program to exchange content of HL register pair with DE register pair
  • Last Updated : 01 Jun, 2018

Problem – Write an assembly language program in 8085 microprocessor to exchange content of HL register pair with DE register pair using PUSH and POP instructions.

Example –

Assumption – Content is already present in HL and DE register.

Algorithm –



  1. Initialize stack pointer (SP) by 3FFF.
  2. Push the content of H and L register into the stack. Decrements SP by 2.
  3. Push the content of D and E register into the stack. Decrements SP by 2.
  4. Pop the upper two bytes from top of stack and place it in HL register. Increment SP by 2.
  5. Pop the remaining two bytes from top of stack and place it in DE register. Increment SP by 2.

Program –

MEMORY ADDRESSMNEMONICSCOMMENT
2000LXI SP 3FFFSP <- 3FFF
2003PUSH HSP <- SP – 1, M[SP] <- H, SP <- SP – 1, M[SP] <- L
2004PUSH DSP <- SP – 1, M[SP] <- D, SP <- SP – 1, M[SP] <- E
2005POP HL <- M[SP], SP <- SP + 1, H <- M[SP], SP <- SP + 1
2006POP DE <- M[SP], SP <- SP + 1, D <- M[SP], SP <- SP + 1
2007HLTENDT

Explanation – Registers used H, L, D, E:

  1. LXI SP 3FFF: initialize SP by 3FFF.
  2. PUSH H: push the content of H and L register into the stack and decrements stack pointer by 2.
  3. PUSH D: push the content of D and E register into the stack and decrements stack pointer by 2.
  4. POP H: pop the upper two bytes from top of stack and place it in HL register pair and increment SP by 2.
  5. POP D: pop the upper two bytes from top of stack and place it in DE register pair and increment SP by 2.
  6. HLT: stops executing the program and halts any further execution.

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
Recommended Articles
Page :