|
|
|
|
|
|
|
Syntax to create a component:
ComponentFunctionName( parameters ) ;
|
Note:
|
void NewComp( const Signal &a, const Signal &b, const Signal &c,
const Signal &d, const Signal &z )
{
Sig(x,1);
Sig(y,1);
And( "bb", (a,b), x );
And( "bb", (c,d), y );
Or ( "bb", (x,y), z);
}
/* -----
Set up circuit that uses "NewComp"
----- */
void simnet()
{
Sig(in0,1);
Sig(in1,1);
Sig(in2,1);
Sig(in3,1);
Sig(out,1);
/* The input bits to the mux */
Switch ( "aa", in0, '0', Zero );
Switch ( "ba", in1, '1', Zero );
Switch ( "ca", in2, '2', Zero );
Switch ( "da", in3, '3', Zero );
NewComp( in0, in1, in2, in3, out ); // Use the NewComp component
Probe ( "ce", out );
}
|
How to run the program:
|
Result:
|
|
(A box instead of exposed internal circuits)
|
|
How to run the program:
|
Result:
|
Note:
|
|
|
|
Not ( "db", c0, not_c0 ); Not ( "db", c1, not_c1 ); And ( "ac", (i0, not_c1, not_c0), out_0 ); And ( "ac", (i1, not_c1, c0), out_1 ); And ( "bc", (i2, c1, not_c0), out_2 ); And ( "bc", (i3, c1, c0), out_3 ); Or ( "ad", (out_0, out_1, out_2, out_3), out ); |
How to run the program:
|
void MyMux( const SD &coord,
const Signal &i3, const Signal &i2, const Signal &i1, const Signal &i0,
const Signal &c1, const Signal &c0,
const Signal &out )
{
Signal out_0, out_1, out_2, out_3, not_c0, not_c1;
Module( coord, "MyMux", (i3,i2,i1,i0,c1,c0), out);
Not ( SD(coord,"db"), c0, not_c0 );
Not ( SD(coord,"db"), c1, not_c1 );
And ( SD(coord,"ac"), (i0, not_c1, not_c0), out_0 );
And ( SD(coord,"ac"), (i1, not_c1, c0), out_1 );
And ( SD(coord,"bc"), (i2, c1, not_c0), out_2 );
And ( SD(coord,"bc"), (i3, c1, c0), out_3 );
Or ( SD(coord,"ad"), (out_0, out_1, out_2, out_3), out );
}
|
Notice that the control signals (c0, c1) are input signals !!!
MyMux ( "cc", i3, i2, i1, i0, c1, c0, out ); |
How to run the program:
|
MyMux ( "cc", i3, i2, i1, i0, c1, c0, out ); |
Observe:
i3, i2, i1, i0 are input signals
c1, c0 are control signals
|
|
void MyMux( const SD &coord,
const Signal &i, const Signal &c, // i and c are arrays
const Signal &out )
{
Signal out_0, out_1, out_2, out_3, not_c0, not_c1;
Module( coord, "MyMux", (i,c), out);
Not ( SD(coord,"db"), c[0], not_c0 );
Not ( SD(coord,"db"), c[1], not_c1 );
And ( SD(coord,"ac"), (i[0], not_c1, not_c0), out_0 );
And ( SD(coord,"ac"), (i[1], not_c1, c[0]), out_1 );
And ( SD(coord,"bc"), (i[2], c[1], not_c0), out_2 );
And ( SD(coord,"bc"), (i[3], c[1], c[0]), out_3 );
Or ( SD(coord,"ad"), (out_0, out_1, out_2, out_3), out );
}
|
MyMux ( "ab-dd", (in3, in2, in1, in0), (co1, co0), out );
// ^^^^^^^^^^^^^^^^^^^ ^^^^^^^^
// Pass 2 arrays of signals
|
How to run the program:
|