【问题标题】:If...else error (newbie, VHDL)If...else 错误(新手,VHDL)
【发布时间】:2014-11-15 16:48:48
【问题描述】:

我在让这段代码工作时遇到问题:

if(s="00") then
    f3 <= x and not(y);
elsif(s="11") then 
    f3 <= not(y) xor x;
else 
    f3 <= x or y;
end if;

地点:

f3 : out std_logic_vector(2 downto 0);
x, y : in std_logic_vector(2 downto 0);
s : in std_logic_vector(1 downto 0)    

当然,我不能真正依赖编译错误消息,因为它们并没有具体说明错误。提前致谢!

整个代码:

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity cw1 is
port(
    f0, f2 : out std_logic;
    f3 : out std_logic_vector(2 downto 0);
    a0, a1, a2, a3, a4 : in std_logic;
    x, y : in std_logic_vector(2 downto 0);
    s : in std_logic_vector(1 downto 0)
);
end entity;

architecture A of cw1 is
    signal s1 : std_logic_vector(3 downto 0);
    signal a : std_logic_vector(2 downto 0);
begin
    s1 <= a0 & a1 & a2 & a3;
    a <= a0 & a1 &a2;

with a select
    f2 <= not(a4) when "000",
            a3 when "001"|"010"|"101"|"111",
            a4 or not(a3) when "011"|"100",
            '-' when "110",
            'X' when others;

if s="00" then
    f3 <= x and not(y);
elsif s="11" then 
    f3 <= not(y) xor x;
else 
    f3 <= x or y;
end if;

end A;

【问题讨论】:

  • 什么错误? 将什么定义为“工作”?
  • 错误是没有编译。错误 (10500):zA.vhd(36) 附近文本“if”处的 VHDL 语法错误;期待“end”或“(”,或标识符(“if”是保留关键字),或并发语句和错误 (10500):zA.vhd(36) 附近文本“then”处的 VHDL 语法错误;期待"
  • 错误出现在这段代码之前,并且解析器不同步。您可以消除所有括号。条件句周围不需要它们,并且 not 运算符不是函数。
  • 错误消息是特定于错误的 - “...或并发语句”。您在并发区域中使用 if ... then,而它应该在进程中使用。你可以在这里使用条件赋值表f3 &lt;= x and not y when s = "00" else ...
  • 这就是问题@BrianDrummond - 我必须在我的课程中使用 if-else 来证明我可以。

标签: if-statement vhdl


【解决方案1】:

如果你想使用if,你必须把它放在一个进程中:

process(s, x, y)
begin
  if(s="00") then
     f3 <= x and not(y);
  elsif(s="11") then 
     f3 <= not(y) xor x;
  else 
     f3 <= x or y;
  end if;
end process;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-18
    • 2019-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多