8085 program to swap two 8 bit numbers using Direct addressing mode
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 – Algorithm –
- Load a 8-bit number from memory 3000 into accumulator
- Move value of accumulator into register H
- Load a 8-bit number from memory 3001 into accumulator
- Move value of accumulator into register D
- Exchange both the register pairs
||[A] <- 
||[H] <- [A]
||[A] <- 
||[D] <- [A]
Explanation – Registers A, H, D are used for general purpose.
- LDA is used to load accumulator direct using 16-bit address (3 Byte instruction)
- MOV is used to transfer the data (1 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 8-bit numbers using direct addressing mode.
- It is relatively simple and easy to understand, making it useful for teaching purposes.
- It requires fewer instructions than the 16-bit swap program, making it faster and more efficient.
- The program is still 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 8 bits.
- The program only swaps two 8-bit numbers and would need modification to swap larger data sets.
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!