Wednesday, November 21, 2012

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

No comments:

Post a Comment