These instructions exchange values between registers.
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | |
---|---|---|---|---|---|---|---|---|
\(AF \longleftrightarrow AF'\) | ||||||||
EX AF, AF' | ||||||||
0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 08 |
\(BC \longleftrightarrow BC', DE \longleftrightarrow DE', HL \longleftrightarrow HL'\) | ||||||||
EXX | ||||||||
1 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | D9 |
\(DE \longleftrightarrow HL\) | ||||||||
EX DE, HL | ||||||||
1 | 1 | 1 | 0 | 1 | 0 | 1 | 1 | EB |
\(H \longleftrightarrow (SP+1), L \longleftrightarrow (SP)\) | ||||||||
EX (SP), HL | ||||||||
1 | 1 | 1 | 0 | 0 | 0 | 1 | 1 | E3 |
\(IX_h \longleftrightarrow (SP+1), IX_l \longleftrightarrow (SP)\) | ||||||||
EX (SP), IX | ||||||||
1 | 1 | 0 | 1 | 1 | 1 | 0 | 1 | DD |
1 | 1 | 1 | 0 | 0 | 0 | 1 | 1 | E3 |
\(IY_h \longleftrightarrow (SP+1), IY_l \longleftrightarrow (SP)\) | ||||||||
EX (SP), IY | ||||||||
1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | FD |
1 | 1 | 1 | 0 | 0 | 0 | 1 | 1 | E3 |
EX AF, AF'
(0x08) allows the programmer to switch between the two pairs of Accumulator flag
registers.
EX DE, HL
(0xEB) exchanges the values between those two registers.
EXX
(0xD9) allows the programmer to switch BC, DE and HL and BC', DE' and HL' register pairs.
Internally these instructions toggles a flip-flop which determines which register or register set is the active one. This minimises how long the instruction takes as no data is transferred - just a single bit changes state.
EX (SP),HL
exchanges HL with the last value pushed on the stack.
Flags Affected
None. |
Opcode Matrix
AF' | HL | IX | IY | BC',DE',HL' | |
---|---|---|---|---|---|
AF |
EX AF, AF'
0814 |
|
|
|
|
DE |
|
EX DE, HL
EB14 |
|
|
|
(SP) |
|
EX (SP), HL
E3119 |
EX (SP), IX
DDE3223 |
EX (SP), IY
FDE3223 |
|
BC,DE,HL |
|
|
|
|
EXX
D914 |
Instruction
Opcode hexSize bytesCycle count
| Register | Memory |