2016年1月29日金曜日

開発環境

  • OS X El Capitan - Apple (OS)
  • Emacs(Text Editor)
  • Java (実行環境)

コンピュータシステムの理論と実装 (Noam Nisan (著)、Shimon Schocken (著)、斎藤 康毅(翻訳)、オライリージャパン)の1章(ブール論理)、1.5(プロジェクト(1.2.4(多入力の基本ゲート、多入力Or、多入力/多ビットマルチプレクサ、多出力/多ビットデマルチプレクサ))を取り組んでみる。

1.5(プロジェクト)

コード(Emacs)

Or8.hdl

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

    PARTS:
    Or(a=in[0], b=in[1], out=w1);
    Or(a=w1, b=in[2], out=w2);
    Or(a=w2, b=in[3], out=w3);
    Or(a=w3, b=in[4], out=w4);
    Or(a=w4, b=in[5], out=w5);
    Or(a=w5, b=in[6], out=w6);
    Or(a=w6, b=in[7], out=out);
}

Mux4Way16.hdl

CHIP Mux4Way16 {
    IN a[16], b[16], c[16], d[16], sel[2];
    OUT out[16];

    PARTS:
    Or(a=sel[0], b=sel[1], out=a1);
    Not(in=a1, out=a2);
    
    And(a=a2, b=a[0], out=aout0);
    And(a=a2, b=a[1], out=aout1);
    And(a=a2, b=a[2], out=aout2);
    And(a=a2, b=a[3], out=aout3);
    And(a=a2, b=a[4], out=aout4);
    And(a=a2, b=a[5], out=aout5);
    And(a=a2, b=a[6], out=aout6);
    And(a=a2, b=a[7], out=aout7);
    And(a=a2, b=a[8], out=aout8);
    And(a=a2, b=a[9], out=aout9);
    And(a=a2, b=a[10], out=aout10);
    And(a=a2, b=a[11], out=aout11);
    And(a=a2, b=a[12], out=aout12);
    And(a=a2, b=a[13], out=aout13);
    And(a=a2, b=a[14], out=aout14);
    And(a=a2, b=a[15], out=aout15);

    Not(in=sel[1], out=b1);
    And(a=b1, b=sel[0], out=b2);
    And(a=b2, b=b[0], out=bout0);
    And(a=b2, b=b[1], out=bout1);
    And(a=b2, b=b[2], out=bout2);
    And(a=b2, b=b[3], out=bout3);
    And(a=b2, b=b[4], out=bout4);
    And(a=b2, b=b[5], out=bout5);
    And(a=b2, b=b[6], out=bout6);
    And(a=b2, b=b[7], out=bout7);
    And(a=b2, b=b[8], out=bout8);
    And(a=b2, b=b[9], out=bout9);
    And(a=b2, b=b[10], out=bout10);
    And(a=b2, b=b[11], out=bout11);
    And(a=b2, b=b[12], out=bout12);
    And(a=b2, b=b[13], out=bout13);
    And(a=b2, b=b[14], out=bout14);
    And(a=b2, b=b[15], out=bout15);

    Not(in=sel[0], out=c1);
    And(a=c1, b=sel[1], out=c2);
    And(a=c2, b=c[0], out=cout0);
    And(a=c2, b=c[1], out=cout1);
    And(a=c2, b=c[2], out=cout2);
    And(a=c2, b=c[3], out=cout3);
    And(a=c2, b=c[4], out=cout4);
    And(a=c2, b=c[5], out=cout5);
    And(a=c2, b=c[6], out=cout6);
    And(a=c2, b=c[7], out=cout7);
    And(a=c2, b=c[8], out=cout8);
    And(a=c2, b=c[9], out=cout9);
    And(a=c2, b=c[10], out=cout10);
    And(a=c2, b=c[11], out=cout11);
    And(a=c2, b=c[12], out=cout12);
    And(a=c2, b=c[13], out=cout13);
    And(a=c2, b=c[14], out=cout14);
    And(a=c2, b=c[15], out=cout15);    

    And(a=sel[0], b=sel[1], out=d1);
    And(a=d1, b=d[0], out=dout0);
    And(a=d1, b=d[1], out=dout1);
    And(a=d1, b=d[2], out=dout2);
    And(a=d1, b=d[3], out=dout3);
    And(a=d1, b=d[4], out=dout4);
    And(a=d1, b=d[5], out=dout5);
    And(a=d1, b=d[6], out=dout6);
    And(a=d1, b=d[7], out=dout7);
    And(a=d1, b=d[8], out=dout8);
    And(a=d1, b=d[9], out=dout9);
    And(a=d1, b=d[10], out=dout10);
    And(a=d1, b=d[11], out=dout11);
    And(a=d1, b=d[12], out=dout12);
    And(a=d1, b=d[13], out=dout13);
    And(a=d1, b=d[14], out=dout14);
    And(a=d1, b=d[15], out=dout15);

    Or16(a[0]=aout0,
         a[1]=aout1,
         a[2]=aout2,
         a[3]=aout3,
         a[4]=aout4,
         a[5]=aout5,
         a[6]=aout6,
         a[7]=aout7,
         a[8]=aout8,
         a[9]=aout9,
         a[10]=aout10,
         a[11]=aout11,
         a[12]=aout12,
         a[13]=aout13,
         a[14]=aout14,
         a[15]=aout15,
         b[0]=bout0,
         b[1]=bout1,
         b[2]=bout2,
         b[3]=bout3,
         b[4]=bout4,
         b[5]=bout5,
         b[6]=bout6,
         b[7]=bout7,
         b[8]=bout8,
         b[9]=bout9,
         b[10]=bout10,
         b[11]=bout11,
         b[12]=bout12,
         b[13]=bout13,
         b[14]=bout14,
         b[15]=bout15,
         out=out1);
    Or16(a=out1,
         b[0]=cout0,
         b[1]=cout1,
         b[2]=cout2,
         b[3]=cout3,
         b[4]=cout4,
         b[5]=cout5,
         b[6]=cout6,
         b[7]=cout7,
         b[8]=cout8,
         b[9]=cout9,
         b[10]=cout10,
         b[11]=cout11,
         b[12]=cout12,
         b[13]=cout13,
         b[14]=cout14,
         b[15]=cout15,
         out=out2);
    Or16(a=out2,
         b[0]=dout0,
         b[1]=dout1,
         b[2]=dout2,
         b[3]=dout3,
         b[4]=dout4,
         b[5]=dout5,
         b[6]=dout6,
         b[7]=dout7,
         b[8]=dout8,
         b[9]=dout9,
         b[10]=dout10,
         b[11]=dout11,
         b[12]=dout12,
         b[13]=dout13,
         b[14]=dout14,
         b[15]=dout15,
         out=out);
}

