错误:带移位单元的“表达式不恒定”

时间:2019-04-14 21:25:04

标签: vhdl

我写了下面的代码,以便对二进制数进行移位,我尝试将其编译为设备cyclonII-EP2C20F484C7,但收到此错误:

Error (10779): VHDL error at shiftNbits.vhd(30): expression is not constant

Error (10658): VHDL Operator error at shiftNbits.vhd(30): failed to evaluate call to operator ""&""

vhd(30)是一行:

resultTemp  <= A( N-1-numberOfShifts downto 0) & (numberOfShifts-1 downto 0 => '0');

我看到有人问了这个问题,他们得到的答案是编译器不喜欢N-1-numberOfShiftsnumberOfShifts-1否定的想法。问题是我确保numberOfShifts

if  numberOfShifts>=N then
    resultTemp  <= (N-1 downto 0 => '0');

我什至尝试将范围添加到numberOfShifts定义中:

variable numberOfShifts: integer range 1 to N-1;

为了确保numberOfShifts-1不为负。

当我捐赠A(0 downto 0)时,实际上得到了一个位向量,如果A( -1 downto 0)不合法,如何定义NULL向量?

library ieee;
use ieee.numeric_std.all;
use ieee.std_logic_1164.all;
entity shiftNbits is
  generic(N: integer := 8);
  port (
    typeOfShift :    in std_logic_vector (1 downto 0);
    enable : in std_logic;
    A :      in std_logic_vector(N-1 downto 0);
    B :      in std_logic_vector (N-1 downto 0);
    result : out std_logic_vector(N-1 downto 0)
    );
end shiftNbits;

architecture shiftNbitsGate of shiftNbits is
    signal resultTemp: std_logic_vector(N-1 downto 0);
    begin
        process (typeOfShift, enable, A, B)
        variable numberOfShifts: integer;
        begin
        numberOfShifts:=  to_integer(unsigned(B)); 
        if enable= '1' then
            case typeOfShift is
                when "00" => --RLA
                    if  numberOfShifts>=N then
                        resultTemp  <= (N-1 downto 0 => '0');
                    else
                        resultTemp  <= A( N-1-numberOfShifts downto 0) & (numberOfShifts-1 downto 0 => '0');
                    end if;
                when "01" => --RLC
                    numberOfShifts := numberOfShifts mod N;
                    resultTemp <=  A( N-1-numberOfShifts downto 0) & A( N-1 downto N-numberOfShifts);
                when "10" => --RRA
                    if  numberOfShifts>=N then
                        resultTemp  <= (N-1 downto 0 => A(N-1));
                    else    
                        resultTemp <=  (N-1 downto N-numberOfShifts => A(N-1)) & A( N-1 downto numberOfShifts);
                    end if;                             
                when "11" => --RRC
                    numberOfShifts := numberOfShifts mod N;
                    resultTemp  <=  A( numberOfShifts-1 downto 0) & A( N-1 downto numberOfShifts);
                when others => null;
            end case;
        else
        resultTemp <= A; --what we should insert here?
        end if;
        end process;
        result <= resultTemp;
    end shiftNbitsGate;

1 个答案:

答案 0 :(得分:1)

resultTemp <= A( N-1-numberOfShifts downto 0) & (numberOfShifts-1 downto 0 => '0'); 无法在硬件中以一条“线”(一组门/一个逻辑方程式)实现,因为它可能对应于许多不同的情况(每班次一个)。
在VHDL中,您需要使用if else或case select扩展所有这些可能性。
如果平移值恒定,则代码确实可以合成,因此会出现错误消息!