8085 program to swap two 16 bit numbers using Direct addressing mode

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 –

Memory Mnemonics Operands Comment
2000 LHLD [3000] [H-L] <- [3000]
2003 XCHG [H-L] [D-E]
2004 LHLD [3002] [H-L] <- [3002]
2007 XCHG [H-L] [D-E]
2008 HLT Stop

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.


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.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.