architecture 中不能有 if 语句。 architecture 中的关键思想是所有语句的并行执行没有order 的概念。例如,
architecture Struct of Counter
signal A1: bit;
signal A2: bit;
begin
A1 <= A2 and '1';
A2 <= '1';
end Struct;
如果这是一个顺序块,A1 将输出0,因为A2 最初采用其默认值0。但是 VHDL 的算法巧妙地多次执行该块,给出了两个语句 A1 <= A2 and '1'; 和 A2 <= '1'; 同时发生的效果。
因此,如果您运行此代码,您将获得 A1 为 1 和 A2 为 1。
回答您的问题,if 是一个 顺序 语句,由于其顺序性,不能在进程内。但是,when 可以直接用于提供多路复用器的效果。
查看您的代码,您似乎想要制作一个级别敏感的锁存器。这就是你可以做到的。
architecture behavior of IR_REG is
signal temp: std_logic_vector(1 downto 0);
begin
process(IR_LD, Input, temp, clk)
begin
if IR_LD = '1' and clk = '1' then
temp <= Input;
end if;
if IR_LD = '1' and clk = '0' then
IR <= temp;
end if;
end process;
end behavior;
此代码将产生多路复用器效果,但您似乎想创建一个如上所示的锁存器。
architecture behavior of IR_REG is
signal temp: std_logic_vector(1 downto 0);
begin
temp <= Input when clk = '1' and IR_LD = '1' else "00";
IR <= temp when clk = '0' and IR_LD = '1' else "00";
end behavior;