Login  Register

Xor not working

Posted by Anirudh on Dec 18, 2010; 6:36am
URL: http://nand2tetris-questions-and-answers-forum.52.s1.nabble.com/Xor-not-working-tp2109401.html

Hi,

I am using Windows7.  I tried to test my Xor script(below)

// This file is part of the materials accompanying the book
// "The Elements of Computing Systems" by Nisan and Schocken,
// MIT Press. Book site: www.idc.ac.il/tecs
// File name: projects/01/Xor.hdl

/**
 *  Exclusive-or gate.  out = a xor b.
 */
CHIP Xor {
    IN  a, b;
    OUT out;
    PARTS:
    Not(in=a,out=nota);
    Not(in=b,out=notb);
    And(a=a,b=notb,out=w1);
    And(a=nota,b=b,out=w2);
    Or(a=w1,b=w2,out=out);
}

In the testing process, it runs fine for a=0 and b=0 with out=0. But when a=0 and b=1, the out=0 and it says 'Comparison Failure at line 3. The above code is exactly the same as given in the tutorial pdf. What am I doing wrong here?

Thanks
Anirudh