Verilog Report
Verilog Report
Code :
module full_adder (
input A,
input B,
input Cin,
output Sum,
output Cout
);
endmodule
Test bench :
module test_full_adder;
reg A, B, Cin;
wire Sum, Cout;
fulladderuut (
. A(A),
. B(B),
. Cin (Cin),
. Sum (Sum),
. Cout (Cout)
);
initial begin
$monitor ("A = %b, B = %b, Cin = %b | Sum = %b, Cout = %b", A, B, Cin,
Sum, Cout);
A = 0; B = 0; Cin = 0; #10;
A = 0; B = 0; Cin = 1; #10;
A = 0; B = 1; Cin = 0; #10;
A = 0; B = 1; Cin = 1; #10;
A = 1; B = 0; Cin = 0; #10;
A = 1; B = 0; Cin = 1; #10;
A = 1; B = 1; Cin = 0; #10;
A = 1; B = 1; Cin = 1; #10;
// End simulation
$finish;
end
endmodule
Waveform :
Code:
module full_subtractor (
input A,
input B,
input Bin,
output Diff,
output Bout
);
endmodule
test bench :
module test_full_subtractor;
reg A, B, Bin;
full_subtractor uut (
.A(A),
.B(B),
.Bin(Bin),
.Diff(Diff),
.Bout(Bout)
);
initial begin
$monitor("A = %b, B = %b, Bin = %b | Diff = %b, Bout = %b", A, B, Bin, Diff,
Bout);
A = 0; B = 0; Bin = 0; #10;
A = 0; B = 0; Bin = 1; #10;
A = 0; B = 1; Bin = 0; #10;
A = 0; B = 1; Bin = 1; #10;
A = 1; B = 0; Bin = 0; #10;
A = 1; B = 0; Bin = 1; #10;
A = 1; B = 1; Bin = 0; #10;
A = 1; B = 1; Bin = 1; #10;
$finish;
end
endmodule
Waveform :
Code :
module johnson_counter (
input clk,
input reset,
);
if (reset) begin
q <= 4'b0000; // Reset the counter to 0000
// Shift the bits to the right, and invert the MSB to get the Johnson
counter sequence
end
end
endmodule
Test bench:
module test_johnson_counter;
reg clk;
reg reset;
wire [3:0] q;
johnson_counter uut (
.clk(clk),
.reset(reset),
.q(q)
);
always begin
end
initial begin
// Initialize signals
clk = 0;
reset = 0;
reset = 1;
#10;
reset = 0;
#10;
$finish;
end
initial begin
end
endmodule
Waveform :