在网上找到这个程序,但是仿真后结果不对, 看了下程序好像是有点问题。<br>
哪位大牛能修改一下?<br>
<br>
library IEEE;<br>
use IEEE.STD_LOGIC_1164.ALL;<br>
use IEEE.STD_LOGIC_ARITH.ALL;<br>
use IEEE.STD_LOGIC_UNSIGNED.ALL;<br>
<br>
<br>
entity div is<br>
Port (clk,rst:in std_logic;<br>
bei,chu:in std_logic_vector(31 downto 0);<br>
shangut std_logic_vector(31 downto 0);<br>
dianut integer range -10 to 10 );<br>
end div;<br>
<br>
architecture Behavioral of div is<br>
type ss is array (1 to 8) of std_logic_vector(3 downto 0);<br>
signal s:ss;<br>
signal a,b:std_logic_vector(31 downto 0);<br>
signal n:integer range -10 to 10;<br>
signal c:integer range 0 to 8;<br>
signal k:integer range 1 to 7;<br>
signal d:integer range 0 to 1;<br>
<br>
begin<br>
process(clk,k,n,c,s,bei,chu,a,b,rst)<br>
variable cnt:integer range 0 to 31;<br>
variable m:std_logic_vector(3 downto 0);<br>
<br>
begin<br>
if rst='0' then<br>
k<=5;n<=7;c<=8;cnt:=0;m:="0000";s<=(("0000"),("0000"),("0000"),("0000"),("0000"),("0000"),("0000"),("0000"));<br>
shang<=(others=>'0');<br>
elsif rising_edge(clk) then<br>
case k is<br>
when 1=>if b(31 downto 28)=0 then <br>
b<=b(27 downto 0)&"0000";<br>
if n<10 then<br>
n<=n+1;<br>
else<br>
k<=5;<br>
n<=7;<br>
end if;<br>
else<br>
k<=2;<br>
end if;<br>
when 2=>if a<b then <br>
b<="0000"&b(31 downto 4);<br>
n<=n-1;<br>
else<br>
if n=0 then<br>
k<=5;<br>
n<=7;<br>
else<br>
k<=3;<br>
end if;<br>
end if;<br>
when 3=> if a(cnt+3 downto cnt)>=b(cnt+3 downto cnt)+d then <br>
a(cnt+3 downto cnt)<=a(cnt+3 downto cnt)-b(cnt+3 downto cnt)-d;<br>
d<=0;<br>
else<br>
a(cnt+3 downto cnt)<=a(cnt+3 downto cnt)+10-b(cnt+03 downto cnt)-d;<br>
d<=1;<br>
end if;<br>
if cnt<28 then<br>
cnt:=cnt+4;<br>
k<=3;<br>
else<br>
k<=4;<br>
end if;<br>
when 4=> m:=m+1;<br>
cnt:=0;<br>
d<=0;<br>
if a<=b then <br>
s(c)<=m;<br>
m:="0000";<br>
if c=1 then <br>
k<=5;<br>
else<br>
k<=7;<br>
c<=c-1;<br>
if a(31 downto 28)=0 then<br>
a<=a(27 downto 0)&"0000";<br>
else<br>
b<="0000"&b(31 downto 4);<br>
end if;<br>
end if;<br>
else<br>
k<=3;<br>
end if;<br>
when 7=>if a>=b then<br>
k<=3;<br>
else<br>
a<=a(27 downto 0)&"0000";<br>
s(c)<=m;<br>
if c>=2 then<br>
c<=c-1;<br>
else<br>
k<=5;<br>
end if;<br>
end if;<br>
when 5=>a<=bei;<br>
b<=chu;<br>
shang<=s(8)&s(7)&s(6)&s(5)&s(4)&s(3)&s(2)&s(1);<br>
k<=6;<br>
dian<=n;<br>
n<=7;<br>
m:="0000";<br>
c<=8;<br>
cnt:=0;<br>
when 6=>if a(31 downto 28)=0 then<br>
a<=a(27 downto 0)&"0000";<br>
if n>=0 then <br>
n<=n-1;<br>
else<br>
n<=7;<br>
k<=5;<br>
end if;<br>
else<br>
k<=1;<br>
end if;<br>
<br>
when others=>k<=5;<br>
end case;<br>
end if;<br>
end process; <br>
end Behavioral;<br>
<br>
[ 本帖最后由 oaktwig 于 2007-1-31 17:03 编辑 ] |