Verilog code for multiplier

Verilog code for multiplier

4X4 Binary Multiplier:
A Binary Multiplier is a digital circuit used in digital electronics to multiply two binary numbers and provide the result as output. The method used to multiply two binary numbers is similar to the method taught to school children for multiplying decimal numbers which is based on calculating partial product, shifting them and adding them together. Similar approach is used to multiply two binary numbers. Long multiplicand is multiplied by 0 or 1 which is much easier than decimal multiplication as product by 0 or 1 is 0 or same number respectively.

Verilog code for 4X4 multilpier:


1. module multiplier(a,b,out);
2. input [3:0]a;//4bit first input.
3. input [3:0]b;//4bit second input.
4. output [7:0]out;//8bit output.
5. wire [7:0]w1,w2,w3,w4,w5,w6,w7;

6. assign w1=a*b[0];//we are multiplying first bit of b to 4bit input a.
7. assign w2=a*b[1];//we are multiplying second bit of b to 4bit input a.
8. assign w3=w2<<1;//we are shifting left one bit.
9. assign w4=a*b[2];//we are multiplying third bit of b to 4bit input a.
10. assign w5=w4<<2;//we are shifting left two bit.
11. assign w6=a*b[3];//we are multiplying fourth bit of b to 4bit input a.
12. assign w7=w6<<3;//we are shifting left three bit.
13. assign out=w1+w3+w5+w7;//we are adding the total result.
14. endmodule

 OUTPUT:



                                                

Post a Comment

0 Comments