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
- Print a number in any base without helpZ80 assembly
- Flappy birdZ80 assembly
SZHP/VNC ––––––
- Changes no flag
Forms
ex af, af'1 byte · 4 cyclesExchanges the 16-bit contents of AF and AF'.
ex (sp), hl1 byte · 19 cyclesExchanges (SP) with L, and (SP+1) with H.
ex de, hl1 byte · 4 cyclesExchanges 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
ixindex register. You can also useiy, with the same instruction size and timing. More
.org 0x8000
ld a, 5
ex af, af'
halt