Question

In: Computer Science

Write in verilog, code to implement a 6 bit multiplier. Cascade a 1 bit multiplier to...

Write in verilog, code to implement a 6 bit multiplier. Cascade a 1 bit multiplier to implement this.

Solutions

Expert Solution

The 1 bit multiplier verilog code:

module multiplier_1bit(a,b,p);
input a,b; //1 bit inputs
output wire p; //1 bit output
assign p=a&b; //product assignment
endmodule

code snippet:

6_bit multiplier by cascading 1 bit multiplier:

Verilog code:

module multiplier_6bit(a,b,prod);
input [5:0] a,b; //6 bit input a,b
output wire [11:0] prod; //the product is 12 bit stored in prod
wire [5:0]p0,p1,p2,p3,p4,p5; //which stores the 1 bit multiplier outputs
wire [9:0] cy; //stores the carry value while adding 1 bit products
//The below 1 bit module instantiation stores p0=B*A0
multiplier_1bit m1(a[0],b[0],p0[0]);
multiplier_1bit m2(a[0],b[1],p0[1]);
multiplier_1bit m3(a[0],b[2],p0[2]);
multiplier_1bit m4(a[0],b[3],p0[3]);
multiplier_1bit m5(a[0],b[4],p0[4]);
multiplier_1bit m6(a[0],b[5],p0[5]);
//The below 1 bit module instantiation stores p1=B*A1
multiplier_1bit mm1(a[1],b[0],p1[0]);
multiplier_1bit mm2(a[1],b[1],p1[1]);
multiplier_1bit mm3(a[1],b[2],p1[2]);
multiplier_1bit mm4(a[1],b[3],p1[3]);
multiplier_1bit mm5(a[1],b[4],p1[4]);
multiplier_1bit mm6(a[1],b[5],p1[5]);
//The below 1 bit module instantiation stores p2=B*A2
multiplier_1bit mmm1(a[2],b[0],p2[0]);
multiplier_1bit mmm2(a[2],b[1],p2[1]);
multiplier_1bit mmm3(a[2],b[2],p2[2]);
multiplier_1bit mmm4(a[2],b[3],p2[3]);
multiplier_1bit mmm5(a[2],b[4],p2[4]);
multiplier_1bit mmm6(a[2],b[5],p2[5]);
//The below 1 bit module instantiation stores p3=B*A3
multiplier_1bit mmm11(a[3],b[0],p3[0]);
multiplier_1bit mmm22(a[3],b[1],p3[1]);
multiplier_1bit mmm33(a[3],b[2],p3[2]);
multiplier_1bit mmm44(a[3],b[3],p3[3]);
multiplier_1bit mmm55(a[3],b[4],p3[4]);
multiplier_1bit mmm66(a[3],b[5],p3[5]);
//The below 1 bit module instantiation stores p4=B*A4
multiplier_1bit mm11(a[4],b[0],p4[0]);
multiplier_1bit mm22(a[4],b[1],p4[1]);
multiplier_1bit mm33(a[4],b[2],p4[2]);
multiplier_1bit mm44(a[4],b[3],p4[3]);
multiplier_1bit mm55(a[4],b[4],p4[4]);
multiplier_1bit mm66(a[4],b[5],p4[5]);
//The below 1 bit module instantiation stores p5=B*A5
multiplier_1bit m11(a[5],b[0],p5[0]);
multiplier_1bit m22(a[5],b[1],p5[1]);
multiplier_1bit m33(a[5],b[2],p5[2]);
multiplier_1bit m44(a[5],b[3],p5[3]);
multiplier_1bit m55(a[5],b[4],p5[4]);
multiplier_1bit m66(a[5],b[5],p5[5]);
//The below assignment operations used to assign the final product.
assign prod[0]=p0[0];
assign {cy[0],prod[1]}=p0[1]+p1[0];
assign {cy[1],prod[2]}=p0[2]+p1[1]+p2[0]+cy[0];
assign {cy[2],prod[3]}=p0[3]+p1[2]+p2[1]+p3[0]+cy[1];
assign {cy[3],prod[4]}=p0[4]+p1[3]+p2[2]+p3[1]+p4[0]+cy[2];
assign {cy[4],prod[5]}=p0[5]+p1[4]+p2[3]+p3[2]+p4[1]+p5[0]+cy[3];
assign {cy[5],prod[6]}=p1[5]+p2[4]+p3[3]+p4[2]+p5[1]+cy[4];
assign {cy[6],prod[7]}=p2[5]+p3[4]+p4[3]+p5[2]+cy[5];
assign {cy[7],prod[8]}=p3[5]+p4[4]+p5[3]+cy[6];
assign {cy[8],prod[9]}=p4[5]+p5[4]+cy[7];
assign {cy[9],prod[10]}=p5[5]+cy[8];
assign prod[11]=cy[9];
endmodule

Code snippets:

Simulation results:

Here i just multiplied the each single bits of A with B.This is like

A0*B=(B5A0)(B4A0)(B3A0)(B2A0)(B1A0)(B0A0)

Simillarly for A1*B;A2*B;A3*B;A4*B;A5*B

By using this i assigned the product values.Please see the below figure for better understanding.By using this picture i assigned the sum values to the product.

For prod[1]=p0[1]+p1[0];

prod[2]=p0[2]+p1[1]+p2[0]+cy[0];

simillary for remaining.

Here i used vivado tool for simulation of the code.

In simulation results I convert a,b,prod radix to unsigned decimal.

Please upvote this..


Related Solutions

Write a Verilog code to implement 16 bit LFSR
Write a Verilog code to implement 16 bit LFSR
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.
Implement a 4x4 multiplier using gate level (verilog code and test bench)
Implement a 4x4 multiplier using gate level (verilog code and test bench)
verilog code to implement 32 bit Floating Point Adder in Verilog using IEEE 754 floating point...
verilog code to implement 32 bit Floating Point Adder in Verilog using IEEE 754 floating point representation.
Write a verilog code for 5 to 8 multiplier using fourbit adder
Write a verilog code for 5 to 8 multiplier using fourbit adder
Write a VHDL code for a 8x8 bit multiplier. use structural approach. write the design code...
Write a VHDL code for a 8x8 bit multiplier. use structural approach. write the design code and testbench. Use for-generate if possible
write a verilog code to implement a digital system that has an odd counter that counts...
write a verilog code to implement a digital system that has an odd counter that counts from 1 to 11. Also, this system has an output Y that detects a specific number in the odd counter. Test your code when you detect the number 3, the output Y is 1, if the counter value is set to 3, otherwise 0.
Write the Verilog code for a 12-bit shift register with ability to shift left or right,...
Write the Verilog code for a 12-bit shift register with ability to shift left or right, synchronized parallel load, asynchronous reset, and serial output? The register is able to load the 12-bit input value (at the positive edge of the clock) if the load signal is one, shift the value in register one bit to the right (at the positive edge of the clock) if the rss signal is one, shift the value in register one bit to the left(at...
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.
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT