0

我有这段代码可以计算 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;

我收到此错误"Non-shared variable declaration not allowed here"

我做错了什么或失踪的任何线索?

提前致谢!

4

1 回答 1

1

变量应该在 a 内声明process,因此具有受限的范围。

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
    begin

    process(clock, reset) is
    variable    dividendovar : integer range 0 to  15;
    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;

正如评论中提到的,全局共享变量在 VHDL2002 标准之前可用。如果仍然需要,我认为现在应该保护它们。但到目前为止,我遇到了一个需要变量的用例。

无论如何,只要有可能,我都会更喜欢signalsvariables所有的设计。

于 2020-06-17T06:41:06.337 回答