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.
Assumption – Content is already present in HL and DE register.
- Initialize stack pointer (SP) by 3FFF.
- Push the content of H and L register into the stack. Decrements SP by 2.
- Push the content of D and E register into the stack. Decrements SP by 2.
- Pop the upper two bytes from top of stack and place it in HL register. Increment SP by 2.
- Pop the remaining two bytes from top of stack and place it in DE register. Increment SP by 2.
|2000||LXI SP 3FFF||SP <- 3FFF|
|2003||PUSH H||SP <- SP – 1, M[SP] <- H, SP <- SP – 1, M[SP] <- L|
|2004||PUSH D||SP <- SP – 1, M[SP] <- D, SP <- SP – 1, M[SP] <- E|
|2005||POP H||L <- M[SP], SP <- SP + 1, H <- M[SP], SP <- SP + 1|
|2006||POP D||E <- M[SP], SP <- SP + 1, D <- M[SP], SP <- SP + 1|
Explanation – Registers used H, L, D, E:
- LXI SP 3FFF: initialize SP by 3FFF.
- PUSH H: push the content of H and L register into the stack and decrements stack pointer by 2.
- PUSH D: push the content of D and E register into the stack and decrements stack pointer by 2.
- POP H: pop the upper two bytes from top of stack and place it in HL register pair and increment SP by 2.
- POP D: pop the upper two bytes from top of stack and place it in DE register pair and increment SP by 2.
- HLT: stops executing the program and halts any further execution.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- 8085 program to access and exchange the content of Flag register with register B
- 8085 program to count the number of ones in contents of register B
- 8085 program to find 2's complement of the contents of Flag Register
- Flag register in 8085 microprocessor
- Register content and Flag status after Instructions
- Difference between Register Mode and Register Indirect Mode
- 8085 program to exchange a block of bytes in memory
- Difference between Register and Memory
- Register Transfer Language (RTL)
- Register Allocations in Code Generation
- Flag register of 8086 microprocessor
- Introduction of General Register based CPU Organization
- Difference between PC relative and Base register Addressing Modes
- Difference between Memory based and Register based Addressing Modes
- Subtract content of two ports by interfacing 8255 with 8085 microprocessor
- 8085 program to add 2-BCD numbers
- 8085 program to add two 8 bit numbers
- 8085 program to add two 16 bit numbers
- 8085 program to reverse 8 bit number
- 8085 program for bubble sort
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.