2020-05-19 12:42:52 +00:00
|
|
|
// This file is part of www.nand2tetris.org
|
|
|
|
// and the book "The Elements of Computing Systems"
|
|
|
|
// by Nisan and Schocken, MIT Press.
|
|
|
|
// File name: projects/01/Xor.hdl
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Exclusive-or gate:
|
|
|
|
* out = not (a == b)
|
|
|
|
*/
|
2020-05-19 13:58:09 +00:00
|
|
|
// Cost = 6 NAND Gates
|
|
|
|
// TODO: Improve this
|
2020-05-19 12:42:52 +00:00
|
|
|
|
|
|
|
CHIP Xor {
|
|
|
|
IN a, b;
|
|
|
|
OUT out;
|
|
|
|
|
|
|
|
PARTS:
|
2020-05-19 12:56:05 +00:00
|
|
|
Nand(a=a, b=b, out=w);
|
|
|
|
Or(a=a, b=b, out=x);
|
|
|
|
And(a=x, b=w, out=out);
|
|
|
|
}
|