Thursday, November 22, 2012

Boolean Logic : Activity 16

Activity 16 : Build an 8 WAY DMUX



WILL SOON PUBLISH NOTES ON THIS !!


/**

 * 8-way demultiplexor.
 * {a,b,c,d,e,f,g,h} = {in,0,0,0,0,0,0,0} if sel==000
 *                     {0,in,0,0,0,0,0,0} if sel==001
 *                     etc.
 *                     {0,0,0,0,0,0,0,in} if sel==111
 */


CHIP DMux8Way {
    IN in, sel[3];
    OUT a, b, c, d, e, f, g, h;

    PARTS:
    // Put your code here.
DMux(in=in, sel=sel[2], a=w1, b=w2);

DMux(in=w1, sel=sel[1], a=w3, b=w4);
DMux(in=w2, sel=sel[1], a=w5, b=w6);

DMux(in=w3, sel=sel[0], a=a, b=b);
DMux(in=w4, sel=sel[0], a=c, b=d);
DMux(in=w5, sel=sel[0], a=e, b=f);
DMux(in=w6, sel=sel[0], a=g, b=h);


}



Downloads :

Boolean Logic : Activity 15

Activity 15 : Build a 4 WAY DMUX





/**
 * 4-way demultiplexor.
 * {a,b,c,d} = {in,0,0,0} if sel==00
 *             {0,in,0,0} if sel==01
 *             {0,0,in,0} if sel==10
 *             {0,0,0,in} if sel==11
 */


CHIP DMux4Way {


    IN in, sel[2];

    OUT a, b, c, d;

    PARTS:
    // Put your code here.
    Not(in=sel[0], out=nots1);
    Not(in=sel[1], out=nots2);
    And(a=sel[0], b=sel[0], out=s1);
    And(a=sel[1], b=sel[1], out=s2);



    And(a=nots1, b=nots2, out=a1);
    And(a=nots1, b=s2, out=b1);
    And(a=s1, b=nots2, out=c1);
    And(a=s1, b=s2, out=d1);

    And(a=a1, b=in, out=a);
    And(a=b1, b=in, out=c);
    And(a=c1, b=in, out=b);
    And(a=d1, b=in, out=d);




}

////////////////////////////////////
00-a,
01-b, 
10-c, 
11-d 
where ordering is sel[1]sel[0]..  (After 20 mins of hovering over DMUX diagram) 


Can I use DMUX to make this ??
Using DMUX >


/**
 * 4-way demultiplexor.
 * {a,b,c,d} = {in,0,0,0} if sel==00
 *             {0,in,0,0} if sel==01
 *             {0,0,in,0} if sel==10
 *             {0,0,0,in} if sel==11
 */


CHIP DMux4Way {


    IN in, sel[2];

    OUT a, b, c, d;

    PARTS:
    // Put your code here.
DMux(in=in, sel=sel[1], a=w1, b=w2);
DMux(in=w1, sel=sel[0], a=a, b=b);
DMux(in=w2, sel=sel[0], a=c, b=d);

}





Downloads :




Wednesday, November 21, 2012

Boolean Logic : Activity 14

Activity 14 : Build 16 bit / 8 WAY MUX using the gates previously built




/**
 * 8-way 16-bit multiplexor.
 * out = a if sel==000
 *       b if sel==001
 *       etc.
 *       h if sel==111
 */


CHIP Mux8Way16 {
    IN a[16], b[16], c[16], d[16],
       e[16], f[16], g[16], h[16],
       sel[3];
    OUT out[16];

    PARTS:
    // Put your code here.
Mux16(a=a,b=b,sel=sel[0],out=selab);
Mux16(a=c,b=d,sel=sel[0],out=selcd);
Mux16(a=e,b=f,sel=sel[0],out=selef);
Mux16(a=g,b=h,sel=sel[0],out=selgh);
Mux16(a=selab,b=selcd,sel=sel[1],out=selabcd);
Mux16(a=selef,b=selgh,sel=sel[1],out=selefgh);
Mux16(a=selabcd,b=selefgh,sel=sel[2],out=out);
}



Downloads :

