ex

Exchange

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

SZHP/VNC ––––––
  • Most forms leave every flag unchanged

Forms that affect the flags differently are shown in their row.

Forms

  • ex af, af' 1 byte4 cycles S●Z●H●P/V●N●C●

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

  • ex (sp), hl 1 byte19 cycles

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

  • ex de, hl 1 byte4 cycles

    Exchanges the 16-bit contents of DE and HL.

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

Pseudo-instructions

The assembler also accepts these forms, which are other ways to write Z80 instructions. Open a row to see what each form 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