Anda di halaman 1dari 5

AND2,OR2,NAND3,NOR3 USING MUX(WITH OUTPUT)

2 TO 1 MUX CODE:
//2 TO 1 MULTIPLEXER CODE

//DATED 19-07-2017

module mux_2x1(f,a,b,select);

output f;

input a,b,select;

//CONDITIONAL STATEMENT IS USED HERE

assign f=(~select)?a:b;

endmodule

AND2_USING_MUX CODE:
`timescale 1ns/1ps; // TIMESCALE IS USED TO SPECIFY DELAY TIME IN NANO SECONDS

//(I.E)BY MULTIPLIER AND PRECISION

module and2_using_mux();

reg A,B;

wire out;

mux_2x1 DUT(.f(out),.a(0),.b(A),.select(B));

initial #100 $finish;

initial

begin

A=1'b0;

B=1'b0;

#200 $finish;

end

always #20 A =~A; //KEEPS NOTING TO PRODUCE ALL COMBINATIONS OF AB

always #10 B =~B; // KEEPS NOTING TO PRODUCE ALL COMBINATIONS OF AB

initial

begin

$monitor ("time =%0d ns",$time," A=%b B=%b output=%b",A,B,out); //DISPLAYS OUTPUT

end
endmodule

OUTPUT:-
VSIM21>run

# time =0 ns A=0 B=0 output=0

# time =10 ns A=0 B=1 output=0

# time =20 ns A=1 B=0 output=0

# time =30 ns A=1 B=1 output=1

OR2_USING_MUX CODE:
`timescale 1ns/1ps;

module or2_using_mux();

reg A,B;

wire out;

mux_2x1 DUT(.f(out),.a(B),.b(1),.select(A));

initial #100 $finish;

initial

begin

A=1'b0;

B=1'b0;

#200 $finish;

end

always #20 A =~A;

always #10 B =~B;

initial

begin

$monitor ("time =%0d ns",$time," A=%b B=%b output=%b",A,B,out);

end

endmodule
OUTPUT:-
VSIM 21>run

# time =0 ns A=0 B=0 output=0

# time =10 ns A=0 B=1 output=1

# time =20 ns A=1 B=0 output=1

# time =30 ns A=1 B=1 output=1

4x1 MUX CODE:

// 4 to 1 MULTIPLEXER CODE

module mux_4x1( select, d, q );

input[1:0] select;//INPUTS INITIALISED

input[3:0] d;

output q;//OUTPUTS INITIALISED

//IF SELECT IS '10' IT IS TAKEN AS 2 AND IF IT IS '11' IT IS TAKEN AS 3 AND SO ON

assign q = d[select];

endmodule

NOR3_USING_MUX CODE:
`timescale 1ns/1ps;

module nor3_using_mux();

reg a,b,c;

wire f;

mux_4x1 DUT( {b,c},{1'b0,1'b0,1'b0,~a},f);

initial
begin

a=1'b0;

b=1'b0;

c=1'b0;

#100 $finish;

end

always #(40) a=~a; //NOTING TO PRODUCE ALL POSSIBLE COMBINATIONS OF ABC

always #(20) b=~b;

always #(10) c=~c;

initial

begin

$monitor ("time =%0d ns",$time," A=%b B=%b C=%b output=%b",a,b,c,f);

end

endmodule

OUTPUT:-
VSIM 29> run

# time =0 ns A=0 B=0 C=0 output=1

# time =10 ns A=0 B=0 C=1 output=0

# time =20 ns A=0 B=1 C=0 output=0

# time =30 ns A=0 B=1 C=1 output=0

# time =40 ns A=1 B=0 C=0 output=0

# time =50 ns A=1 B=0 C=1 output=0

# time =60 ns A=1 B=1 C=0 output=0

# time =70 ns A=1 B=1 C=1 output=0

Nand3_USING_MUX CODE:

`timescale 1ns/1ps;
module nand3_using_mux();

reg a,b,c;

wire f;

mux_4x1 DUT( {b,c},{~a,1'b1,1'b1,1'b1},f);

initial

begin

a=1'b0;

b=1'b0;

c=1'b0;

#100 $finish;

end

always #(40) a=~a;//NOTING TO PRODUCE ALL COMBINATIONS OF ABC

always #(20) b=~b;

always #(10) c=~c;

initial

begin

$monitor ("time =%0d ns",$time," A=%b B=%b C=%b output=%b",a,b,c,f);

end

endmodule

OUTPUT:-
VSIM 21>run

# time =0 ns A=0 B=0 C=0 output=1

# time =10 ns A=0 B=0 C=1 output=1

# time =20 ns A=0 B=1 C=0 output=1

# time =30 ns A=0 B=1 C=1 output=1

# time =40 ns A=1 B=0 C=0 output=1

# time =50 ns A=1 B=0 C=1 output=1

# time =60 ns A=1 B=1 C=0 output=1

# time =70 ns A=1 B=1 C=1 output=0

Anda mungkin juga menyukai