当我尝试通过 Vivado 2022.2 中的模拟对其进行测试时,下面代码中描述的四位乘法器进入无限循环。乘法器的实现是“移位加法乘法”。测试台vhdl代码编写正确。
当我取消模拟时,应用程序允许我像调试器一样介入,并且看起来“while”循环无限运行,因为 N 没有递减。 我搜索了答案,并且还添加了敏感度列表,但它仍然显示相同的问题。
你对为什么 while 不停止并且 N 不递减有什么想法吗?或者其他地方是否有其他问题?
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity four_bit_multiplier is
Port ( x : in STD_LOGIC_VECTOR(3 downto 0);
y : in STD_LOGIC_VECTOR(3 downto 0);
result : out STD_LOGIC_VECTOR(7 downto 0) );
end four_bit_multiplier;
architecture Behavioral of four_bit_multiplier is
component eight_bit_adder is
Port (x : in STD_LOGIC_VECTOR(7 downto 0);
y : in STD_LOGIC_VECTOR(7 downto 0);
c_in: in STD_LOGIC;
c_out: out STD_LOGIC;
sum : out STD_LOGIC_VECTOR(7 downto 0) );
end component;
signal B : STD_LOGIC_VECTOR(7 downto 0);
signal Q : STD_LOGIC_VECTOR(7 downto 0);
signal A : STD_LOGIC_VECTOR(7 downto 0) := x"00";
signal adder_out : STD_LOGIC_VECTOR(7 downto 0);
signal c_out : STD_LOGIC;
signal N: integer := 4;
begin
p1: eight_bit_adder port map(B, A, '0', c_out, adder_out);
process(x, y, B, N, Q, adder_out)
begin
B <= "0000" & x;
Q <= "0000" & y;
while N > 0 loop
if Q(0) = '1' then
A <= adder_out;
end if;
B <= B(6 downto 0) & '0';
Q <= '0' & Q(7 downto 1);
N <= N - 1;
end loop;
result <= A;
end process;
end Behavioral;
请记住,VHDL 是一种描述语言,而不是编程语言。不过,它包含此类功能,但仅用于模拟。
带有
while
的循环通常不可合成。相反,请使用 for
循环。