首页 文章

使用条件信号赋值时VHDL小错误(当...其他时)

提问于
浏览
0

我目前正在开发一个可以执行加法或减法的组件,具体取决于用户输入 . 现在,我正在研究一个处理内部信号值的赋值的过程,这些内部信号将由我正在使用的内部组件使用 . 当我用输入b或输入b的2的补码分配b_in时,出现的一个问题是在行中 . 出现两个错误:

错误:COMP96_0015:addsub_16.vhd:(85,17):';'预期 . 错误:COMP96_0046:addsub_16.vhd:(85,41):预期的顺序语句 . 当add_sub ='0'时,错误全部引用行b_in <=(b)(b_2scomp);但是当我把它放在过程之外时,没有发生错误;只有当它在过程中 . 有人可以帮助我为什么这样做以及我能做些什么来解决它?

另外,我知道通常端口映射是在体系结构声明和体系结构的begin语句之间完成的 . 我在这个过程之后放置它们的原因是因为我需要确保b_in在其他组件可以使用它之前有正确的信号 . 我不知道这是否是正确的方法,但我希望是这样 . 这是为了以防万一你们想知道我为什么这样做 . 谢谢

library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.STD_LOGIC_UNSIGNED.all;  
use IEEE.STD_LOGIC_ARITH.all;

entity addsub_16 is
     port(
         c_in : in STD_LOGIC; 
         enable : in std_logic;
         reset : in std_logic;
         clk : in std_logic;
         add_sub : in STD_LOGIC;
         a : in STD_LOGIC_VECTOR(15 downto 0);
         b : in STD_LOGIC_VECTOR(15 downto 0);
         c_out : out STD_LOGIC;
         result : out STD_LOGIC_VECTOR(15 downto 0)
         );
end addsub_16;

architecture addsub_16 of addsub_16 is 

--Signal declarations to hold internal vectors a, b g, p, and carry
signal a_in : std_logic_vector(15 downto 0);        --Holds input a
signal b_in : std_logic_vector(15 downto 0);        --Holds input b if add_sub = 0. Otherwise, holds b_2scomp
signal b_2scomp : std_logic_vector(15 downto 0);    --Holds the 2s complement of b
signal prop_in : std_logic_vector(15 downto 0);     --Holds the propagate signals from CLAs
signal gen_in : std_logic_vector(15 downto 0);      --Holds the generate signals from CLAs
signal carry_in : std_logic_vector(15 downto 0);    --Holds the carry signal from carry_logic 
signal temp_result : std_logic_vector(15 downto 0); --Holds the temporary result to be driven out

--Component declarations 
component cla_4bit
    port (
        a, b : in std_logic_vector(3 downto 0);
        gen, prop : out std_logic_vector(3 downto 0)
        );
end component;

component carry_logic
    port (
        g, p : in std_logic_vector(15 downto 0);
        c_in : in std_logic;
        carry : out std_logic_vector(15 downto 0);
        c_out : out std_logic
    ); 
end component;

--Actual behavior of module
begin   

--b_in <= (b) when add_sub = '0' else (b_2scomp);

    process (clk, reset)
    begin 
        if reset = '0' then                 --At reset, everything is 0
            a_in <= (others => '0');
            b_in <= (others => '0');
            b_2scomp <= (others => '0');
            temp_result <= (others => '0');

        elsif (rising_edge(clk)) then       --Read in data to components on rising edge
            if enable = '1' then            --Only if enable is on
                a_in <= a;
                b_2scomp <= ((not b) + '1');
                b_in <= (b) when add_sub = '0' else (b_2scomp);             
            end if;
        elsif (falling_edge(clk)) then      --Drive out values on falling edge
            for i in 0 to 15 loop
                temp_result(i) <= a_in(i) xor b_in(i) xor carry_in(i);
            end loop;
            result <= temp_result;  
        end if;
    end process;

--portmapping of the components here. I don't think it'd be necessary to include them, but let me know if they are needed.

1 回答

  • 2

    在VHDL-2008之前的进程块内不允许使用三元运算符 .. when .. else .. .

    解决方案1:编写一个普通的 if .. then .. else .. end if 语句
    解决方案2:在您的工具链中启用VHDL-2008支持
    解决方案3:编写一个函数,让我们说一下执行三元运算的ite(if-then-else) .

相关问题