ex

Exchange

Swaps AF with AF', DE with HL, or the word at (SP) with HL, IX or IY.

SZHP/VNC ––––––
  • Changes no flag

Forms

  • ex af, af' 1 byte · 4 cycles

    Exchanges the 16-bit contents of AF and AF'.

  • ex (sp), hl 1 byte · 19 cycles

    Exchanges (SP) with L, and (SP+1) with H.

  • ex de, hl 1 byte · 4 cycles

    Exchanges the 16-bit contents of DE and HL.

  • Exchanges (SP) with IXL, and (SP+1) with IXH.

Pseudo-instructions

Other spellings the assembler accepts; each form shows the instruction it becomes.

  • Exchanges the 16-bit contents of AF and AF'.

  • Exchanges (SP) with L, and (SP+1) with H.

  • Exchanges the 16-bit contents of DE and HL.

  • Exchanges (SP) with IXL, and (SP+1) with IXH.

Operands

ix
The ix index register. You can also use iy, with the same instruction size and timing. More
        .org 0x8000
        ld a, 5
        ex af, af'
        halt