Boolean Logic : Activity 13

Activity 13 : Build 16 bit / 4 WAY MUX using the gates previously built





// 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/Mux4Way16.hdl

/**
 * 4-way 16-bit multiplexor.
 * out = a if sel==00
 *       b if sel==01
 *       c if sel==10
 *       d if sel==11
 */


CHIP Mux4Way16 {


    IN a[16], b[16], c[16], d[16], sel[2];

    OUT out[16];

    PARTS:
    // Put your code here.


Mux16(a=a, b=b, sel=sel[0], out=w1);
Mux16(a=c, b=d, sel=sel[0], out=w2);
Mux16(a=w1, b=w2, sel=sel[1], out=out);


}




Downloads :


Boolean Logic : Activity 12

Activity 12 : Build 8 WAY OR using any of the gates previously built


Yes, it says 8 Way OR and not 8 bit..
la la la.. open the book !!






/**
 * 8-way or gate: out = in[0] or in[1] or ... or in[7].
 */

CHIP Or8Way {
    IN in[8];
    OUT out;

    PARTS:
    // Put your code here.
Or(a=in[0], b=in[1], out=p0);
Or(a=p0, b=in[2], out=p1);
Or(a=p1, b=in[3], out=p2);
Or(a=p2, b=in[4], out=p3);
Or(a=p3, b=in[5], out=p4);
Or(a=p4, b=in[6], out=p5);
Or(a=p5, b=in[7], out=out);

}



////////////////////////////////

Downloads :
activity 12


Boolean Logic : Activity 11

Activity 11 : Build 16 bit Mux using (NAND, AND, OR, XOR, MUX, DMUX, 16-AND, 16-OR, 16-NOT)


hmm.. boring !!



/**
 * 16 bit multiplexor. If sel==1 then out=b else out=a.
 */

CHIP Mux16 {
    IN a[16], b[16], sel;
    OUT out[16];

    PARTS:
    // Put your code here.
Mux(a=a[0], b=b[0], sel=sel, out=out[0]);
Mux(a=a[1], b=b[1], sel=sel, out=out[1]);
Mux(a=a[2], b=b[2], sel=sel, out=out[2]);
Mux(a=a[3], b=b[3], sel=sel, out=out[3]);
Mux(a=a[4], b=b[4], sel=sel, out=out[4]);
Mux(a=a[5], b=b[5], sel=sel, out=out[5]);
Mux(a=a[6], b=b[6], sel=sel, out=out[6]);
Mux(a=a[7], b=b[7], sel=sel, out=out[7]);
Mux(a=a[8], b=b[8], sel=sel, out=out[8]);
Mux(a=a[9], b=b[9], sel=sel, out=out[9]);
Mux(a=a[10], b=b[10], sel=sel, out=out[10]);
Mux(a=a[11], b=b[11], sel=sel, out=out[11]);
Mux(a=a[12], b=b[12], sel=sel, out=out[12]);
Mux(a=a[13], b=b[13], sel=sel, out=out[13]);
Mux(a=a[14], b=b[14], sel=sel, out=out[14]);
Mux(a=a[15], b=b[15], sel=sel, out=out[15]);
}


Downloads :

Boolean Logic : Activity 10

Activity 10 : Build 16 bit OR using (NAND, AND, XOR, OR, MUX, DMUX)


You can do this using only Or; the below solution is by using only Nand..
If you read the previous solutions, you really wont be checking this out !! ;)



/**
 * 16-bit bitwise Or gate: for i=0..15 out[i] = a[i] or b[i].
 */

