Mux8Way16

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Mux8Way16

chris_sooseok
My code is basically like this below.

Mux16(a=a, b=b, sel=sel[0], out=OutAB);
Mux16(a=c, b=d, sel=sel[0], out=OutCD);
Mux16(a=e, b=f, sel=sel[0], out=OutEF);
Mux16(a=g, b=h, sel=sel[0], out=OutGH);
   
Mux16(a=OutAB, b=OutCD, sel=sel[1], out=OutABCD);
Mux16(a=OutEF, b=OutGH, sel=sel[1], out=OutEFGH);

Mux16(a=OutABCD, b=OutEFGH, sel=sel[2], out=out);

I understand the code I write, and it has passed with the given test.

But, as far as I can think and understand, even if I switch the b and d in the first two lines like this:
Mux16(a=a, b=d, sel=sel[0], out=OutAD);
Mux16(a=c, b=b, sel=sel[0], out=OutCB);
or also switch the f and h in the third to fourth lines like this:
Mux16(a=e, b=h, sel=sel[0], out=OutEH);
Mux16(a=g, b=f, sel=sel[0], out=OutGF);

,the code should not be a problem because we are evaluating each inputs of Mux with indexed sel bit [0 or 1].

However, this switch doesn't work as I expected.

I thought this wouldn't be a problem because i consumed the order wouldn't matter since all inputs will merge into comparison of each after all.

I am curious of why this wouldn't work..

Thank you!





Reply | Threaded
Open this post in threaded view
|

Re: Mux8Way16

dolomiti7
The order matters. It is a selection of a specific input and not a comparison. You will still have a unique allocation of inputs based on the sel input, e.g. each of the 8 inputs is linked to exactly one of the 8 possible combinations of the sel input. However, if you switch your signals, you are not following the specification anymore:

The chip should return
  a if and only if sel=000
  b if and only if sel=001
      (this is violated when you switch, in your case you return d for sel=001)
  ...
  h if and only if sel=111

Hope that helps
Reply | Threaded
Open this post in threaded view
|

Re: Mux8Way16

chris_sooseok
Thank you for the help!

But, I am thinking that even if I switch the order, doesn't it end up to the correct answer based on the selection of code lines? So, let's say the given sel is 001. Then, the code is this, which I basically switched b and d.

Mux16(a=a, b=d, sel=sel[0], out=OutAB); // 1
Mux16(a=c, b=b, sel=sel[0], out=OutCD); // 2
Mux16(a=e, b=f, sel=sel[0], out=OutEF); // 3
Mux16(a=g, b=h, sel=sel[0], out=OutGH); // 4
   
Mux16(a=OutAB, b=OutCD, sel=sel[1], out=OutABCD); // 5
Mux16(a=OutEF, b=OutGH, sel=sel[1], out=OutEFGH); // 6

Mux16(a=OutABCD, b=OutEFGH, sel=sel[2], out=out); // 7

Then, following the lines of the code running,
line 1 will output d
line 2 will output b
line 3 will output f
line 4 will output h

line 5 will output b
line 6 will output f

line 7 will eventually output b, which corrects to sel 001.

I understand each of the inputs is linked to only one selection input.
But, following the code line, the change order seems not to bother the linking because we are selecting bit by bit based on the given sel value.

a if sel = 000
b if sel = 001
c if sel = 010
d if sel = 011
e if sel = 100
f if sel = 101
g if sel = 110
h if sel = 111

Thank you so much!
Reply | Threaded
Open this post in threaded view
|

Re: Mux8Way16

WBahn
Administrator
In reply to this post by chris_sooseok
chris_sooseok wrote
My code is basically like this below.

Mux16(a=a, b=b, sel=sel[0], out=OutAB);
Mux16(a=c, b=d, sel=sel[0], out=OutCD);
Mux16(a=e, b=f, sel=sel[0], out=OutEF);
Mux16(a=g, b=h, sel=sel[0], out=OutGH);
   
Mux16(a=OutAB, b=OutCD, sel=sel[1], out=OutABCD);
Mux16(a=OutEF, b=OutGH, sel=sel[1], out=OutEFGH);

Mux16(a=OutABCD, b=OutEFGH, sel=sel[2], out=out);

I understand the code I write, and it has passed with the given test.
For the code above, what has to be the state of the select bits in order to select input 'b'?

sel[0] = 1 (so that OutAB = b)
sel[1] = 0 (so that outABCD = OutAB = b)
sel[2] = 0 (so that out = OutABCD = OutAB = b)

But, as far as I can think and understand, even if I switch the b and d in the first two lines like this:
Mux16(a=a, b=d, sel=sel[0], out=OutAD);
Mux16(a=c, b=b, sel=sel[0], out=OutCB);
or also switch the f and h in the third to fourth lines like this:
Mux16(a=e, b=h, sel=sel[0], out=OutEH);
Mux16(a=g, b=f, sel=sel[0], out=OutGF);

,the code should not be a problem because we are evaluating each inputs of Mux with indexed sel bit [0 or 1].

However, this switch doesn't work as I expected.
It's impossible to tell what it will do because you have changed signal names and given no indication of how those new signals are connected to the later multiplexers.
Reply | Threaded
Open this post in threaded view
|

Re: Mux8Way16

WBahn
Administrator
In reply to this post by chris_sooseok
chris_sooseok wrote
Thank you for the help!

But, I am thinking that even if I switch the order, doesn't it end up to the correct answer based on the selection of code lines? So, let's say the given sel is 001. Then, the code is this, which I basically switched b and d.

Mux16(a=a, b=d, sel=sel[0], out=OutAB); // 1
Mux16(a=c, b=b, sel=sel[0], out=OutCD); // 2
Mux16(a=e, b=f, sel=sel[0], out=OutEF); // 3
Mux16(a=g, b=h, sel=sel[0], out=OutGH); // 4
   
Mux16(a=OutAB, b=OutCD, sel=sel[1], out=OutABCD); // 5
Mux16(a=OutEF, b=OutGH, sel=sel[1], out=OutEFGH); // 6

Mux16(a=OutABCD, b=OutEFGH, sel=sel[2], out=out); // 7

Then, following the lines of the code running,
line 1 will output d
line 2 will output b
line 3 will output f
line 4 will output h

line 5 will output b
line 6 will output f

line 7 will eventually output b, which corrects to sel 001.

I understand each of the inputs is linked to only one selection input.
But, following the code line, the change order seems not to bother the linking because we are selecting bit by bit based on the given sel value.

a if sel = 000
b if sel = 001
c if sel = 010
d if sel = 011
e if sel = 100
f if sel = 101
g if sel = 110
h if sel = 111

Thank you so much!
Changing the order to WHAT?

Give a complete example of what changes you would make that would demonstrate that the order doesn't matter.

There are multiple correct ways to set things up so that you get the correct output -- you have three layers of selection and you can use any selection bit for each of the layers, giving you eight different possibilities. But, for each one of those possibilities, the eight input data signals must be connected to a specific input on a specific multiplexer in order to get the correct mapping.
Reply | Threaded
Open this post in threaded view
|

Re: Mux8Way16

chris_sooseok
Ok!
I didn't understand the part that "the eight input data signals must be connected to a specific input on a specific multiplexer in order to get the correct mapping". Especially, the part of a specific multiplexer.

Now I do. Thank you!