为什么它的代码无法编译?

时间:2016-05-19 19:00:36

标签: vhdl

library IEEE;
use IEEE.STD_LOGIC_1164.all;

entity paralel_reg is
    generic ( default : positive := 4);
    port(C, notR, E: in std_logic; D: in std_logic_vector(default downto 1); 
    Q: out std_logic_vector(default downto 1)); 
end paralel_reg;

architecture paralel_reg of paralel_reg is
signal q : std_logic_vector(default downto 1);
begin
process (C, notR)
begin
    if notR = '0' then q <= (others => '0');
    else if rising_edge(C) then q <= D;  
    end if;
end process;  --# Error: COMP96_0019: paralel_register.vhd : (18, 5): Keyword "if" expected.
    --# Error: COMP96_0015: paralel_register.vhd : (18, 5): ';' expected.

process (E, q) --# Error: COMP96_0019: paralel_register.vhd : (24, 2): Keyword "end" expected.
begin
    if E = '0' then Q <= (others => '0');
    else Q <= q;        --# Error: COMP96_0019: paralel_register.vhd : (24, 2): Keyword "end" expected.
            --# Error: COMP96_0016: paralel_register.vhd : (24, 7): Design unit declaration expected.
    end if;
end process;
end paralel_reg;
  

#错误:COMP96_0019:paralel_register.vhd:(18,5):关键字&#34; if&#34;预期。   #错误:COMP96_0015:paralel_register.vhd:(18,5):&#39;;&#39;预期。   #错误:COMP96_0019:paralel_register.vhd:(21,1):关键字&#34;结束&#34;预期。   #错误:COMP96_0019:paralel_register.vhd:(24,2):关键字&#34;结束&#34;预期。   #错误:COMP96_0016:paralel_register.vhd:(24,7):预期的设计单位声明。

2 个答案:

答案 0 :(得分:1)

VHDL中不存在“Else If”,您必须写:

IF ... THEN
ELSIF ... THEN
ELSE 
END IF;

答案 1 :(得分:0)

此:

process (C, notR) begin
    if notR = '0' then q <= (others => '0');
    else if rising_edge(C) then q <= D;  
    end if; end process;

应该是这样的:

process (C, notR)
begin
    if notR = '0' then q <= (others => '0');
    elsif rising_edge(C) then q <= D;  
    end if;
end process;

VHDL if语句具有以下格式:

if ... then
  ...
elsif ... then
  ...
elsif ... then
  ...
else
  ...
end if;

所有VHDL语句都以分号结尾。以上是一个以end if;结尾的陈述。 VHDL语句可以嵌入到另一个语句中。因此,您可以在if语句中嵌入另一个if语句,如果您使用else if而不是elsif,这就是您正在做的事情:

if ... then
  ...
elsif ... then
  ...
elsif ... then
  ...
else
  IF ... THEN
    ...
  ELSIF ... THEN
    ...
  ELSE 
    ...
  END IF;
end if;

VHDL中的每个if语句都需要end if;。请注意,在上面的内容中,如果一个if语句嵌入另一个中,则有两个{​​{1}}个。所以,你可以写:

end if

但我总是建议使用process (C, notR) begin if notR = '0' then q <= (others => '0'); else if rising_edge(C) then q <= D; end if; end if; end process; 代替elsif,因为您需要的else if更少。

相关问题