CHIP Or16 {
    IN a[16], b[16];
    OUT out[16];

    PARTS:
    // Put your code here.

Nand(a=a[0], b=a[0], out=p0);
Nand(a=a[1], b=a[1], out=p1);
Nand(a=a[2], b=a[2], out=p2);
Nand(a=a[3], b=a[3], out=p3);
Nand(a=a[4], b=a[4], out=p4);
Nand(a=a[5], b=a[5], out=p5);
Nand(a=a[6], b=a[6], out=p6);
Nand(a=a[7], b=a[7], out=p7);
Nand(a=a[8], b=a[8], out=p8);
Nand(a=a[9], b=a[9], out=p9);
Nand(a=a[10], b=a[10], out=p10);
Nand(a=a[11], b=a[11], out=p11);
Nand(a=a[12], b=a[12], out=p12);
Nand(a=a[13], b=a[13], out=p13);
Nand(a=a[14], b=a[14], out=p14);
Nand(a=a[15], b=a[15], out=p15);


Nand(a=b[0], b=b[0], out=q0);
Nand(a=b[1], b=b[1], out=q1);
Nand(a=b[2], b=b[2], out=q2);
Nand(a=b[3], b=b[3], out=q3);
Nand(a=b[4], b=b[4], out=q4);
Nand(a=b[5], b=b[5], out=q5);
Nand(a=b[6], b=b[6], out=q6);
Nand(a=b[7], b=b[7], out=q7);
Nand(a=b[8], b=b[8], out=q8);
Nand(a=b[9], b=b[9], out=q9);
Nand(a=b[10], b=b[10], out=q10);
Nand(a=b[11], b=b[11], out=q11);
Nand(a=b[12], b=b[12], out=q12);
Nand(a=b[13], b=b[13], out=q13);
Nand(a=b[14], b=b[14], out=q14);
Nand(a=b[15], b=b[15], out=q15);



Nand(a=p0, b=q0, out=out[0]);
Nand(a=p1, b=q1, out=out[1]);
Nand(a=p2, b=q2, out=out[2]);
Nand(a=p3, b=q3, out=out[3]);
Nand(a=p4, b=q4, out=out[4]);
Nand(a=p5, b=q5, out=out[5]);
Nand(a=p6, b=q6, out=out[6]);
Nand(a=p7, b=q7, out=out[7]);
Nand(a=p8, b=q8, out=out[8]);
Nand(a=p9, b=q9, out=out[9]);
Nand(a=p10, b=q10, out=out[10]);
Nand(a=p11, b=q11, out=out[11]);
Nand(a=p12, b=q12, out=out[12]);
Nand(a=p13, b=q13, out=out[13]);
Nand(a=p14, b=q14, out=out[14]);
Nand(a=p15, b=q15, out=out[15]);

}

////////////////////////////////////////////////////////

Wanted to make use of Mux which I did, but dha !! I am using Or too




/**
 * 16-bit bitwise Or gate: for i=0..15 out[i] = a[i] or b[i].
 */

CHIP Or16 {
    IN a[16], b[16];
    OUT out[16];

    PARTS:
    // Put your code here.

Mux(a=a[0], b=b[0], out=w0);
Mux(a=a[1], b=b[1], out=w1);
Mux(a=a[2], b=b[2], out=w2);
Mux(a=a[3], b=b[3], out=w3);
Mux(a=a[4], b=b[4], out=w4);
Mux(a=a[5], b=b[5], out=w5);
Mux(a=a[6], b=b[6], out=w6);
Mux(a=a[7], b=b[7], out=w7);
Mux(a=a[8], b=b[8], out=w8);
Mux(a=a[9], b=b[9], out=w9);
Mux(a=a[10], b=b[10], out=w10);
Mux(a=a[11], b=b[11], out=w11);
Mux(a=a[12], b=b[12], out=w12);
Mux(a=a[13], b=b[13], out=w13);
Mux(a=a[14], b=b[14], out=w14);
Mux(a=a[15], b=b[15], out=w15);



Or(a=a[0], b=w0, out=p0);
Or(a=a[1], b=w1, out=p1);
Or(a=a[2], b=w2, out=p2);
Or(a=a[3], b=w3, out=p3);
Or(a=a[4], b=w4, out=p4);
Or(a=a[5], b=w5, out=p5);
Or(a=a[6], b=w6, out=p6);
Or(a=a[7], b=w7, out=p7);
Or(a=a[8], b=w8, out=p8);
Or(a=a[9], b=w9, out=p9);
Or(a=a[10], b=w10, out=p10);
Or(a=a[11], b=w11, out=p11);
Or(a=a[12], b=w12, out=p12);
Or(a=a[13], b=w13, out=p13);
Or(a=a[14], b=w14, out=p14);
Or(a=a[15], b=w15, out=p15);



Or(a=b[0], b=p0, out=out[0]);
Or(a=b[1], b=p1, out=out[1]);
Or(a=b[2], b=p2, out=out[2]);
Or(a=b[3], b=p3, out=out[3]);
Or(a=b[4], b=p4, out=out[4]);
Or(a=b[5], b=p5, out=out[5]);
Or(a=b[6], b=p6, out=out[6]);
Or(a=b[7], b=p7, out=out[7]);
Or(a=b[8], b=p8, out=out[8]);
Or(a=b[9], b=p9, out=out[9]);
Or(a=b[10], b=p10, out=out[10]);
Or(a=b[11], b=p11, out=out[11]);
Or(a=b[12], b=p12, out=out[12]);
Or(a=b[13], b=p13, out=out[13]);
Or(a=b[14], b=p14, out=out[14]);
Or(a=b[15], b=p15, out=out[15]);

}

