【问题标题】:VHDL if statement errorVHDL if 语句错误
【发布时间】:2014-02-18 16:25:00
【问题描述】:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity mux is
port (sel: in std_logic; 
        s0,s1: in std_logic_vector (3 downto 0) ; 
        sout : out std_logic_vector (3 downto 0));  
end mux;

architecture Behavioral of mux is

begin
if sel = '0' then 
    sout <= s0; 
else 
    sout <= s1; 
end if; 

end Behavioral;

-- 我正在尝试为四位串行加法器输出制作多路复用器。如果 cin 为 0,那么它将采用 - 来自第一个加法器的总和,它有 cin 0,如果 cin 为 1,那么它将从第二个加法器中得到总和 - 我用 cin 1 提供的加法器。但是,如果某处我不能弄清楚。编译器在 if else 和 end if 语句附近说错误

【问题讨论】:

    标签: if-statement vhdl


    【解决方案1】:

    在具有适当敏感性列表的进程中使用 if-else 构造。

    `

    process(sel)
    begin
    (
       if sel = '0' then 
          sout <= s0; 
    else 
        sout <= s1; 
    end if; 
    );
    end process; 
    

    否则使用When Else 构造

    【讨论】:

      【解决方案2】:

      if 是一个顺序语句,所以它只出现在 process 内部。将if 替换为when,因为这是一个并发语句,因此可以直接在架构中使用:

      sout <= s0 when (sel = '0') else s1;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多