为什么它的代码无法编译?
Why it's code not compile?
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;
# Error: COMP96_0019: paralel_register.vhd : (18, 5): Keyword "if" expected.
# Error: COMP96_0015: paralel_register.vhd : (18, 5): ';' expected.
# Error: COMP96_0019: paralel_register.vhd : (21, 1): Keyword "end" expected.
# Error: COMP96_0019: paralel_register.vhd : (24, 2): Keyword "end" expected.
# Error: COMP96_0016: paralel_register.vhd : (24, 7): Design unit declaration expected.
"Else If"在VHDL中不存在,必须写成:
IF ... THEN
ELSIF ... THEN
ELSE
END IF;
这个:
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
语句嵌入另一个语句中,有两个 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
因为你需要的 end if
更少。
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;
# Error: COMP96_0019: paralel_register.vhd : (18, 5): Keyword "if" expected. # Error: COMP96_0015: paralel_register.vhd : (18, 5): ';' expected. # Error: COMP96_0019: paralel_register.vhd : (21, 1): Keyword "end" expected. # Error: COMP96_0019: paralel_register.vhd : (24, 2): Keyword "end" expected. # Error: COMP96_0016: paralel_register.vhd : (24, 7): Design unit declaration expected.
"Else If"在VHDL中不存在,必须写成:
IF ... THEN
ELSIF ... THEN
ELSE
END IF;
这个:
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
语句嵌入另一个语句中,有两个 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
因为你需要的 end if
更少。