Skip to content
Related Articles

Related Articles

Improve Article
8085 program to swap two 16 bit numbers using Direct addressing mode
  • Last Updated : 16 May, 2018

Problem – Write a program to swap two 16-bit numbers using direct addressing mode where starting address is 2000 and the first 16-bit number is stored at 3000 and the second 16-bit number is stored at 3002 memory address.

Example –

Algorithm –

  1. Load a 16-bit number from memory 3000 into a register pair (H-L)
  2. Exchange the register pairs
  3. Load a 16-bit number from memory 3002 into a register pair (H-L)
  4. Exchange both the register pairs
  5. Stop

Program –

2000LHLD[3000][H-L] <- [3000]
2003XCHG[H-L] [D-E]
2004LHLD[3002][H-L] <- [3002]
2007XCHG[H-L] [D-E]

Explanation – Registers (H-L) pair, (D-E) pair are used for general purpose.

  1. LHLD is used to load register pair H-L direct using 16-bit address (3 Byte instruction)
  2. XCHG is used to exchange the data of both the register pair (H-L), (D-E) (1 Byte instruction)
  3. HLT is used to halt the 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
Recommended Articles
Page :