Implement basic logic gates: Not, And, Or, Xor, Mux, DMux

This commit is contained in:
2025-08-27 19:07:20 +02:00
parent beb668806a
commit ad5f774ae0
6 changed files with 32 additions and 13 deletions

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}