Question

In: Computer Science

Create a testbench in Verilog for the following module (logic). Verify the testbench works in your...

Create a testbench in Verilog for the following module (logic). Verify the testbench works in your answer. I'll upvote correct answers.

This module does the following. The algorithm takes an input between 0 and 255 (in unsigned binary and counts the number of ones in each number (ex. 01010101 has 4 ones). Then the output would be 00000100 (4 in binary because there are 4 ones.

The test bench would need to verify the inputs and outputs of each number. Test 5 different numbers and ensure the output is expected for the input.

module logic(
  input [7:0] A, //input is between 0-255, so 8 bits.
  output reg [3:0] ones // 0-3 because, at max there can be 8 ones. As, 8 can be represented in 3 bits.
  );

integer i;// declaration of vailable i

always@(A)
begin
ones = 0;  //initialize count variable.
  for(i=0;i<8;i=i+1)   //Iterate all the bits. As input lies between 0 & 255, so, 8 bits.
ones = ones + A[i]; //Adding the bit to the count.
end

endmodule

Solutions

Expert Solution

code:

output :

raw_code :

`timescale 1ns / 1ps
module testlogic;

reg [7:0] A; //declaring input
wire [3:0]ones; //declaring outptu

logic v(.A(A),.ones(ones)); //instantiation of logic module


initial begin
$monitor("A = %b , ones = %d",A,ones); //to display output
end

initial
begin
#10 A = 8'b01010101; // checking with test cases
#100 A = 8'b00000100;
#200 A = 8'b00110001;
#400 A = 8'b00000000;
#500 A = 8'b11111111;
end
endmodule

***do comment for queries and rate me up******


Related Solutions

Create a testbench in Verilog for the following module (logic). Verify the testbench works in your...
Create a testbench in Verilog for the following module (logic). Verify the testbench works in your answer. I'll upvote correct answers. This module does the following. The algorithm takes an input between 0 and 255 (in unsigned binary and counts the number of ones in each number (ex. 01010101 has 4 ones). Then the output would be 00000100 (4 in binary because there are 4 ones. The test bench would need to verify the inputs and outputs of each number....
Please Create the Verilog/Vivado Code For: An LFSR Pseudonumber generator, and the testbench for test it,...
Please Create the Verilog/Vivado Code For: An LFSR Pseudonumber generator, and the testbench for test it, please comment and explain the answer as much as possible if possible, post Pic of the waveform simulation!
Please Create the Verilog/Vivado Code For: An LFSR Pseudonumber generator, and the testbench for test it,...
Please Create the Verilog/Vivado Code For: An LFSR Pseudonumber generator, and the testbench for test it, please comment and explain the answer as much as possible waveform simulation answer would be nice too!
Please Create the Verilog/Vivado Code For: An LFSR Pseudonumber generator, and the testbench for test it,...
Please Create the Verilog/Vivado Code For: An LFSR Pseudonumber generator, and the testbench for test it, please comment and explain the answer as much as possible!
Please Create the Verilog/Vivado Code For: An LFSR Pseudonumber generator, and the testbench for test it,...
Please Create the Verilog/Vivado Code For: An LFSR Pseudonumber generator, and the testbench for test it, please comment and explain the answer as much as possible,(Make your own code, even it is more simple, but do not copy from others sources on the internet) if possible, post Pic of the waveform simulation!
Verilog counter problem: Using the attached 4-bit up-counter module and testbench as a template, write a...
Verilog counter problem: Using the attached 4-bit up-counter module and testbench as a template, write a Verilog module that implements a certain 4-bit counter. The module should include two more input variables: “updown” and “count2”. If “updown” is 1, the circuit should count up (by 1s); if it is 0 it should count down (by 1s). If “count2” has a value of 1, the circuit should instead count up by 2s; otherwise it will have no effect (the circuit counts...
Verilog counter problem: Using the attached 4-bit up-counter module and testbench as a template, write a...
Verilog counter problem: Using the attached 4-bit up-counter module and testbench as a template, write a Verilog module that implements a certain 4-bit counter. The module should include two more input variables: “updown” and “count2”. If “updown” is 1, the circuit should count up (by 1s); if it is 0 it should count down (by 1s). If “count2” has a value of 1, the circuit should instead count up by 2s; otherwise it will have no effect (the circuit counts...
Verilog code for Traffic light controller. Need a block diagram, Verilog codes used with testbench, and...
Verilog code for Traffic light controller. Need a block diagram, Verilog codes used with testbench, and the waveforms screen-prints.
Write a Huffman decoder in verilog that inputs a text file with testbench.
Write a Huffman decoder in verilog that inputs a text file with testbench.
Design an 8-bit adder. Show Verilog code and testbench.
Design an 8-bit adder. Show Verilog code and testbench.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT