🎓 BookMCQ
← Back to 5. The 8085 Microprocessor

📝 Timing Diagram of XCHG of 8085 Microprocessor (8 MCQs)

Exchange of DE and HL Register-Pair Contents

XCHG is a one-byte instruction that exchanges the contents of the DE and HL register pairs in the 8085. Register D exchanges its value with H, while E exchanges its value with L. It provides a convenient way to exchange two sixteen-bit values without using separate data-transfer instructions or accessing external memory for the exchange.

Internal Register Organization and Exchange Operation

The DE and HL pairs each contain sixteen bits formed from two eight-bit registers. The processor internally transfers their contents using temporary storage so that neither original value is lost during the exchange. The final result places the original DE value in HL and the original HL value in DE.

Opcode Fetch and Four-T-State Execution

The opcode for XCHG is EBH. The instruction requires one opcode-fetch machine cycle of four T-states and no additional operand-memory read or write cycle. During fetching, the program counter supplies the instruction address, ALE indicates lower-address validity and memory provides the opcode for decoding.

Numerical Example of Exchanging Register Pairs

Suppose D contains 20H, E contains 50H, H contains 30H and L contains 00H. Initially, DE equals 2050H and HL equals 3000H. After executing XCHG, DE becomes 3000H and HL becomes 2050H. Both original sixteen-bit values are preserved but their register-pair locations are exchanged.

Use of XCHG in Address and Data Manipulation

The exchange instruction is useful when a program must switch between two sixteen-bit addresses or temporarily use a different memory pointer. It is particularly helpful when HL contains a memory address and DE holds another address or data pair. Because it uses an internal exchange, it avoids additional memory-transfer cycles.

Misconceptions About the XCHG Instruction

'XCHG exchanges the accumulator and B register' is incorrect because only DE and HL are exchanged. 'XCHG requires two memory-access cycles' is incorrect because its operands are internal register pairs. 'XCHG clears the status flags' is incorrect because the instruction leaves all five flags unchanged.

Register-Pair Values and XCHG Timing Questions

Practise forming DE and HL values from their high and low bytes before and after exchange. Identify opcode EBH and calculate the four-T-state execution time. Distinguish XCHG from MOV operations, and explain why the instruction changes register-pair contents without changing memory, the accumulator or the flag register.

Register Exchange and Instruction Timing Terms

  • XCHG - Exchanges DE and HL contents.
  • DE Pair - Combines D and E registers.
  • HL Pair - Combines H and L registers.
  • EBH - Machine opcode of XCHG.
  • Opcode Fetch - Retrieves the instruction byte.
  • Internal Transfer - Moves data between processor registers.
2
Easy
4
Medium
2
Hard

📝 All Timing Diagram of XCHG of 8085 Microprocessor MCQs

Q1. What operation does the XCHG instruction perform in the SAP-III processor?

A.Exchange the contents of two registers ✅
B.Increment the accumulator
C.Reset all flag bits
D.Perform a logical AND on two registers
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: The XCHG mnemonic stands for exchange, meaning it swaps the binary values held in two registers without altering any other part of the CPU state. Option A describes this swap accurately. Options B, C, and D describe unrelated actions: incrementing affects only one register, resetting flags is a separate operation, and logical AND produces a new result rather than swapping. Understanding the exchange behavior is essential when designing code that needs to reorder data quickly.

Q2. In the timing diagram of XCHG, which control line is asserted during the first half of T2 to allow the internal data bus to read a register value?

A.Address line A0‾\overline{A0}
B.Control line WR‾\overline{WR}
C.Control line RD‾\overline{RD} ✅
D.Data line D7
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: During the first half of T2 the processor activates the read control line RD‾\overline{RD} so that the internal data bus can capture the source register’s content. Option C correctly identifies this line. The address line is not used because XCHG does not access memory, and the write line WR‾\overline{WR} is only asserted later when data is placed back. The data line D7 is a data bit, not a control signal.

Q3. A programmer wants to swap the values in registers B and C using the fewest instruction cycles. Which sequence achieves this?

A.MOV B, C; MOV C, B
B.XCHG A, B; XCHG A, C
C.XCHG D, E; MOV B, D
D.XCHG B, C ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: The XCHG instruction can directly exchange the contents of any two registers that form a pair, and B and C constitute a valid pair. Option D therefore performs the swap in a single machine cycle. Option A requires two MOV instructions, doubling the cycle count. Option B uses the accumulator as an intermediary, needing two extra cycles. Option C swaps unrelated registers D and E before moving data, which does not achieve the desired B‑C exchange.

Q4. Why does executing XCHG never modify any of the four flag bits (S, Z, CY, P) in the SAP-III flag register?

A.Because it resets them to zero
B.Because it only moves data internally ✅
C.Because flags are only affected by arithmetic operations
D.Because it sets them based on the parity of exchanged bytes
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: XCHG swaps register contents purely through internal data paths; no arithmetic or logical calculation occurs, so the flag logic is bypassed. Option B captures this reason. Option A is incorrect because XCHG does not clear flags. Option C is misleading; while arithmetic instructions affect flags, XCHG is not arithmetic. Option D suggests a parity check, which XCHG does not perform. Preserving flags is important for subsequent conditional branches.

Q5. At which T‑state does the original content of register H become available on the internal data bus for the exchange operation?

A.T2
B.T3 ✅
C.T4
D.T1
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: During the XCHG cycle the processor reads the high‑order register (H) in the third machine state, T3, making its value present on the internal data bus for transfer. Option B correctly identifies this state. T1 is the opcode fetch, T2 handles the low‑order register (L), and T4 completes the write‑back phase. Knowing the exact timing helps designers avoid bus contention when inserting other micro‑operations around an XCHG.

Q6. If two XCHG instructions are placed back‑to‑back without an intervening NOP, which timing problem is most likely to occur?

A.Overlap of internal bus activity causing contention ✅
B.Incorrect flag updates
C.Program counter misalignment
D.Stack pointer overflow
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: XCHG uses the internal data bus for a few T‑states; issuing another XCHG immediately can cause the second instruction to start before the first has released the bus, leading to contention and unpredictable data. Option A describes this hazard. Flags are untouched by XCHG, so option B is irrelevant. The program counter automatically increments each instruction, so option C does not arise. Stack operations are unrelated, eliminating option D.

Q7. How does the timing diagram illustrate the atomic nature of the register exchange performed by XCHG?

A.All phases occur within a single instruction cycle
B.No intermediate external bus access is required ✅
C.Flag bits are updated only after the exchange
D.The instruction uses microcode sub‑routines
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The diagram shows that the exchange proceeds entirely inside the CPU, with internal latches updating simultaneously, meaning no external observation can see a partially swapped state. Option B captures this atomic behavior. Option A is inaccurate because the instruction spans multiple T‑states, not a single clock tick. Flag updates do not happen, contradicting option C. Microcode sub‑routines are an implementation detail, not the reason for atomicity.

Q8. After swapping registers D and E with XCHG, a program must increment the new value now held in D without disturbing the exchanged data. Which instruction should follow XCHG?

A.INR D ✅
B.DCR D
C.INX D
D.INR E
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: The INR D instruction adds one to the content of register D while leaving all other registers untouched, making it the correct choice after an XCHG. Option A therefore satisfies the requirement. DCR D would decrement instead of increment. INX D is not a valid instruction; the increment instruction for register pairs is INX H, etc. INR E would modify the wrong register, breaking the intended data flow.

🔗 Related Topics (MCQs)