EX (SP),HL

Operation

H <-> (SP+1), L <-> (SP)

Mnemonic

EX

Operands

(SP),HL

b7b6b5b4b3b2b1b0
1 1 1 0 0 0 1 1$E3

Description

The low-order byte contained in register pair HL is exchanged with the contents of the memory address specified by the contents of register pair SP (Stack Pointer), and the high-order byte of HL is exchanged with the next highest memory address (SP+1).

Condition Bits Affected

None

Example

If the HL register pair contains $7012, the SP register pair contains $8856, the memory location $8856 contains byte $11, and memory location $8857 contains byte $22, then the instruction

	EX	(SP),HL

results in the HL register pair containing number $2211, memory location $8856 containing byte $12, memory location $8857 containing byte $70 and Stack Pointer containing $8856.