?? divide.txt
字號:
-----------compare
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity compare2 is
port(q:in std_logic_vector(8 downto 0);
b:in std_logic_vector(7 downto 0);
great_en:out std_logic);
end;
architecture one of compare2 is
signal y:std_logic_vector(8 downto 0);
begin
y<='0'& b;
process(q,y)
variable check:std_logic;
begin
check:='1';
if q=y then great_en<='1';
else
for i in 8 downto 1 loop
if check='1' then
if(q(i)/=y(i)) then
if ((q(i)='1') and (y(i)='0')) then great_en<='1'; check:='0';end if;
if(q(i)='0' and y(i)='1' ) then great_en<='0'; check:='0';end if;
else
if(q(i-1)/=y(i-1)) then
if ((q(i-1)='1') and (y(i-1)='0')) then great_en<='1';check:='0'; end if;
if(q(i-1)='0' and y(i-1)='1' ) then great_en<='0'; check:='0';end if;
end if;
end if;
end if;
end loop;
end if;
end process;
end;
-----------clock
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity clock is
port(clk,load:in std_logic;
clkk,ariend:out std_logic);
end;
architecture one of clock is
signal cnt:std_logic_vector(4 downto 0);
begin
process(clk,load)--產生16個脈沖
begin
if load='1' then cnt<="00000";
elsif clk'event and clk='1' then
if cnt<16 then cnt<=cnt+1;
end if;
end if;
end process;
process(clk,cnt,load)
begin
if load='0' then
if cnt<16 then clkk<=clk; ariend<='0';
else clkk<='0';ariend<='1';
end if;
else clkk<=clk;
end if;
end process;
end;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity divide is
port(clk,load:in std_logic;---clk為時鐘信號,load為裝載信號
ariend:in std_logic;---ariend為運算結束信號
ain,bin:in std_logic_vector(7 downto 0);--a為被除數,b為除數
q,r:out std_logic_vector(7 downto 0));--q為商,r為余數
end;
architecture one of divide is
signal sign:std_logic_vector(15 downto 0);
signal p,y: std_logic_vector(8 downto 0);---p為中間變量用于保存高17位數
signal great_en:std_logic;
begin
y<='0'&bin;
---移位模塊
process(clk,load,ariend,great_en)
begin
if clk'event and clk='1' then
if ariend='0' then
if load='1'then
sign<="00000000"&ain(7 downto 0);
else
if great_en='1' then
sign(15 downto 1)<=sign(14 downto 0);sign(0)<='1';
else
sign(15 downto 1)<=sign(14 downto 0);sign(0)<='0';
end if;
p<=sign(15 downto 7);
end if;
end if;
end if;
end process;
------
------減法電路
process(clk,great_en)
variable y:std_logic_vector(8 downto 0);
variable a: std_logic_vector(8 downto 0);
begin
if clk'event and clk='1' then
if great_en='1' then
y:=not ('0'& bin);
a:=p+y+1;---a為高17位與除數的差
end if;
sign(15 downto 7)<=a;
end if;
end process;
---------
---------比較電路
process(p,y)
variable check:std_logic;
begin
check:='1';
if p=y then great_en<='1';
else
for i in 8 downto 1 loop
if check='1' then
if(p(i)/=y(i)) then
if ((p(i)='1') and (y(i)='0')) then great_en<='1'; check:='0';end if;
if(p(i)='0' and y(i)='1' ) then great_en<='0'; check:='0';end if;
else
if(p(i-1)/=y(i-1)) then
if ((p(i-1)='1') and (y(i-1)='0')) then great_en<='1';check:='0'; end if;
if(p(i-1)='0' and y(i-1)='1' ) then great_en<='0'; check:='0';end if;
end if;
end if;
end if;
end loop;
end if;
end process;
---------
q<=sign(7 downto 0);
r<=sign(15 downto 8);
-----
end;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -