Sei sulla pagina 1di 4

---------------------------------------------------------------------------------- Company:

-- Engineer:
--- Create Date:
14:45:07 09/30/2015
-- Design Name:
-- Module Name:
Square_Root - Behavioral
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:
--- Dependencies:
--- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
---------------------------------------------------------------------------------library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use ieee.numeric_std.all;
---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity Square_Root is
Port ( Qi : in STD_LOGIC_VECTOR (7 downto 0);
Qj : out STD_LOGIC_VECTOR (7 downto 0)
);
end Square_Root;
architecture Behavioral of Square_Root is
signal S,R,T,N,DY,Temp : std_logic_vector(7 downto 0):="00000000";
signal E : std_logic_vector(1 downto 0):="00";
begin
process(Qi)
variable m,l,k : integer ;
variable j,i : integer ;
variable Qi_cat: STD_LOGIC_vector(1 downto 0);
begin
i:=7;j:=7;
for k in 4 downto 1 loop
if ((Qi(i downto i-1)) = E) then
Temp(j)<='0';
i:=i-2;
j:=j-1;
else
Temp(j) <= '1'; --"10000000";
j:=j-1;
m:=j;
R(1 downto 0) <= ((Qi(i) & Qi(i-1))-01);
if (i>=2) then
S <= (R(6 downto 0) & Qi(i-2));

if (S(1 downto 0)<"10") then


Temp(j)<='0';
else
S <= (R(6 downto 0) & Qi(i-2))-10;
Temp(j)<='1';
end if;
end if;
R <= S;
exit;
end if;
end loop;
if(i>0 and j>0) then
--R(1 downto 0) <= ((Qi(i) & Qi(i-1))-01);
-- Qi_cat := (Qi(i downto i-1));
-- R(1 downto 0) <= Qi_cat - 1;
--if(S<N) then
--Temp(j)<='0';
--else
--Temp(j)<='1';
--end if;
while (i > 0) loop
i:=i-1;
DY<="00000000";
-- Duplex calculation
l:=j;
k:=m;
if((k-l)
=0) then
DY<= DY+ Temp(l);
end if;
if((k-l)=2) then
DY<=DY+ (Temp(l) and Tem
p(k)) + (Temp(l) and Temp(k));
end if;
if((k-l)
=3) then
DY<=DY+ (Temp(l) and Tem
p(k)) + (Temp(l) and Temp(k))+Temp(k-1);
end if;
if((k-l)
=4) then
DY<=DY+ (Temp(l)
p(k)) + (Temp(l) and Temp(k))+(Temp(l+1) and Temp(k-1)) + (Temp(l+1) and
1));
end if;
if((k-l)=5) then
DY<=DY+ (Temp(l)
p(k)) + (Temp(l) and Temp(k))+(Temp(l+1) and Temp(k-1)) + (Temp(l+1) and
1))+ Temp(k-2);
end if;
if((k-l)=6) then
DY<=DY+ (Temp(l)
p(k)) + (Temp(l) and Temp(k))+(Temp(l+1) and Temp(k-1)) + (Temp(l+1) and
1))+ (Temp(k-2) and Temp(k-2))+(Temp(k-2) and Temp(k-2));
end if;

and Tem
Temp(k-

and Tem
Temp(k-

and Tem
Temp(k-

-----mp(k)) + (Temp(l) and Temp(k));


------ end Duplex calculation
j:=j-1;
S <= (R(6 downto 0) & Qi(i-1));
if(S<DY) then
Temp(j+1)<='0';
-- Duplex calculation
-------mp(k)) + (Temp(l) and Temp(k));
-----

while(k>=l) loop
if (l=k) then
DY<=DY + Temp(j);
else
DY<=DY + (Temp(l) and Te
k:=k-1;
l:=l+1;
end if;
end loop;

l:=j;
k:=m;
while(k>l) loop
if (l=k) then
DY<=DY + Temp(j);
else
DY<=DY + (Temp(l) and Te
k:=k-1;
l:=l+1;
end if;
end loop;
l:=j+1;
k:=m;
if((k-l)

=0) then
DY<= DY+ Temp(l);
end if;
if((k-l)=2) then
DY<=DY+ (Temp(l) and Tem
p(k)) + (Temp(l) and Temp(k));
end if;
if((k-l)
=3) then
DY<=DY+ (Temp(l) and Tem
p(k)) + (Temp(l) and Temp(k))+Temp(k-1);
end if;
if((k-l)
=4) then
DY<=DY+ (Temp(l)
p(k)) + (Temp(l) and Temp(k))+(Temp(l+1) and Temp(k-1)) + (Temp(l+1) and
1));
end if;
if((k-l)=5) then
DY<=DY+ (Temp(l)
p(k)) + (Temp(l) and Temp(k))+(Temp(l+1) and Temp(k-1)) + (Temp(l+1) and
1))+ Temp(k-2);
end if;
if((k-l)=6) then
DY<=DY+ (Temp(l)
p(k)) + (Temp(l) and Temp(k))+(Temp(l+1) and Temp(k-1)) + (Temp(l+1) and
1))+ (Temp(k-2) and Temp(k-2))+(Temp(k-2) and Temp(k-2));
end if;

and Tem
Temp(k-

and Tem
Temp(k-

and Tem
Temp(k-

-- end Duplex calculation


S<=((R(6 downto 0)+10) & Qi(i-1))-DY;
if S > "000000010" then
T<= S-10;
Temp(j)<='1';
R<=T;
else
Temp(j)<='0';
R<=S;
end if;
else
S <= (R(6 downto 0) & Qi(i-1))-DY;
--T<=S-10;
if S > "000000010" then
T<= S-10;
Temp(j)<='1';
R<=T;
else
Temp(j)<='0';
R<=S;
end if;
end if;
end loop;
Qj<=Temp(7 downto 0);
end if;
end process;
end Behavioral;