eeks.. better to use only Or.. but just wanted to write Mux :)
Did you notice? I didn't write sel in the Mux definition and it worked perfectly !!



Downloads :
activity 10 | using Nand
activity 10 | using Mux and Or

Boolean Logic : Activity 9

Activity 9 : Build 16 bit AND using (NAND, AND , OR, XOR, MUX, DMUX)


and again and again ;)



/**
 * 16-bit-wise and gate: for i = 0..15: out[i] = a[i] and b[i]
 */

CHIP And16 {
    IN a[16], b[16];
    OUT out[16];

    PARTS:
    // Put your code here.
And(a=a[0], b=b[0], out=out[0]);
And(a=a[1], b=b[1], out=out[1]);
And(a=a[2], b=b[2], out=out[2]);
And(a=a[3], b=b[3], out=out[3]);
And(a=a[4], b=b[4], out=out[4]);
And(a=a[5], b=b[5], out=out[5]);
And(a=a[6], b=b[6], out=out[6]);
And(a=a[7], b=b[7], out=out[7]);
And(a=a[8], b=b[8], out=out[8]);
And(a=a[9], b=b[9], out=out[9]);
And(a=a[10], b=b[10], out=out[10]);
And(a=a[11], b=b[11], out=out[11]);
And(a=a[12], b=b[12], out=out[12]);
And(a=a[13], b=b[13], out=out[13]);
And(a=a[14], b=b[14], out=out[14]);
And(a=a[15], b=b[15], out=out[15]);
}


/////////////////////////////////////////////

Now backtracking to represent it in Nand only :




/**
 * 16-bit-wise and gate: for i = 0..15: out[i] = a[i] and b[i]
 */

CHIP And16 {
    IN a[16], b[16];
    OUT out[16];

    PARTS:
    // Put your code here.

Nand(a=a[0], b=b[0], out=p0);
Nand(a=a[1], b=b[1], out=p1);
Nand(a=a[2], b=b[2], out=p2);
Nand(a=a[3], b=b[3], out=p3);
Nand(a=a[4], b=b[4], out=p4);
Nand(a=a[5], b=b[5], out=p5);
Nand(a=a[6], b=b[6], out=p6);
Nand(a=a[7], b=b[7], out=p7);
Nand(a=a[8], b=b[8], out=p8);
Nand(a=a[9], b=b[9], out=p9);
Nand(a=a[10], b=b[10], out=p10);
Nand(a=a[11], b=b[11], out=p11);
Nand(a=a[12], b=b[12], out=p12);
Nand(a=a[13], b=b[13], out=p13);
Nand(a=a[14], b=b[14], out=p14);
Nand(a=a[15], b=b[15], out=p15);

Nand(a=p0, b=p0, out=out[0]);
Nand(a=p1, b=p1, out=out[1]);
Nand(a=p2, b=p2, out=out[2]);
Nand(a=p3, b=p3, out=out[3]);
Nand(a=p4, b=p4, out=out[4]);
Nand(a=p5, b=p5, out=out[5]);
Nand(a=p6, b=p6, out=out[6]);
Nand(a=p7, b=p7, out=out[7]);
Nand(a=p8, b=p8, out=out[8]);
Nand(a=p9, b=p9, out=out[9]);
Nand(a=p10, b=p10, out=out[10]);
Nand(a=p11, b=p11, out=out[11]);
Nand(a=p12, b=p12, out=out[12]);
Nand(a=p13, b=p13, out=out[13]);
Nand(a=p14, b=p14, out=out[14]);
Nand(a=p15, b=p15, out=out[15]);

}





