VHDL 3-8解码器在“ else”和“ process”附近使用if else语法错误

时间:2019-03-09 14:42:14

标签: if-statement syntax vhdl decoder

我一直在尝试编译该程序,并尝试根据对错误消息的理解进行编辑,从而增加了错误数量。这是我编写的第二个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

this is the error message

更新

我分别将else if更改为elsifelse

Now I'm getting all these errors

我尝试从then中删除else,但出现类似错误

    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;

2 个答案:

答案 0 :(得分:0)

您需要更改块中所有以

开头的其他内容
interface Props {
    theme?: object; //Or whatever type it is
}

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

“ else”关键字未声明特定的语句。它仅用于检查一个条件并在不满足条件时执行某些操作。

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

下面给出了正确的代码。

if (A="000") then
 .
 .
 .
end if;

答案 1 :(得分:-1)

您为什么只想使用else语句,因为解码器是一种组合逻辑,因此您可以使用case语句来设计逻辑,这会更合适。