- UID
- 856476
|
module sqrt
#(parameter N = 8)(
input [N-1:0]radical,
output [N/2-1:0]resualt,
output [N/2:0]remainder
);
parameter k = (N + N%2)/2; //toget the nearest even number of
integer i;
reg [N-1:0] r[0:k];
reg [N:0] b[0:k];
[email=always@(radical]always@(radical[/email])
begin
r[0]<=0;
b[0]<=0;
for(i=0;i<k;i =i+1)
begin
if (4*r +2*radical[N - 2*i - 1] + radical[N - 2*i - 2] >=4*b + 1)
begin
r[i+1]<= 4*r + 2*radical[N - 2*i - 1]+ radical[N - 2*i - 2] - 4*b - 1;
b[i+1]<= 2*b + 1;
end
else
begin
r[i+1]<= 4*r + 2*radical[N - 2*i - 1] + radical[N - 2*i- 2];
b[i+1]<= 2*b;
end
end
end
assign resualt = b[k];
assign remainder = r[k];
endmodule |
|