Downloads :
activity 9
activity 9 | using Nand

Boolean Logic : Activity 8

Activity 8 : Build 16 bit NOT using (NAND, AND, OR, XOR, MUX, DMUX)



The simplest solution to this :
using NOT >


/**

 * 16-bit Not gate: for i=0..15: out[i] = not in[i]
 */

CHIP Not16 {
    IN in[16];
    OUT out[16];

    PARTS:
Not(in=in[0], out=out[0]);
Not(in=in[1], out=out[1]);
Not(in=in[2], out=out[2]);
Not(in=in[3], out=out[3]);
Not(in=in[4], out=out[4]);
Not(in=in[5], out=out[5]);
Not(in=in[6], out=out[6]);
Not(in=in[7], out=out[7]);
Not(in=in[8], out=out[8]);
Not(in=in[9], out=out[9]);
Not(in=in[10], out=out[10]);
Not(in=in[11], out=out[11]);
Not(in=in[12], out=out[12]);
Not(in=in[13], out=out[13]);
Not(in=in[14], out=out[14]);
Not(in=in[15], out=out[15]);
}


//////////////////////////////////////////////
You really dont want to type so much; what you can do is use your fav prog lang to get this as o/p :

        for(int i=0; i<=15; i++){
            System.out.println("Not(in=in[" + i + "], out=out[" + i + "]);");
        }



Hey, how about we use Nand to solve this !!
using Nand >



/**
 * 16-bit Not gate: for i=0..15: out[i] = not in[i]
 */

CHIP Not16 {
    IN in[16];
    OUT out[16];

    PARTS:
Nand(a=in[0], b=in[0], out=out[0]);
Nand(a=in[1], b=in[1], out=out[1]);
Nand(a=in[2], b=in[2], out=out[2]);
Nand(a=in[3], b=in[3], out=out[3]);
Nand(a=in[4], b=in[4], out=out[4]);
Nand(a=in[5], b=in[5], out=out[5]);
Nand(a=in[6], b=in[6], out=out[6]);
Nand(a=in[7], b=in[7], out=out[7]);
Nand(a=in[8], b=in[8], out=out[8]);
Nand(a=in[9], b=in[9], out=out[9]);
Nand(a=in[10], b=in[10], out=out[10]);
Nand(a=in[11], b=in[11], out=out[11]);
Nand(a=in[12], b=in[12], out=out[12]);
Nand(a=in[13], b=in[13], out=out[13]);
Nand(a=in[14], b=in[14], out=out[14]);
Nand(a=in[15], b=in[15], out=out[15]);


}


//////////////////////////////////////////////////

Trying to use Mux; here I learnt that we cannot create array variables like w[0], w[1].. 
using Mux >



/**
 * 16-bit Not gate: for i=0..15: out[i] = not in[i]
 */

