Half Adder: Gate Level Verilog Code For Half Adder
Half Adder: Gate Level Verilog Code For Half Adder
Full adder:
Gate Level Verilog Code for Full adder:
module halfadder(s,c,a,b);
input a,b;
output s,c;
xor(s,a,b);
and(c,a,b);
endmodule
module Fulladder(S,Cout,A,B,Cin);
input A,B,Cin;
output S,Cout;
wire w1,w2,w3;
halfadder h1(w1,w2,A,B);
halfadder h2(S,w3,w1,Cin);
or(Cout,w2,w3);
endmodule
module fulladder(a,b,cin,s,cout);
input a,b,cin;
outut s,cout;
assign s=a^b^cin;
assign cout(a & b)| cin&(a&b);
endmodule
output Y;
input D0, D1, S;
wire a1, b1, Sbar;
and (a1, D1, S), (b1, D0, Sbar);
not (Sbar, S);
or (Y, a1, b1);
endmodule
Dataflow level Verilog Code for MU21:
module m21(D0, D1, S, Y);
output Y;
input D0, D1, S;
assign Y=(S)?D1:D0;
endmodule
Test Bench Verilog Code:
`timescale 1ns / 1ns
module mux_test();
reg D0,D1,S;
wire Y;
mux_21 h1(.D0(D0),.D1(D1),.S(S),.Y(Y));
initial
begin
$monitor($time, "The value of D0=%b D1=%b S=%b Y=%b",D0,D1,S,Y);
D0=1'b1; D1=1'b0; S=1'b0;
#100;
D0=1'b0; D1=1'b1; S=1'b0;
#100;
D0=1'b0; D1=1'b0; S=1'b0;
#100;
D0=1'b0; D1=1'b1; S=1'b0;
#100;
D0=1'b1; D1=1'b0; S=1'b0;
#100;
D0=1'b1; D1=1'b1; S=1'b0;
#100;
end
endmodule
Simulation Wave form:
end
endmodule
Simulation Wave form:
end
endmodule
Simulation Wave form:
end
endmodule
end
endmodule
Simulation Wave form:
Printed Output from Transcript window
0The value of d0=1 d1=0 d2=0 d3=0 d4=0 d5=0 d6=0 d7=0 a=0 b=0 c=0
# 100The value of d0=0 d1=1 d2=0 d3=0 d4=0 d5=0 d6=0 d7=0 a=0 b=0 c=1
# 200The value of d0=0 d1=0 d2=1 d3=0 d4=0 d5=0 d6=0 d7=0 a=0 b=1 c=0
# 300The value of d0=0 d1=0 d2=0 d3=1 d4=0 d5=0 d6=0 d7=0 a=0 b=1 c=1
# 400The value of d0=0 d1=0 d2=0 d3=0 d4=1 d5=0 d6=0 d7=0 a=1 b=0 c=0
# 500The value of d0=0 d1=0 d2=0 d3=0 d4=0 d5=1 d6=0 d7=0 a=1 b=0 c=1
# 600The value of d0=0 d1=0 d2=0 d3=0 d4=0 d5=0 d6=1 d7=0 a=1 b=1 c=0
# 700The value of d0=0 d1=0 d2=0 d3=0 d4=0 d5=0 d6=0 d7=1 a=1 b=1 c=1
end
endmodule
Simulation Wave form: