Skip to content
Related Articles

Related Articles

Improve Article

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

  • Difficulty Level : Basic
  • Last Updated : 16 May, 2018

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

Example –

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.

 



Algorithm –

  1. Load a 8-bit number from memory 3000 into accumulator
  2. Move value of accumulator into register H
  3. Load a 8-bit number from memory 3001 into accumulator
  4. Move value of accumulator into register D
  5. Exchange both the register pairs
  6. Stop

Program –

MemoryMnemonicsOperandsComment
2000LDA[3000][A] <- [3000]
2003MOVH, A[H] <- [A]
2004LDA[3001][A] <- [3001]
2007MOVD, A[D] <- [A]
2008XCHG[H-L] [D-E]
2009HLTStop

Explanation – Registers A, H, D are used for general purpose.

  1. LDA is used to load accumulator direct using 16-bit address (3 Byte instruction)
  2. MOV is used to transfer the data (1 Byte instruction)
  3. XCHG is used to exchange the data of both the register pair (H-L), (D-E) (1 Byte instruction)
  4. HLT is used to halt the program.
My Personal Notes arrow_drop_up
Recommended Articles
Page :