Mux8Way16.hdl

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:
    Not(in=sel[0], out=asel0not);
    Not(in=sel[1], out=asel1not);
    Not(in=sel[2], out=asel2not);
    And(a=asel0not, b=asel1not, out=a0);
    And(a=a0, b=asel2not, out=a1);

    And16(a[0]=a1,
    a[1]=a1,
    a[2]=a1,
    a[3]=a1,
    a[4]=a1,
    a[5]=a1,
    a[6]=a1,
    a[7]=a1,
    a[8]=a1,
    a[9]=a1,
    a[10]=a1,
    a[11]=a1,
    a[12]=a1,
    a[13]=a1,
    a[14]=a1,
    a[15]=a1,
    b=a, out=aout);

    Not(in=sel[1], out=bsel1not);
    Not(in=sel[2], out=bsel2not);
    And(a=sel[0], b=bsel1not, out=b0);
    And(a=b0, b=bsel2not, out=b1);

    And16(a[0]=b1,
    a[1]=b1,
    a[2]=b1,
    a[3]=b1,
    a[4]=b1,
    a[5]=b1,
    a[6]=b1,
    a[7]=b1,
    a[8]=b1,
    a[9]=b1,
    a[10]=b1,
    a[11]=b1,
    a[12]=b1,
    a[13]=b1,
    a[14]=b1,
    a[15]=b1,
    b=b, out=bout);

    Not(in=sel[0], out=csel0not);
    Not(in=sel[2], out=csel2not);
    And(a=csel0not, b=sel[1], out=c0);
    And(a=c0, b=csel2not, out=c1);

    And16(a[0]=c1,
    a[1]=c1,
    a[2]=c1,
    a[3]=c1,
    a[4]=c1,
    a[5]=c1,
    a[6]=c1,
    a[7]=c1,
    a[8]=c1,
    a[9]=c1,
    a[10]=c1,
    a[11]=c1,
    a[12]=c1,
    a[13]=c1,
    a[14]=c1,
    a[15]=c1,
    b=c, out=cout);

    Not(in=sel[2], out=dsel2not);
    And(a=sel[0], b=sel[1], out=d0);
    And(a=d0, b=dsel2not, out=d1);

    And16(a[0]=d1,
    a[1]=d1,
    a[2]=d1,
    a[3]=d1,
    a[4]=d1,
    a[5]=d1,
    a[6]=d1,
    a[7]=d1,
    a[8]=d1,
    a[9]=d1,
    a[10]=d1,
    a[11]=d1,
    a[12]=d1,
    a[13]=d1,
    a[14]=d1,
    a[15]=d1,
    b=d, out=dout);

    Not(in=sel[0], out=esel0not);
    Not(in=sel[1], out=esel1not);
    And(a=esel0not, b=esel1not, out=e0);
    And(a=e0, b=sel[2], out=e1);

    And16(a[0]=e1,
    a[1]=e1,
    a[2]=e1,
    a[3]=e1,
    a[4]=e1,
    a[5]=e1,
    a[6]=e1,
    a[7]=e1,
    a[8]=e1,
    a[9]=e1,
    a[10]=e1,
    a[11]=e1,
    a[12]=e1,
    a[13]=e1,
    a[14]=e1,
    a[15]=e1,
    b=e, out=eout);        

    Not(in=sel[1], out=fsel1not);
    And(a=sel[0], b=fsel1not, out=f0);
    And(a=f0, b=sel[2], out=f1);

    And16(a[0]=f1,
    a[1]=f1,
    a[2]=f1,
    a[3]=f1,
    a[4]=f1,
    a[5]=f1,
    a[6]=f1,
    a[7]=f1,
    a[8]=f1,
    a[9]=f1,
    a[10]=f1,
    a[11]=f1,
    a[12]=f1,
    a[13]=f1,
    a[14]=f1,
    a[15]=f1,
    b=f, out=fout);

    Not(in=sel[0], out=gsel0not);
    And(a=gsel0not, b=sel[1], out=g0);
    And(a=g0, b=sel[2], out=g1);

    And16(a[0]=g1,
    a[1]=g1,
    a[2]=g1,
    a[3]=g1,
    a[4]=g1,
    a[5]=g1,
    a[6]=g1,
    a[7]=g1,
    a[8]=g1,
    a[9]=g1,
    a[10]=g1,
    a[11]=g1,
    a[12]=g1,
    a[13]=g1,
    a[14]=g1,
    a[15]=g1,
    b=g, out=gout);

    And(a=sel[0], b=sel[1], out=h0);
    And(a=h0, b=sel[2], out=h1);

    And16(a[0]=h1,
    a[1]=h1,
    a[2]=h1,
    a[3]=h1,
    a[4]=h1,
    a[5]=h1,
    a[6]=h1,
    a[7]=h1,
    a[8]=h1,
    a[9]=h1,
    a[10]=h1,
    a[11]=h1,
    a[12]=h1,
    a[13]=h1,
    a[14]=h1,
    a[15]=h1,
    b=h, out=hout);
    
    Or16(a=aout, b=bout, out=out0);
    Or16(a=out0, b=cout, out=out1);
    Or16(a=out1, b=dout, out=out2);
    Or16(a=out2, b=eout, out=out3);
    Or16(a=out3, b=fout, out=out4);
    Or16(a=out4, b=gout, out=out5);
    Or16(a=out5, b=hout, out=out);
}

