-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathDIV.v
More file actions
44 lines (38 loc) · 648 Bytes
/
Copy pathDIV.v
File metadata and controls
44 lines (38 loc) · 648 Bytes
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
36
37
38
39
40
41
42
43
44
`timescale 1ns / 1ps
module DIV #( parameter N = 8, M = N )(
input [N-1:0] A,
input [M-1:0] B,
output [N-1:0] O
);
wire [N+M-1:0] A_[N:0];
wire [N+M-1:0] D[N-1:0];
assign A_[N] = {{M{1'b0}}, A};
genvar g;
generate
for(g = N-1; g >= 0;g = g - 1)
begin:DIV_UNIT
if (g > 0)
ADD #(.N(N+M)) SUB(
.A(A_[g+1]),
.B({{(N-g){1'b1}}, ~B, {g{1'b1}}}),
.CI(1'b1),
.S(D[g]),
.CO(O[g])
);
else
ADD #(.N(N+M)) SUB(
.A(A_[g+1]),
.B({{(N-g){1'b1}}, ~B}),
.CI(1'b1),
.S(D[g]),
.CO(O[g])
);
MUX #(.N(N+M)) MUX(
.A(A_[g+1]),
.B(D[g]),
.S(O[g]),
.O(A_[g])
);
end
endgenerate
endmodule