CHIP Not16 {
    IN in[16];
    OUT out[16];

    PARTS:
Mux(a=in[0], b=in[0], out=w0);
Mux(a=in[1], b=in[1], out=w1);
Mux(a=in[2], b=in[2], out=w2);
Mux(a=in[3], b=in[3], out=w3);
Mux(a=in[4], b=in[4], out=w4);
Mux(a=in[5], b=in[5], out=w5);
Mux(a=in[6], b=in[6], out=w6);
Mux(a=in[7], b=in[7], out=w7);
Mux(a=in[8], b=in[8], out=w8);
Mux(a=in[9], b=in[9], out=w9);
Mux(a=in[10], b=in[10], out=w10);
Mux(a=in[11], b=in[11], out=w11);
Mux(a=in[12], b=in[12], out=w12);
Mux(a=in[13], b=in[13], out=w13);
Mux(a=in[14], b=in[14], out=w14);
Mux(a=in[15], b=in[15], out=w15);


Nand(a=w0, b=w0, out=out[0]);
Nand(a=w1, b=w1, out=out[1]);
Nand(a=w2, b=w2, out=out[2]);
Nand(a=w3, b=w3, out=out[3]);
Nand(a=w4, b=w4, out=out[4]);
Nand(a=w5, b=w5, out=out[5]);
Nand(a=w6, b=w6, out=out[6]);
Nand(a=w7, b=w7, out=out[7]);
Nand(a=w8, b=w8, out=out[8]);
Nand(a=w9, b=w9, out=out[9]);
Nand(a=w10, b=w10, out=out[10]);
Nand(a=w11, b=w11, out=out[11]);
Nand(a=w12, b=w12, out=out[12]);
Nand(a=w13, b=w13, out=out[13]);
Nand(a=w14, b=w14, out=out[14]);
Nand(a=w15, b=w15, out=out[15]);


}


////////////////////////////////////////////////////////

We can always substitute chip definitions, the expressions for which we found in earlier activities



Downloads :
activity 8 | using not
activity 8 | using Nand
activity 8 | using mux

Tuesday, November 20, 2012

Boolean Logic : Activity 7

Activity 7 : Build DMUX by using (NAND, OR, AND, NOT, MUX)


/**

 * Dmultiplexor.  
 * {a,b} = {in,0} if sel==0
 *         {0,in} if sel==1
 */


CHIP DMux {
    IN in, sel;
    OUT a, b;

    PARTS:
    // Put your code here.
    Not(in=sel, out=notsel);

    And(a=in, b=notsel, out=a);
    And(a=in, b=sel, out=b);
}



/////////////////////////////////
This should be a piece of cake !!




Downloads :
 activity 7

Boolean Logic : Activity 6

Activity 6 : Build MUX by using (NAND, OR, AND, NOT)


Write truth table -> canonical form 







/**
 * Multiplexor. If sel==1 then out=b else out=a.
 */

CHIP Mux {
    IN a, b, sel;
    OUT out;

    PARTS:
    // Put your code here.
    Not(in=a, out=nota);
    Not(in=b, out=notb);
    Not(in=sel, out=notsel);


    And(a=nota, b=b, out=a1);
    And(a=a, b=b, out=a2);
    Or(a=a1, b=a2, out=o1);
    And(a=sel, b=o1, out=p1);

    And(a=a, b=notb, out=a3);
    Or(a=a2, b=a3, out=o2);
    And(a=notsel, b=o2, out=p2);


    Or(a=p1, b=p2, out=out);
}


On simplifying further :
way 2 >



/** 
 * Multiplexor. If sel==1 then out=b else out=a.
 */

CHIP Mux {
    IN a, b, sel;
    OUT out;

    PARTS:
    // Put your code here.
    Not(in=a, out=nota);
    Not(in=b, out=notb);
    Not(in=sel, out=notsel);


    And(a=a, b=b, out=a3);

    And(a=nota, b=b, out=t1);
    And(a=t1, b=sel, out=a1);

    And(a=a, b=notb, out=t2);
    And(a=t2, b=notsel, out=a2);

    Or(a=a1, b=a2, out=o1);
    Or(a=o1, b=a3, out=out);

}

Both the above solutions were built sequentially. Now its time to shorten it.. 
way 3>



/** 
 * Multiplexor. If sel==1 then out=b else out=a.
 */

CHIP Mux {
    IN a, b, sel;
    OUT out;

    PARTS:
    // Put your code here.
    Not(in=sel, out=notsel);
    And(a=a, b=notsel, out=w1);
    And(a=b, b=sel, out=w2);
    Or(a=w1, b=w2, out=out);
}





Downloads : 


Boolean Logic : Activity 5

Activity 5 : Build XOR from primitive NAND



// 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 == b).
 */

