# Exchange instruction of 8085 microprocessor

How XCHG instruction is executed by 8085 microprocessor ? By default XCHG instruction takes place between DE pair and HL pair. Suppose let us assume contents of DE pair is replaced by the contents of HL pair, then how contents of HL pair are replaced by the contents of DE pair, because it is already replaced by contents of HL pair. How this is possible ?

• electronics.stackexchange.com/questions/151631/… – Meenie Leis May 3 '18 at 9:49
• could it be done with the XOR SWAP algorithm? No intermediate registers are required: en.wikipedia.org/wiki/XOR_swap_algorithm – glen_geek May 3 '18 at 12:15
• The 8085 has 3 temporary registers, W, Z and a third (I cannot remember the name). Google 8085 temporary registers. – Steve G May 3 '18 at 14:44
• not enough clock cycles for XOR swap and the ALU can only write the A register. – Jasen May 4 '18 at 11:03

In Verilog HDL:

always @(posedge clk)
begin
...
if (is_xchg_opcode)
begin
DE <= HL;
HL <= DE;
end

• I think the OP won't understand this though ... – Mitu Raj May 3 '18 at 10:27
• It was mean as a brain teaser to encourage looking into how a hardware language works. I'll update with the term 'verilog'. – Oldfart May 3 '18 at 10:36
• aren't you just rephrasing the question? – Jasen May 3 '18 at 10:48

See this part of this answer to How is XCHG implemented in a 8086 processor?:

Using a hidden register. The 8085 has 2 hidden registers, but it is unknown if it used those registers for the xchange instruction. The 8086 has not been reverse engineered as of yet, so we don't know how many hidden registers it has.

Temp = A
A = B
B = Temp


The content of the DE register pair is stored in the WZ register pair then:

DE <= content of HL
HL <= content of WZ