【问题标题】:VHDL 3-8 decoder using if else syntax error near 'else' and 'process'VHDL 3-8解码器使用'else'和'process'附近的if else语法错误
【发布时间】:2019-07-31 09:16:09
【问题描述】:

我一直在尝试编译这个程序,并尝试根据我对增加错误数量的错误消息的理解进行编辑。这是我编写的第二个 VHDL 代码,我不确定我还能做什么

这是代码:

    entity maashro3o is
port (Q: out bit_vector (0 to 7);
        A: in bit_vector(2 down to 0);
        en: in bit);
end maashro3o;

architecture maashro3o of maashro3o is
begin


process(A, en)
begin

if (en = "1") 
then 
    if (A = "000") 
    then
        Q <= "10000000";
    else if (A = "001") then
        Q <= "01000000";
    else if (A = "010") then
        Q <= "00100000";
    else if (A = "011") then
        Q <= "00010000";
    else if (A = "100") then
        Q <= "00001000";
    else if (A = "101") then
        Q <= "00000100";
    else if (A = "110") then
        Q <= "00000010";         
    else if (A = "111") then
        Q <= "00000001";    

END If;
    else
        Q <= "00000000";
End If;

end process;

end maashro3o

更新

我将else if 分别更改为elsifelse

我试图从 else 中删除 then,但我遇到了类似的错误

    entity maashro3o is
port (Q: out bit_vector (0 to 7);
        A: in bit_vector(2 downto 0);
        en: in bit);
end maashro3o;

architecture maashro3o of maashro3o is
begin


process(A, en)
begin

if (en = '1') 
then 
    if (A = "000") 
    then
        Q <= "10000000";
    elsif (A = "001") then
        Q <= "01000000";
    else (A = "010") then
        Q <= "00100000";
    elsif (A = "011") then
        Q <= "00010000";
    else (A = "100") then
        Q <= "00001000";
    elsif (A = "101") then
        Q <= "00000100";
    else (A = "110") then
        Q <= "00000010";         
    elsif(A = "111") then
        Q <= "00000001";    

END If;
    else
        Q <= "00000000";
End If;

end process;

end maashro3o;

【问题讨论】:

  • 语法错误:1) 第 3 行,downto 是单个保留字 2) 第 14 行,en 不是复合数组类型;使用 '1' 而不是 "1" 3) 第 19、21、23、25、27、29、31 行,elsif 而不是 else if4) 第 41 行,缺少最后的分号。
  • 请注意,模拟器通常比合成器提供更好的错误消息。
  • @user1155120 非常感谢!我进行了更改,但现在我遇到了更多错误。我不确定是then 还是括号
  • 您的代码中没有任何括号,只有括号和some of those aren't needed
  • 这些elsees:else (A = "010") thenelse (A = "100") thenelse (A = "110") then 应该是elsifs。您应该能够通过校对找到所有这些语法错误。

标签: if-statement syntax vhdl decoder


【解决方案1】:

您需要更改块内以

开头的所有其他内容
if (A="000") then
 .
 .
 .
end if;

VHDL 中没有“else if”关键字。使用“elif”。在编写具有多个条件的 if-else 语句时,不应在 elsif 之后编写 else,反之亦然。你不能同时使用它们。

“else”关键字没有声明特定的语句。用于只检查一个条件,当条件不满足时做某事。

另外,在编写 VHDL 代码时,不要忘记包含您将需要和可能需要的库。

更正的代码如下。

library ieee;
use ieee.std_logic_1164.all;

entity maashro3o is
port (Q: out bit_vector (0 to 7);
        A: in bit_vector(2 downto 0);
        en: in bit);
end maashro3o;

architecture maashro3o of maashro3o is
begin


process(A, en)
begin

if (en = '1')  then 

    if (A = "000")  then
        Q <= "10000000";
    elsif (A = "001") then
        Q <= "01000000";
    elsif (A = "010") then
        Q <= "00100000";
    elsif (A = "011") then
        Q <= "00010000";
    elsif (A = "100") then
        Q <= "00001000";
    elsif (A = "101") then
        Q <= "00000100";
    elsif (A = "110") then
        Q <= "00000010";         
    elsif(A = "111") then
        Q <= "00000001";    
end if;

    else
        Q <= "00000000";
end if;

end process;

end maashro3o;

【讨论】:

    【解决方案2】:

    为什么要只用if else语句,因为decoder是组合逻辑,可以用case语句来设计逻辑,会更合适。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多