Verilog
Verilog
Verilog
Exercise 1_1
module exercise1_1(W,X,Y,Z);
output [0:3] W;
input X,Y;
input Z;
wire X1,Y1,Z1;
not g1(X1,X), g2(Y1,Y), g3(Z1,Z);
nand g4(W[0],X1,Y1,Z1), g5(W[1],X1,Y,Z1), g6(W[2],X,Y1,Z1), g7(W[3],X,Y,Z1);
endmodule
module testex1();
reg X,Y,Z;
wire [0:3] W;
exercise1_1 tb(W,X,Y,Z);
initial begin
#4 X=1'b0; Y=1'b0; Z=1'b0;
$monitor("X=%b Y=%b Z=%b W=%b",X,Y,Z,W);
#4 X=1'b0; Y=1'b0; Z=1'b1;
#4 X=1'b0; Y=1'b1; Z=1'b0;
#4 X=1'b0; Y=1'b1; Z=1'b1;
#4 X=1'b1; Y=1'b0; Z=1'b0;
#4 X=1'b1; Y=1'b0; Z=1'b1;
#4 X=1'b1; Y=1'b1; Z=1'b0;
#4 X=1'b1; Y=1'b1; Z=1'b1;
#2 $finish;
end
endmodule
Exercise 1_2
module circuit1_1(A,B,C,X);
input A,B,C;
output X;
wire wire1, wire2, wire3;
not NOT(wire2,A);
xor EOR2(wire1,B,C);
and AND2(wire3,wire1,A);
nor NOR2(X,wire3,wire2);
endmodule
module testbench1_1();
reg A,B,C;
wire Z;
circuit1_1 tb1(A,B,C,Z);
initial
begin
A=1'b0; B=1'b0; C=1'b0;
$strobe($time,,,"A=%b B=%b C=%b Z=%b",A,B,C,Z);
#20 A=1'b0; B=1'b0; C=1'b1;
$strobe($time,,,"A=%b B=%b C=%b Z=%b",A,B,C,Z);
#10 A=1'b0; B=1'b1; C=1'b0;
$strobe($time,,,"A=%b B=%b C=%b Z=%b",A,B,C,Z);
#10 A=1'b0; B=1'b1; C=1'b1;
$strobe($time,,,"A=%b B=%b C=%b Z=%b",A,B,C,Z);
#10 A=1'b1; B=1'b0; C=1'b0;
$strobe($time,,,"A=%b B=%b C=%b Z=%b",A,B,C,Z);
#10 A=1'b1; B=1'b0; C=1'b1;
$strobe($time,,,"A=%b B=%b C=%b Z=%b",A,B,C,Z);
#10 A=1'b1; B=1'b1; C=1'b0;
$strobe($time,,,"A=%b B=%b C=%b Z=%b",A,B,C,Z);