【发布时间】:2020-06-17 06:29:54
【问题描述】:
我有这段代码可以计算 2 个数字的模
library IEEE;
use ieee.numeric_bit.all;
entity resto is
port (clock , reset : in bit ;
inicio : in bit ;
fim : out bit ;
dividendo , divisor : in bit_vector (15 downto 0) ;
resto : out bit_vector (15 downto 0)
) ;
end resto;
architecture processo of resto is
variable dividendovar : integer range 0 to 15;
begin
process(clock, reset) is
begin
if reset = '1' then
fim <= '0';
resto <= "0000000000000000";
elsif clock'event and clock = '1' and inicio = '1' then
dividendovar <= to_integer(unsigned(dividendo));
if (divisor = "0000000000000000") then
-- report "zero";
resto <= dividendo;
fim <= '1';
elsif (dividendovar = to_integer(unsigned(divisor))) then
-- report "menor";
-- report "dividendoaux vale "& integer'image(to_integer(unsigned(dividendoaux))) ;
resto <= "0000000000000000";
fim <= '1';
elsif (to_integer(unsigned(dividendo)) < to_integer(unsigned(divisor))) then
resto <= dividendo;
fim <= '1';
else -- comeca a subtrair
while (dividendovar > to_integer(unsigned(divisor))) loop
dividendovar := dividendovar - to_integer(unsigned(divisor));
end loop ;
resto <= bit_vector(to_unsigned(dividendovar, resto'length));
fim <= '1';
end if;
end if;
end process;
end architecture;
但是就行了
variable dividendovar : integer range 0 to 15;
我收到此错误“此处不允许使用非共享变量声明”。
我做错了什么或错过了什么的任何线索?
提前致谢!
【问题讨论】:
-
整个错误消息包括指向保留字
variable的行号和字符计数。非共享变量声明只能作为子程序参数声明、子程序声明项或进程声明项出现。您的 original question 将信号dividendo_n声明为块声明项。仅仅更改名称并将其声明为variable类是不够的。 -
您是否打算让 divendovar 只有 4 位(范围 0 到 15)?我猜它是 16 位。
-
另一个想法,你的 while 循环可能是不可合成的。您是否考虑过使用 for 循环并可能迭代不超过 N 次,其中 N 是除数中的位数?