Question

In: Computer Science

using verilog to design a 8x8 unsigned multiplier(with testbench) utilizing a 2x8 multiplier as a building...

using verilog to design a 8x8 unsigned multiplier(with testbench) utilizing a 2x8 multiplier as a building block

here is the testbench and code for 2x8:

module cpp_mult(mplr,mcand, prod);

input [1:0] mplr;

input [7:0] mcand;

output [9:0] prod;


wire [9:0] mcand1;
wire [9:0] mcand2;
wire [9:0] mcand3;


assign mcand0 = 10'b00000000;
assign prod = (mplr==2'b00)?mcand0 :
       ((mplr==2'b01)?{2'b00,mcand[7:0]}:
       ((mplr==2'b10)?{1'b0,mcand[7:0],1'b0}:
       ((mplr==2'b11)?{2'b00,mcand[7:0]}+{1'b0,mcand[7:0],1'b0}:8'hxx)));

endmodule

____________________________________________________________________

module cpp_mult_tb();
reg [1:0] mplr;
reg [7:0] mcand;
wire [9:0] prod;

// Instantiate the design under test (DUT). In this case it is cpp_mult.
cpp_mult U1 (mcand, mplr, prod);

initial // initial block executes only once
begin
mplr = 2'b00;
mcand = 8'h00;
#10;   
mplr = 2'b00;
mcand = 8'hFF;
#10;   
mplr = 2'b01;
mcand = 8'hFF;
#10;   
mplr = 2'b01;
mcand = 8'hFF;
#10;   
mplr = 2'b10;
mcand = 8'hFF;
#10;   
mplr = 2'b11;
mcand = 8'hFF;
#10;   
end

endmodule

Solutions

Expert Solution

There are errors in the code you given the question.Lets verify your code doing simulation it gives error.

The modification of your code is below.

Code:

module cpp_mult(mplr,mcand, prod);
input [1:0] mplr;
input [7:0] mcand;
output [9:0] prod;
wire [9:0] mcand1;
wire [9:0] mcand2;
wire [9:0] mcand3;
assign mcand0 = 10'b00000000;
assign prod = (mplr==2'b00)?mcand0 :
((mplr==2'b01)?{2'b00,mcand[7:0]}:
((mplr==2'b10)?{1'b0,mcand[7:0],1'b0}:{2'b00,mcand[7:0]}+{1'b0,mcand[7:0],1'b0}));
//((mplr==2'b11)?{2'b00,mcand[7:0]}+{1'b0,mcand[7:0],1'b0}:8'hxx)));

endmodule

code snippet:

Test Bench code:

module cpp_mult_tb();
reg [1:0] mplr;
reg [7:0] mcand;
wire [9:0] prod;
// Instantiate the design under test (DUT). In this case it is cpp_mult.
cpp_mult U1 (mplr,mcand, prod);
initial // initial block executes only once
begin
mplr = 2'b00;
mcand = 8'h00;
#10;   
mplr = 2'b00;
mcand = 8'hFF;
#10;   
mplr = 2'b01;
mcand = 8'hFF;
#10;   
mplr = 2'b01;
mcand = 8'hFF;
#10;   
mplr = 2'b10;
mcand = 8'hFF;
#10;   
mplr = 2'b11;
mcand = 8'hFF;
#10;   
end
endmodule

Code Snippet:

In your code you made a mistake in assignment statement .You used 8,bxx so while i simulate your code i got the output as xx only for all input combinations.

So i changed the condition once see into my code.

In the testbench while module instantiation you have to fallow the same order how you declared inputs and outputs in the module.But in your code the instantiation input and output places are not same as in the main module so i have changed that also.

Please see these changes in my code.

After these changes i get the output of the 2x8 multiplier output.

By using this code i designed 8x8 multiplier

8X8 multiplier Verilog code:

module multiplier_8x8(mplr,mcand, prod);
input [7:0] mplr; //inputs mplr and mcand are 8 bits
input [7:0] mcand;
output wire [15:0] prod;//product is 16 bit.
//Wire are all 10 bit which stores each 2X8 multiplier outputs
wire [9:0] mcand1;
wire [9:0] mcand2;
wire [9:0] mcand3;
wire [9:0] mcand4;
//2x8 multliplier module instantiation
cpp_mult c1(mplr[1:0],mcand, mcand1);
cpp_mult c2(mplr[3:2],mcand, mcand2);
cpp_mult c3(mplr[5:4],mcand, mcand3);
cpp_mult c4(mplr[7:6],mcand, mcand4);
//product assignment using partial outputs of 2x8 multipliers
assign prod=({6'b000000,mcand1}+{4'b0000,mcand2,2'b00}+{2'b00,mcand3,4'b0000}+{mcand4,6'b000000});
endmodule

code snippet:

The test bench code of 8x8 multiplier:

module multiplier_8x8_tb;
//In testbench inputs and outputs are declared as reg and wire respectively
reg [7:0] mplr;
reg [7:0] mcand;
wire [15:0] prod;
//8x8 mutliplier module instantiation
multiplier_8x8 m1(mplr,mcand, prod);
initial // initial block executes only once
//value assignments to the input
begin
mplr = 8'b00;
mcand = 8'h00;
#10;   
mplr = 8'b00;
mcand = 8'hFF;
#10;   
mplr = 8'b01;
mcand = 8'hFF;
#10;   
mplr = 8'b01;
mcand = 8'hFF;
#10;   
mplr = 8'b10;
mcand = 8'hFF;
#10;   
mplr = 8'b11;
mcand = 8'hFF;
#10;   
mplr = 8'd5;
mcand = 8'hFF;
#10;   
mplr = 8'd6;
mcand = 8'hFF;
#10;   
mplr = 8'd15;
mcand = 8'hFF;
end
endmodule

Code snippet:

Simulation Results:

This is the output for the some of the inputs.You can change the inputs in testbench.

I used vivado software for the simulation results.

Please upvote this..


Related Solutions

Design an 8-bit adder. Show Verilog code and testbench.
Design an 8-bit adder. Show Verilog code and testbench.
(Write/Design) both the RTL and Testbench using the Verilog HDL language of the five input majority...
(Write/Design) both the RTL and Testbench using the Verilog HDL language of the five input majority using the structure modeling approach. NOTE: Design means RTL code and Testbench covering all possible corner cases
Design a 4-bit multiplier by using 4 bit full adder and write a verilog code.
Design a 4-bit multiplier by using 4 bit full adder and write a verilog code.
Design a Verilog code for 64x64 array multiplier. Use behavioral Verilog description with full adders and/or...
Design a Verilog code for 64x64 array multiplier. Use behavioral Verilog description with full adders and/or half adders. Please include testbench
Design and write a verilog code and testbench for a 16-bit RISC MIPS Processor on vivado...
Design and write a verilog code and testbench for a 16-bit RISC MIPS Processor on vivado and show waveform.
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....
a) Design a16-bit MIPS Processor in a simplest form in Verilog code with testbench. Please mention...
a) Design a16-bit MIPS Processor in a simplest form in Verilog code with testbench. Please mention the comments where applicable. b) mention the steps how your design works.
Write a verilog code for 5 to 8 multiplier using fourbit adder
Write a verilog code for 5 to 8 multiplier using fourbit adder
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT