ex
Exchange
Swaps AF with AF', DE with HL, or the word at (SP) with HL, IX or IY.
Used in
- Multiply and divide, with the remainderZ80 assembly
- Convert a number to a string in any baseZ80 assembly
- Flappy ASMZ80 assembly
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), hl1 byte19 cyclesExchanges (SP) with L, and (SP+1) with H.
ex de, hl1 byte4 cyclesExchanges 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
ixindex register. You can also useiy, with the same instruction size and timing. More
.org 0x8000
ld a, 5
ex af, af'
halt