Header Ads

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:


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

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

 OUTPUT:



Post a Comment

0 Comments