-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdivision16.v
37 lines (33 loc) · 861 Bytes
/
division16.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
36
37
`timescale 1ns / 1ps
module Division16(A,B,Res,remainder);
parameter WIDTH = 16;
//input and output ports.
input [WIDTH-1:0] A;
input [WIDTH-1:0] B;
output [WIDTH-1:0] Res;
output reg [WIDTH-1:0] remainder;
//internal variables
reg [WIDTH-1:0] Res = 0;
reg [WIDTH-1:0] a1,b1;
reg [WIDTH:0] p1;
reg [7:0]remainderL;
integer i;
always@ (A or B)
begin
a1 = A;
b1 = B;
p1= 0;
for(i=0;i < WIDTH;i=i+1) begin
p1 = {p1[WIDTH-2:0],a1[WIDTH-1]};
a1[WIDTH-1:1] = a1[WIDTH-2:0];
p1 = p1-b1;
if(p1[WIDTH-1] == 1) begin
a1[0] = 0;
p1 = p1 + b1; end
else
a1[0] = 1;
end
Res = a1;
{remainderL,remainder} = p1;
end
endmodule