ADD hw4
ADD hw4
Verilog code-
always @(a or b or c)
begin
out = (a^b)|((~b)&c);
end
endmodule
Verilog testbench-
module testprog1();
reg a,b,c;
wire out;
prog1 p1(.a(a),.b(b),.c(c),.out(out));
integer i;
initial
begin
for (i=0;i<8;i=i+1)
#5{a,b,c}=i;
end
endmodule
Simulation waveform-
Problem 2:
Verilog code-
parameter S0 = 0, S1 = 1, S2 = 2, S3 = 3;
always @ (state or in )
begin
out = 0;
case (state) //From the state diagram in the textbook, we can make the following cases-
S0: begin
if (in == 0) nextstate = S1;
end
end
end
end
endcase
end
endmodule
Verilog testbench-
module testmanchester();
wire out;
NRZtoManchesterMooremachine NMM(.in(in),.clk(clk),.reset(reset),.out(out));
initial
begin
repeat (20)
begin
forever begin
clk = 0;
end
reset = 1;
in=$random;
#10;
end
end
endmodule
Problem 3:
Problem 4:
Verilog code-
module comp (A,B,a_gt_b,a_lt_b,a_eq_b);
always @(A,B)
begin
end
endmodule
Verilog testbench-
module test_comp();
wire a_gt_b,a_lt_b,a_eq_b;
comp c1 (.A(A),.B(B),.a_gt_b(a_gt_b),.a_lt_b(a_lt_b),.a_eq_b(a_eq_b));
initial
begin
repeat(15)
begin
B=$random;
#10;
end
end
endmodule
Simulation waveform-
The simulation proved the equality, greater than and less than.
Problem 5:
Else, d = 0
Explanation of the last output pattern in the figure,