Monday, March 2, 2009

Swapping X & Y

X and Y are n-bit wide registers. In each clock cycle you can select a bit-wise basic operation between X and Y and store 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.

load_puzzle.png

3 comments:

  1. x=x^y -- (1) selectLogic Op = XOR, Load XnotY=1

    y=(x^y) selectLogic Op = XOR, Load XnotY=0
    =((x^y)^y) from(1)
    y=x -- (2)

    x=(x^y) selectLogic Op = XOR, Load XnotY=0
    =(x^y^x) -- from (1)&(2)
    x=Y

    So X & Y are swapped

    ReplyDelete
  2. small correction for the above sol...
    the last Load XnotY should be 1 (not 0)

    ReplyDelete
  3. it is a shame you don't give credit to where you 'borrowed' those from...
    http://asicdigitaldesign.wordpress.com

    ReplyDelete