
Puzzle #3
June 4, 2007OK, you seem to like them so here is another puzzle/interview question.
In the diagram below both X and Y are n-bit wide registers. With each clock cycle you could select a bit-wise basic operation between X and Y and load it to either X or Y, while the other register keeps its value.
The problem is to exchange the contents of X and Y. Describe the values of the “select logic op” and “load XnotY” signals for each clock cycle.
This one works on confusion. XOR (^) is all you need here. Remember that
X^X=0 and that X^0=XSo:
X,Y (XOR, store in X)(done)X^Y,Y (XOR, store in Y)
X^Y,Y^(X^Y) = Y^Y^X = 0^X = X (XOR, store in X)
X^(X^Y) = Y,X
Good job Saar!!!
[...] - Solution June 19th, 2007 This post is written only for completeness reasons. The answer to puzzle #3 was almost immediately given in the comments. I will just repeat it here. The important [...]