CHIP Xor {

    IN a, b;
    OUT out;

    PARTS:
    // Put your code here.
    Nand(a=a, b=a, out=nota);
    Nand(a=b, b=b, out=notb);

    Nand(a=a, b=notb, out=w1);
    Nand(a=w1, b=w1, out=a1);

    Nand(a=nota, b=b, out=w2);
    Nand(a=w2, b=w2, out=a2);


    Nand(a=a1, b=a1, out=p1);
    Nand(a=a2, b=a2, out=p2);
    Nand(a=p1, b=p2, out=out);

    
}

////////////////////////////////////////////////////

hmm.. so what we do is make truth table - write canonical rep - and replace the and, or and not def with those of nand which we found out in previous activities.

truth table -> canonical form -> substitute nand def






Downloads : 



Boolean Logic : Activity 4

Activity 4 : Build OR from primitive NAND




// 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/Or.hdl


/**
 * Or gate: out = 1 if {a==1 or b==1}, 0 otherwise
 */

CHIP Or {
    IN a, b;
    OUT out;

    PARTS:
    // Put your code here.
    Nand(a=a, b=a, out=w1);
    Nand(a=b, b=b, out=w2);
    Nand(a=w1, b=w2, out=out);
}




//////////////////////////////////////////////////////
Well, I just made truth tables for basic gates and saw that Nand of nota and notb matched that of or.
So this solution was out of observation. Please share if this can be done logically.


Downloads :

Boolean Logic : Activity 3

Activity 3 : Build AND from primitive NAND




// 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/And.hdl

/**
 * And gate: out = 1 if {a==1 and b==1}, 0 otherwise
 */

CHIP And {
    IN a, b;
    OUT out;

    PARTS:
    // Put your code here.
    //Nand(a='Nand(a=a, b=b, out=w1)', b='Nand(a=a, b=b, out=w2)', out=out);
    Nand(a=a, b=b, out=w1);
    Nand(a=w1, b=w1, out=out);
}


////////////////////////////////////////////////////////////////
Another way would be :
Nand(a=a, b=b, out=w1);
Not(in=w1, out=out);


I wonder although if we could write it as Nand(a=Nand(a=a, b=b, out=w1), b=Nand(a=a, b=b, out=w2), out=out);
Am I missing something ??




Downloads:

Boolean Logic : Activity 2 (with summary of ch-1)

DISCLAIMER: Meant to be read during coffee breaks as a summary // Author is not responsible for your frustration

chips - made of logic gates
and chips make up almost everything in computing science.

logic gates run on 0s and 1s - what we call as boolean and getting fidgetive with it called as boolean algebra.
Next, boolean functions operate on boolean i/p to give boolean o/p.

Truth table : we see all combinations of i/ps and their o/ps. From this we can form canonical representation.
This in turn proves that any boolean function can be formed out of 'And', "Or' and 'Not'.

Then we check out many boolean functions - And, Not, Constant, Equivalence, If then, Xor, Or, Nand, Nor.....
Nand function has an interesting property : And, Or and Not can be constructed from it. If you notice what we said about canonical representation, this means we can construct any boolean function from Nand alone.

Then we moved with gate symbols, interface and implementation.

Multiplexor (nick name: mux) has an extra i/p bit called selector to o/p one of the i/ps depending on the selector/selection-bit.
Demultiplexor (demux) is just the other way around.. the selection bit decides which o/p bit should give the i/p value as the o/p.

The project is meant to simplify our logic about the boolean logic :)


Activity 2 : Building NOT from primitive NAND


This goes in the .hdl file
// 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/Not.hdl

/**
 * Not gate: out = not in
 */

CHIP Not {
    IN in;
    OUT out;

    PARTS:
    // Put your code here.
    Nand(a=in, b=in, out=out);
}


Downloads:

Boolean Logic : Activity 1

0s and 1s can make you kneel on your knees or raise your head high !! A dive into the binary world from scratch..

For the lucky ones out there : Elements of Computing Systems (we all are lucky here ;) )

You can buy this book from here
Download TECS h/w simulator  here and read part I, II, III in this tutorial

Thanks to  Professor Shimon Schocken and Professor Noam Nisan for making everything available online and making it simple for us.


You may want to visit the Q/A forum