4 //This is the main code of integer sqrt function found here:http://verilogcodes.blogspot.com/2017/11/a-verilog-function-for-finding-square-root.html
11 //Verilog function to find square root of a 32 bit number.
12 //The output is 16 bit.
14 input [31:0] num; //declare input
15 //intermediate signals.
18 reg [17:0] left,right,r;
21 //initialize all the variables.
25 left = 0; //input to adder/sub
26 right = 0; //input to adder/sub
28 //run the calculations for 16 iterations.
29 for(i=0;i<16;i=i+1) begin
30 right = {q,r[17],1'b1};
31 left = {r[15:0],a[31:30]};
32 a = {a[29:0],2'b00}; //left shift by 2 bits.
33 if (r[17] == 1) //add if r is negative
35 else //subtract if r is positive
39 sqrt = q; //final assignment of output.
41 endfunction //end of Function