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.
- 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
|2000||LHLD||||[H-L] <- |
|2004||LHLD||||[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.
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.