-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mul16Bit.v
35 lines (32 loc) · 973 Bytes
/
Mul16Bit.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
`timescale 1ns / 1ps
// Multiplica 2 numeros de DATA_WIDTH bits, por defecto 16
module Mul16Bit # (parameter DATA_WIDTH=16)(
input wire [DATA_WIDTH-1:0] a,
input wire [DATA_WIDTH-1:0] b,
output wire [DATA_WIDTH-1:0] result
);
wire [DATA_WIDTH-1:0] partialResult [DATA_WIDTH-2:0];
wire [DATA_WIDTH-1:0] carry [DATA_WIDTH-2:0];
genvar i, j; // col, row
genvar m;
generate
for (j=0; j<DATA_WIDTH-1; j=j+1) begin : for_row
for (i=0; i<DATA_WIDTH; i=i+1) begin : for_col
Adder adder(
.A(a[j+1]&b[i]),
.B((j==0) ? (i==DATA_WIDTH-1)? 0 : a[0] & b[i+1] : (i==DATA_WIDTH-1) ? carry[j-1][i] : partialResult[j-1][i+1]),
.Ci((i==0) ? 0 : carry[j][i-1]),
.R(partialResult[j][i]),
.Co(carry[j][i])
);
end
end
for (m=0; m<DATA_WIDTH; m=m+1) begin : for_result
if (m==0) begin
assign result[m] = a[0] & b[0];
end else begin
assign result[m] = partialResult[m-1][0];
end
end
endgenerate
endmodule