I’m curious to see how other people are solving the exercises in the book. My current workflow is to write out some pseudocode on paper and pass zeros and ones through it, adjusting things until it works. I’m not sure that I like my solutions. I like @Dan’s illustrations on Github, but for some reason my brain has trouble solving the exercises that way. Maybe I’m missing a step or some way of thinking about it.
Example workflow:
Click to show Xor gate (contains code for book exercises)
I start tinkering with something like this:
Xor = Not(And(Nand(Not(a), b), Nand(a, Not(b))))
Then translate it to the HDL:
CHIP Xor {
IN a, b;
OUT out;
PARTS:
Not(in=a, out=nota);
Not(in=b, out=notb);
Nand(a=nota, b=b, out=c);
Nand(a=a, b=notb, out=d);
And(a=c, b=d, out=e);
Not(in=e, out=out);
}
I’m wondering if there is a good way to simplify the expressions or find a better workflow for solving them. Another solution for Xor that I looked at uses only three gates, so I can see that my answer is twice as long as it could be.
A 3-gate solution (contains code for book exercises)
I saw this online:
CHIP Xor {
IN a, b;
OUT out;
PARTS:
Or(a=a, b=b, out=c1);
Nand(a=a, b=b, out=c2);
And(a=c1, b=c2, out=out);
}
There may not be a simple answer to my question, and it could be that I just need to practice building more gates, but I would like to be able to figure out how to get my brain to think about the problems more clearly, possibly starting from illustrations. 