module multiplier(A ,B , P);
parameter BIT_WIDTH = 4;
input [BIT_WIDTH-1 : 0] A;
input [BIT_WIDTH-1 : 0] B;
output [2*BIT_WIDTH-1 : 0] P;
wire [BIT_WIDTH-1 : 0] int_sum [BIT_WIDTH-1 : 0];
wire [BIT_WIDTH-1 : 0] int_cout [BIT_WIDTH-1 : 0];
genvar i,j;
generate
for(i=0;i<=BIT_WIDTH-1;i=i+1) // B corresponds to i
for(j=0;j<=BIT_WIDTH-1;j=j+1) // A corespond to j
if(i==0)
if(j <= BIT_WIDTH-1 )
begin:FIRST_ROW
mul_unit(
.in_x(A[j]),
.in_y(B[0]),
.cin(),
.sin(),
.cout(int_cout[i][0]),
.sout(int_sum[i][0])
);
end
else
if(i == BIT_WIDTH-1)
begin:LAST_ROW
mul_unit(
.in_x(),
.in_y(B[i]),
.cin(int_cout[i-1][j]),
.sin(int_sum[i-1][j+1]),
.cout(int_cout[i][j]),
.sout(int_sum[i][j])
);
end
else
begin:OTHER_ROW
mul_unit(
.in_x(),
.in_y(B[i]),
.cin(int_cout[i-1][j]),
.sin(int_sum[i-1][j+1]),
.cout(int_cout[i][j]),
.sout(int_sum[i][j])
);
end
endgenerate;
for(i=0;i<=BIT_WIDTH-1;i=i+1) // B corresponds to i
for(j=0;j<=BIT_WIDTH-1;j=j+1) // A corespond to j
if(i< BIT_WIDTH -1 )
assign P[i] = int_sum[i][0] ;
else
if(j< BIT_WIDTH-1)
assign P[BIT_WIDTH+j] = int_sum[i][j];
else
assign P[BIT_WIDTH+j] = int_cout[i][j];
endmodule