The XCHG instruction

The XCHG (Exchange) instruction is designed to exchange the contents of the HL register pair with the contents of the DE register pair. This means that the high byte of the HL pair (register H) is swapped with the high byte of the DE pair (register D), and the low byte of the HL pair (register L) is swapped with the low byte of the DE pair (register E).

The XCHG instruction format

InstructionDescription
XCHG This format is used to exchange the contents of the HL register pair with the contents of the DE register pair.

Usage example

; Author: Evgeny Sergeevich Dovgopolov

main:
    lxi     d, 0ABCDh  ; Load the hexadecimal value ABCDh into the DE register pair
    lxi     h, 1234h   ; Load the hexadecimal value 1234h into the HL register pair
    xchg               ; Exchange the DE and HL register pairs

    hlt                ; Stop program execution

Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".

Processor status flags

S
No
Z
No
AC
No
P
No
CY
No