Wednesday 5 February 2014

2x1 multiplexer

DATA FLOW

module mux2_1(a,b,s,cout);
input a,b,s;
output cout;
assign cout = ((a&s)||(b&~s));
endmodule

GATE LEVEL:

module mux2_1(a,b,s,cout);
input a,b,s;
output cout;
wire s0,x1,x2;
xor (s0,s);
and a1(x1,a,s);
and a2(x2,b,s0);
or a3(cout,x1,x2);
endmodule

BEHAVIORAL:

module mux2_1(a,b,s,cout);
input a,b,s;
output cout;
wire s0,x1,x2;
reg cout;
always @(a or b or s) begin
s0=~s;
x1=a&s;
x2=b&s0;
cout=x1||x2;
end
endmodule

TEST BENCH:

module mux2_1( );
//inputs
wire a,b,s;
//outputs
reg cout;
//instantiate the unit under test
muxgtlev uut (
.a(a),
.b(b),
.s(s),
.cout(cout)
);

initial begin
#10 a=2'b01;
#20 b=2'b10;
#25 s=2'b11;
end
initial begin
$monitor($time,"a=%b,b=%b,s=%b,cout=%b",a,b,s,cout);
end
     
endmodule

No comments:

Post a Comment