Login  Register

Re: Chip has a circle in it's parts? Xor.hdl issues

Posted by WBahn on Dec 11, 2020; 8:38pm
URL: http://nand2tetris-questions-and-answers-forum.52.s1.nabble.com/Chip-has-a-circle-in-it-s-parts-Xor-hdl-issues-tp4035304p4035306.html

Zhme wrote
I am getting an error "This chip has a circle in it's parts connections: load Xor.hdl".

My code:

CHIP Xor {
    IN a, b;
    OUT out;

    PARTS:
    Nand(a=a, b=a, out=outa);
    Nand(a=b, b=b, out=outb);
    Nand(a=a, b=notb, out=outanda);
    Nand(a=nota, b=b, out=outandb);
    Nand(a=outanda, b=outanda, out=nota);
    Nand(a=outandb, b=outandb, out=notb);
    Nand(a=nota, b=notb, out=out);
}

I assumed that, noting the title of the course, we should attempt to write each basic gate from a flow built with nand gates alone.

After seeing this error message I wonder if maybe I just needed to see how the most basic of gates could be built with nand alone, and to use the gates that I've built to slowly build more advanced gates?

I wonder if the reason for my error is that I assigned the initial inputs in more than one location? If so, how would I remedy this error and still use this convoluted approach? Thank you in advance for any support given!
A "circle" means that two signals are dependent on each other. The simulator can't handle that situation.

In other words, Fred depends on Sue and Sue depends on Joe, but if Joe depends on Fred, then there is a circle and Fred depends on Fred.

One way to see this is to draw the schematic of the circuit described by your HDL code.

Another way is to list the dependencies for each signal.

out: {nota, notb}

nota: {outanda}
notb: {outandb}

outanda: {a, notb}
outandb: {nota, b}

nota: {outanda}
notb: {outandb}

So nota depends on outanda, outanda depends on notb, notb depends on outandb, and outandb depends on nota. The result is that nota depends on nota.

The circle is (nota -> outandb -> notb -> outanda -> nota)