z80:Opcodes:EX

From Learn @ Cemetech
Jump to navigationJump to search

Exchanges two 16-bit values.

Syntax

   ex op16,op16

Allowed Instructions

   ex af,af'
   ex de,hl
   ex (sp),hl
   ex (sp),ix
   ex (sp),iy

Effects

Flags are preserved.

Uses

EX DE,HL exchanges HL with DE. Note that IX and IY do not work with this command. EX (SP),HL exchanges HL with the last pushed value on the stack. EX AF,AF' exchanges AF with its shadow register. This is mostly used as an alternative to pushing AF to the stack during interrupts. Note that the flags will most likely not be the same after this command.

T-States

de, hl 4
af, af' 4
(sp),hl 19
(sp),ix 19
(sp),iy 19

See Also

EXX