Project 1
Nand
A |
B |
Out |
0 |
0 |
1 |
0 |
1 |
1 |
1 |
0 |
1 |
1 |
1 |
0 |
Not
CHIP Not {
IN in;
OUT out;
PARTS:
Nand(a=in,b=in,out=out);
}
And
CHIP And {
IN a, b;
OUT out;
PARTS:
Nand(a=a, b=b, out=AnandB);
Nand(a=AnandB, b=AnandB, out=out);
}
a |
b |
out |
0 |
0 |
0 |
0 |
1 |
0 |
1 |
0 |
0 |
1 |
1 |
1 |
Or
CHIP Or {
IN a, b;
OUT out;
PARTS:
Not(in=a,out=A);
Not(in=b,out=B);
Nand(a=A,b=B,out=out);
}
a |
b |
out |
0 |
0 |
0 |
0 |
1 |
1 |
1 |
0 |
1 |
1 |
1 |
1 |
Xor
CHIP Xor {
IN a, b;
OUT out;
PARTS:
Not(in=b,out=B);
And(a=a,b=B,out=c);
Not(in=a,out=A);
And(a=A,b=b,out=d);
Or(a=c,b=d,out=out);
}
a |
b |
out |
0 |
0 |
0 |
0 |
1 |
1 |
1 |
0 |
1 |
1 |
1 |
0 |
Mux
CHIP Mux {
IN a, b, sel;
OUT out;
PARTS:
Not(in=sel,out=SEL);
And(a=a,b=SEL,out=o1);
And(a=b,b=sel,out=o2);
Or(a=o1,b=o2,out=out);
}
a |
b |
sel |
out |
0 |
0 |
0 |
0 |
0 |
0 |
1 |
0 |
0 |
1 |
0 |
0 |
0 |
1 |
1 |
1 |
1 |
0 |
0 |
1 |
1 |
0 |
1 |
0 |
1 |
1 |
0 |
1 |
1 |
1 |
1 |
1 |
DMux
CHIP DMux {
IN in, sel;
OUT a, b;
PARTS:
Not(in=sel,out=SEL);
And(a=in,b=SEL,out=a);
And(a=in,b=sel,out=b);
}
in |
sel |
a |
b |
0 |
0 |
0 |
0 |
0 |
1 |
0 |
0 |
1 |
0 |
1 |
0 |
1 |
1 |
0 |
1 |
Not16
CHIP Not16 {
IN in[16];
OUT out[16];
PARTS:
Not(in=in[15],out=out[15]);
Not(in=in[14],out=out[14]);
Not(in=in[13],out=out[13]);
Not(in=in[12],out=out[12]);
Not(in=in[11],out=out[11]);
Not(in=in[10],out=out[10]);
Not(in=in[09],out=out[09]);
Not(in=in[08],out=out[08]);
Not(in=in[07],out=out[07]);
Not(in=in[06],out=out[06]);
Not(in=in[05],out=out[05]);
Not(in=in[04],out=out[04]);
Not(in=in[03],out=out[03]);
Not(in=in[02],out=out[02]);
Not(in=in[01],out=out[01]);
Not(in=in[00],out=out[00]);
}
in |
out |
0000000000000000 |
1111111111111111 |
1111111111111111 |
0000000000000000 |
1010101010101010 |
0101010101010101 |
0011110011000011 |
1100001100111100 |
0001001000110100 |
1110110111001011 |
And16
CHIP And16 {
IN a[16], b[16];
OUT out[16];
PARTS:
And(a=a[00],b=b[00],out=out[00]);
And(a=a[01],b=b[01],out=out[01]);
And(a=a[02],b=b[02],out=out[02]);
And(a=a[03],b=b[03],out=out[03]);
And(a=a[04],b=b[04],out=out[04]);
And(a=a[05],b=b[05],out=out[05]);
And(a=a[06],b=b[06],out=out[06]);
And(a=a[07],b=b[07],out=out[07]);
And(a=a[08],b=b[08],out=out[08]);
And(a=a[09],b=b[09],out=out[09]);
And(a=a[10],b=b[10],out=out[10]);
And(a=a[11],b=b[11],out=out[11]);
And(a=a[12],b=b[12],out=out[12]);
And(a=a[13],b=b[13],out=out[13]);
And(a=a[14],b=b[14],out=out[14]);
And(a=a[15],b=b[15],out=out[15]);
}
a |
b |
out |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
1111111111111111 |
0000000000000000 |
1111111111111111 |
1111111111111111 |
1111111111111111 |
1010101010101010 |
0101010101010101 |
0000000000000000 |
0011110011000011 |
0000111111110000 |
0000110011000000 |
0001001000110100 |
1001100001110110 |
0001000000110100 |
Or16
CHIP Or16 {
IN a[16], b[16];
OUT out[16];
PARTS:
Or(a=a[00],b=b[00],out=out[00]);
Or(a=a[01],b=b[01],out=out[01]);
Or(a=a[02],b=b[02],out=out[02]);
Or(a=a[03],b=b[03],out=out[03]);
Or(a=a[04],b=b[04],out=out[04]);
Or(a=a[05],b=b[05],out=out[05]);
Or(a=a[06],b=b[06],out=out[06]);
Or(a=a[07],b=b[07],out=out[07]);
Or(a=a[08],b=b[08],out=out[08]);
Or(a=a[09],b=b[09],out=out[09]);
Or(a=a[10],b=b[10],out=out[10]);
Or(a=a[11],b=b[11],out=out[11]);
Or(a=a[12],b=b[12],out=out[12]);
Or(a=a[13],b=b[13],out=out[13]);
Or(a=a[14],b=b[14],out=out[14]);
Or(a=a[15],b=b[15],out=out[15]);
}
a |
b |
out |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
1111111111111111 |
1111111111111111 |
1111111111111111 |
1111111111111111 |
1111111111111111 |
1010101010101010 |
0101010101010101 |
1111111111111111 |
0011110011000011 |
0000111111110000 |
0011111111110011 |
0001001000110100 |
1001100001110110 |
1001101001110110 |
Mux16
CHIP Mux16 {
IN a[16], b[16], sel;
OUT out[16];
PARTS:
Mux(a=a[00],b=b[00],sel=sel,out=out[00]);
Mux(a=a[01],b=b[01],sel=sel,out=out[01]);
Mux(a=a[02],b=b[02],sel=sel,out=out[02]);
Mux(a=a[03],b=b[03],sel=sel,out=out[03]);
Mux(a=a[04],b=b[04],sel=sel,out=out[04]);
Mux(a=a[05],b=b[05],sel=sel,out=out[05]);
Mux(a=a[06],b=b[06],sel=sel,out=out[06]);
Mux(a=a[07],b=b[07],sel=sel,out=out[07]);
Mux(a=a[08],b=b[08],sel=sel,out=out[08]);
Mux(a=a[09],b=b[09],sel=sel,out=out[09]);
Mux(a=a[10],b=b[10],sel=sel,out=out[10]);
Mux(a=a[11],b=b[11],sel=sel,out=out[11]);
Mux(a=a[12],b=b[12],sel=sel,out=out[12]);
Mux(a=a[13],b=b[13],sel=sel,out=out[13]);
Mux(a=a[14],b=b[14],sel=sel,out=out[14]);
Mux(a=a[15],b=b[15],sel=sel,out=out[15]);
}
a |
b |
sel |
out |
0000000000000000 |
0000000000000000 |
0 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
1 |
0000000000000000 |
0000000000000000 |
0001001000110100 |
0 |
0000000000000000 |
0000000000000000 |
0001001000110100 |
1 |
0001001000110100 |
1001100001110110 |
0000000000000000 |
0 |
1001100001110110 |
1001100001110110 |
0000000000000000 |
1 |
0000000000000000 |
1010101010101010 |
0101010101010101 |
0 |
1010101010101010 |
1010101010101010 |
0101010101010101 |
1 |
0101010101010101 |
Or8Way
CHIP Or8Way {
IN in[8];
OUT out;
PARTS:
Or(a=in[7],b=in[6],out=or76);
Or(a=in[5],b=in[4],out=or54);
Or(a=in[3],b=in[2],out=or32);
Or(a=in[1],b=in[0],out=or10);
Or(a=or76,b=or54,out=or74);
Or(a=or32,b=or10,out=or30);
Or(a=or74,b=or30,out=out);
}
in |
out |
00000000 |
0 |
11111111 |
1 |
00010000 |
1 |
00000001 |
1 |
00100110 |
1 |
Mux4Way16
CHIP Mux4Way16 {
IN a[16], b[16], c[16], d[16], sel[2];
OUT out[16];
PARTS:
Mux16(a=a,b=b,sel=sel[0],out=outab);
Mux16(a=c,b=d,sel=sel[0],out=outcd);
Mux16(a=outab,b=outcd,sel=sel[1],out=out);
}
a |
b |
c |
d |
sel |
out |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
00 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
01 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
10 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
11 |
0000000000000000 |
0001001000110100 |
1001100001110110 |
1010101010101010 |
0101010101010101 |
00 |
0001001000110100 |
0001001000110100 |
1001100001110110 |
1010101010101010 |
0101010101010101 |
01 |
1001100001110110 |
0001001000110100 |
1001100001110110 |
1010101010101010 |
0101010101010101 |
10 |
1010101010101010 |
0001001000110100 |
1001100001110110 |
1010101010101010 |
0101010101010101 |
11 |
0101010101010101 |
Mux8Way16
CHIP Mux8Way16 {
IN a[16], b[16], c[16], d[16],
e[16], f[16], g[16], h[16],
sel[3];
OUT out[16];
PARTS:
Mux4Way16(a=a,b=b,c=c,d=d,sel=sel[0..1],out=outad);
Mux4Way16(a=e,b=f,c=g,d=h,sel=sel[0..1],out=outeh);
Mux16(a=outad,b=outeh,sel=sel[2],out=out);
}
a |
b |
c |
d |
e |
f |
g |
h |
sel |
out |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
001 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
010 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
011 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
100 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
101 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
110 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
0000000000000000 |
111 |
0000000000000000 |
0001001000110100 |
0010001101000101 |
0011010001010110 |
0100010101100111 |
0101011001111000 |
0110011110001001 |
0111100010011010 |
1000100110101011 |
000 |
0001001000110100 |
0001001000110100 |
0010001101000101 |
0011010001010110 |
0100010101100111 |
0101011001111000 |
0110011110001001 |
0111100010011010 |
1000100110101011 |
001 |
0010001101000101 |
0001001000110100 |
0010001101000101 |
0011010001010110 |
0100010101100111 |
0101011001111000 |
0110011110001001 |
0111100010011010 |
1000100110101011 |
010 |
0011010001010110 |
0001001000110100 |
0010001101000101 |
0011010001010110 |
0100010101100111 |
0101011001111000 |
0110011110001001 |
0111100010011010 |
1000100110101011 |
011 |
0100010101100111 |
0001001000110100 |
0010001101000101 |
0011010001010110 |
0100010101100111 |
0101011001111000 |
0110011110001001 |
0111100010011010 |
1000100110101011 |
100 |
0101011001111000 |
0001001000110100 |
0010001101000101 |
0011010001010110 |
0100010101100111 |
0101011001111000 |
0110011110001001 |
0111100010011010 |
1000100110101011 |
101 |
0110011110001001 |
0001001000110100 |
0010001101000101 |
0011010001010110 |
0100010101100111 |
0101011001111000 |
0110011110001001 |
0111100010011010 |
1000100110101011 |
110 |
0111100010011010 |
0001001000110100 |
0010001101000101 |
0011010001010110 |
0100010101100111 |
0101011001111000 |
0110011110001001 |
0111100010011010 |
1000100110101011 |
111 |
1000100110101011 |
DMux4Way
CHIP DMux4Way {
IN in, sel[2];
OUT a, b, c, d;
PARTS:
Not(in=sel[0],out=sel00);
Not(in=sel[1],out=sel11);
And(a=sel[0],b=sel[1],out=e);
And(a=sel[0],b=sel11,out=f);
And(a=sel00,b=sel[1],out=g);
And(a=sel00,b=sel11,out=h);
DMux(in=in,sel=h,a=i0,b=a);
DMux(in=in,sel=f,a=i1,b=b);
DMux(in=in,sel=g,a=i2,b=c);
DMux(in=in,sel=e,a=i3,b=d);
}
in |
sel |
a |
b |
c |
d |
0 |
00 |
0 |
0 |
0 |
0 |
0 |
01 |
0 |
0 |
0 |
0 |
0 |
10 |
0 |
0 |
0 |
0 |
0 |
11 |
0 |
0 |
0 |
0 |
1 |
00 |
1 |
0 |
0 |
0 |
1 |
01 |
0 |
1 |
0 |
0 |
1 |
10 |
0 |
0 |
1 |
0 |
1 |
11 |
0 |
0 |
0 |
1 |
DMux8Way
CHIP DMux8Way {
IN in, sel[3];
OUT a, b, c, d, e, f, g, h;
PARTS:
Not(in=sel[2],out=sel22);
And(a=in,b=sel[2],out=i);
And(a=in,b=sel22,out=j);
DMux4Way(in=j,sel=sel[0..1],a=a,b=b,c=c,d=d);
DMux4Way(in=i,sel=sel[0..1],a=e,b=f,c=g,d=h);
}
in |
sel |
a |
b |
c |
d |
e |
f |
g |
h |
0 |
000 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
001 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
010 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
011 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
100 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
101 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
110 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
111 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
1 |
000 |
1 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
1 |
001 |
0 |
1 |
0 |
0 |
0 |
0 |
0 |
0 |
1 |
010 |
0 |
0 |
1 |
0 |
0 |
0 |
0 |
0 |
1 |
011 |
0 |
0 |
0 |
1 |
0 |
0 |
0 |
0 |
1 |
100 |
0 |
0 |
0 |
0 |
1 |
0 |
0 |
0 |
1 |
101 |
0 |
0 |
0 |
0 |
0 |
1 |
0 |
0 |
1 |
110 |
0 |
0 |
0 |
0 |
0 |
0 |
1 |
0 |
1 |
111 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
1 |