Q:
Your system has CPU, ALU and two 8bit
registers. There is no external memory. Can you swap the
contents of the registers ?
A: solution by hbegin
XOR has the unique property of giving you the original value
if you XOR it twice: ((A XOR B) XOR B) = A
So... the answer:
Note: values on the left side, showing contents of the
registers, happen after the step listed at right.
REG1 REG2
======================================
A B
A XOR B B Step 1:"XOR R1,R2" #R1 <= R1 XOR R2
A XOR B B XOR (A XOR B) = A Step 2:"XOR R2,R1" #R2 <= R2 XOR R1
(A XOR B) XOR A = B A Step 3:"XOR R1,R2" #R1 <= R1 XOR R2
hbegin