mirror of
https://github.com/soconnor0919/eceg431.git
synced 2025-12-11 22:54:43 -05:00
Implement basic logic gates: Not, And, Or, Xor, Mux, DMux
This commit is contained in:
@@ -11,5 +11,7 @@ CHIP And {
|
||||
OUT out;
|
||||
|
||||
PARTS:
|
||||
//// Replace this comment with your code.
|
||||
// And(a,b) = Not(Nand(a,b))
|
||||
Nand(a=a, b=b, out=nandOut);
|
||||
Not(in=nandOut, out=out);
|
||||
}
|
||||
@@ -12,5 +12,8 @@ CHIP DMux {
|
||||
OUT a, b;
|
||||
|
||||
PARTS:
|
||||
//// Replace this comment with your code.
|
||||
// DMux(in,sel) -> a = And(in, Not(sel)), b = And(in, sel)
|
||||
Not(in=sel, out=notSel);
|
||||
And(a=in, b=notSel, out=a);
|
||||
And(a=in, b=sel, out=b);
|
||||
}
|
||||
|
||||
@@ -11,5 +11,9 @@ CHIP Mux {
|
||||
OUT out;
|
||||
|
||||
PARTS:
|
||||
//// Replace this comment with your code.
|
||||
// Mux(a,b,sel) = Or(And(a, Not(sel)), And(b, sel))
|
||||
Not(in=sel, out=notSel);
|
||||
And(a=a, b=notSel, out=aAndNotSel);
|
||||
And(a=b, b=sel, out=bAndSel);
|
||||
Or(a=aAndNotSel, b=bAndSel, out=out);
|
||||
}
|
||||
@@ -11,5 +11,6 @@ CHIP Not {
|
||||
OUT out;
|
||||
|
||||
PARTS:
|
||||
//// Replace this comment with your code.
|
||||
// Not(in) = Nand(in, in)
|
||||
Nand(a=in, b=in, out=out);
|
||||
}
|
||||
|
||||
@@ -11,5 +11,9 @@ CHIP Or {
|
||||
OUT out;
|
||||
|
||||
PARTS:
|
||||
//// Replace this comment with your code.
|
||||
// Or(a,b) = Not(And(Not(a), Not(b))) - De Morgan's law
|
||||
Not(in=a, out=notA);
|
||||
Not(in=b, out=notB);
|
||||
And(a=notA, b=notB, out=andOut);
|
||||
Not(in=andOut, out=out);
|
||||
}
|
||||
|
||||
@@ -11,5 +11,10 @@ CHIP Xor {
|
||||
OUT out;
|
||||
|
||||
PARTS:
|
||||
//// Replace this comment with your code.
|
||||
// Xor(a,b) = Or(And(a, Not(b)), And(Not(a), b))
|
||||
Not(in=a, out=notA);
|
||||
Not(in=b, out=notB);
|
||||
And(a=a, b=notB, out=aAndNotB);
|
||||
And(a=notA, b=b, out=notAAndB);
|
||||
Or(a=aAndNotB, b=notAAndB, out=out);
|
||||
}
|
||||
Reference in New Issue
Block a user