1
\$\begingroup\$

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 ?

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

In Verilog HDL:

always @(posedge clk)
begin
  ...
  if (is_xchg_opcode)
  begin
     DE <= HL;
     HL <= DE;
  end
\$\endgroup\$
  • \$\begingroup\$ I think the OP won't understand this though ... \$\endgroup\$ – Mitu Raj May 3 '18 at 10:27
  • \$\begingroup\$ It was mean as a brain teaser to encourage looking into how a hardware language works. I'll update with the term 'verilog'. \$\endgroup\$ – Oldfart May 3 '18 at 10:36
  • \$\begingroup\$ aren't you just rephrasing the question? \$\endgroup\$ – Jasen May 3 '18 at 10:48
1
\$\begingroup\$

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
\$\endgroup\$
0
\$\begingroup\$

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

DE <= content of HL
HL <= content of WZ
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.