Open In App
Related Articles

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

Improve Article
Improve
Save Article
Save
Like Article
Like

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 –

MemoryMnemonicsOperandsComment
2000LHLD[3000][H-L] <- [3000]
2003XCHG [H-L] [D-E]
2004LHLD[3002][H-L] <- [3002]
2007XCHG [H-L] [D-E]
2008HLT 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.

Advantages:

  • The program is a useful utility program for swapping two 16-bit numbers using direct addressing mode.
     
  • It is relatively simple and easy to understand, making it useful for teaching purposes.
     
  • It can be customized to swap numbers at different memory locations by modifying the source and destination addresses.
     

Disadvantages:

  • The program is not optimized for speed, as it uses multiple instructions to move each byte of data.
     
  • It requires separate code blocks for each number to swap, which can be cumbersome for large data sets.
     
  • The program does not check for errors or boundary conditions, such as when the source or destination address is outside the valid memory range or when the data size is not a multiple of 16 bits.
Last Updated : 09 Apr, 2023
Like Article
Save Article
Similar Reads