DMux4Way.hdl

CHIP DMux4Way {
    IN in, sel[2];
    OUT a, b, c, d;

    PARTS:
    Not(in=sel[0], out=notsel0);
    Not(in=sel[1], out=notsel1);
    
    And(a=notsel0, b=notsel1, out=outa);
    And(a=outa, b=in, out=a);

    And(a=sel[0], b=notsel1, out=outb);
    And(a=outb, b=in, out=b);

    And(a=notsel0, b=sel[1], out=outc);
    And(a=outc, b=in, out=c);

    And(a=sel[0], b=sel[1], out=outd);
    And(a=outd, b=in, out=d);
}

DMux8Way.hdl

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

    PARTS:
    Not(in=sel[0], out=notsel0);
    Not(in=sel[1], out=notsel1);
    Not(in=sel[2], out=notsel2);

    And(a=notsel0, b=notsel1, out=outa0);
    And(a=outa0, b=notsel2, out=outa1);
    And(a=outa1, b=in, out=a);

    And(a=sel[0], b=notsel1, out=outb0);
    And(a=outb0, b=notsel2, out=outb1);
    And(a=outb1, b=in, out=b);

    And(a=notsel0, b=sel[1], out=outc0);
    And(a=outc0, b=notsel2, out=outc1);
    And(a=outc1, b=in, out=c);

    And(a=sel[0], b=sel[1], out=outd0);
    And(a=outd0, b=notsel2, out=outd1);
    And(a=outd1, b=in, out=d);

    And(a=notsel0, b=notsel1, out=oute0);
    And(a=oute0, b=sel[2], out=oute1);
    And(a=oute1, b=in, out=e);

    And(a=sel[0], b=notsel1, out=outf0);
    And(a=outf0, b=sel[2], out=outf1);
    And(a=outf1, b=in, out=f);

    And(a=notsel0, b=sel[1], out=outg0);
    And(a=outg0, b=sel[2], out=outg1);
    And(a=outg1, b=in, out=g);

    And(a=sel[0], b=sel[1], out=outh0);
    And(a=outh0, b=sel[2], out=outh1);
    And(a=outh1, b=in, out=h);
}

0 コメント:

コメントを投稿

Comments on Google+: