# Chapter 1 - MultiWay Gates

This page continues the first chapter of the Elements of computing Systems creating multi bit gates.

This is the workflow problems of Chapter 1 of the "The Elements of Computing Systems" by Noam Nisan and Shimon Schocken. These are my own solutions for my own reference, The Elements of Computing Systems.

## Multi-Way Or Or8Way

An n-way Or gate outputs 1 when at least one of its n bit inputs is 1 and 0 otherwise. out=Or(in,in,....in).

``````CHIP Or8Way {
IN in;
OUT out;

PARTS:
Or(a=in,b=in,out=c1);
Or(a=in,b=in,out=c2);
Or(a=in,b=in,out=c3);
Or(a=in,b=in,out=c4);
Or(a=c1,b=c2,out=d1);
Or(a=c3,b=c4,out=d2);
Or(a=d1,b=d2,out=out);
}``````

## Multi-Way/Multi-Bix MultiPlexor

An m-way n-bit multiplexor selects one of m n-bit input buses and outputs it to a single n-bit output bus. The selection is specified by a set of k control bits, where k = log2m. The computer platform that will be designed requires two various of this chip a 4 way 16 bit multiplexor and an 8-way 16 bit multiplexor.

What does it all mean basil. If sel = 00, then out = a else if sel = 01 then out = b else if sel = 10 then out c else if sel = 11 then out d

``````CHIP Mux4Way16 {
IN sel, a, b, c, d;
OUT out;

PARTS:
Mux16(a=a, b=b, sel=sel, out=c1);
Mux16(a=c, b=d, sel=sel, out=c2);
Mux16(a=c1, b=c2, sel=sel, out=out);
}``````

If Sel=000 then out=a else if Sel=001 then out=b else if Sel=010 then out=c....else if sel=111 out h

``````CHIP Mux8Way16 {
IN sel, a, b, c, d, e, f, g, h;
OUT out;

PARTS:
Mux4Way16(sel=sel, sel=sel, a, b, c, d, out=c1);
Mux4Way16(sel=sel, sel=sel, e, f, g, h, out=c2);
Mux16(a=c1, b=c2, sel=sel, out=out);
}``````

## Multiway/multibit demultiplexor

An m-way n-bit demultiplexor channels a single n-bit input into one of m possible n-bit outputs. The selection is specified by a set of k control bits, where k=log2m. The specific computer platform that is built requires two various of this 4-way 1-bit demultiplexor and an 8 way 1-bit demultiplexor.

Dmux4Way - if Sel=00 then {a=in, b=c=d=0}, else if Sel=01 then {b=in, a=c=d=0} else if Sel=10 then {c=in, a=b=d=0} else if Sel=11 then {d=in, a=b=c=0}

``````CHIP DMux4Way {
IN in, sel;
OUT a, b, c, d;

Dmux(in=in, sel=sel, a=c1, b=c2);
Dumx(in=c1, sel=sel, a=a, b=b);
Dmux(in=c2, sel=sel, a=c, b=d);
}``````

Dmux8WWay - if Sel=000 then {a = in, b=c=d=e=f=g=h=0}, Sel=001 then {b = in, a=c=d=e=f=g=h=0} ... Sel=111 then {h = in, a=b=c=d=e=f=g=0}

``````CHIP DMux8Way {
IN in, sel;
OUT a, b, c, d, e, f, g, h;

DMux(in=in, sel=sel, a=c1, b=c2);
DMux4Way(in=c1, sel=sel, sel=sel, a=a, b=b, c=c, d=d);
DMux4Way(in=c2, sel=sel, sel=sel, a=e, b=f, c=g, d=h);
}``````