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 –
- Load a 16-bit number from memory 3000 into a register pair (H-L)
- Exchange the register pairs
- Load a 16-bit number from memory 3002 into a register pair (H-L)
- Exchange both the register pairs
||[H-L] <- 
||[H-L] <- 
Explanation – Registers (H-L) pair, (D-E) pair are used for general purpose.
- LHLD is used to load register pair H-L direct using 16-bit address (3 Byte instruction)
- XCHG is used to exchange the data of both the register pair (H-L), (D-E) (1 Byte instruction)
- HLT is used to halt the program.
- 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.
- 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.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!