VHDL if语句的奇怪行为

时间:2015-03-15 21:20:18

标签: if-statement vhdl

当我正在处理我的项目时,我遇到了VHDL if语句的一个奇怪问题。虽然我修好了,但我仍然不明白为什么会这样。我使用ModelSPIM刺激了我的代码。在我更改代码之前,我预计在rd <= inst (20 downto 16);时会RegDst = '1',但它会给我rd <= inst (15 downto 11);。我检查RegDst确实等于0,但它给了我错误的作业。我改变代码后,每一件事都变得正常了。他们之间有什么区别?

在:

fetch: process(inst)
begin
if( inst = x"0000_0000" ) then -- end of program
    endRun <= '1';
else
    endRun <= '0';
    opcode <= inst (31 downto 26);
    rs <= inst (25 downto 21);
    rt <= inst (20 downto 16);
    if( RegDst = '1' ) then
       rd <= inst (15 downto 11);
    else
       rd <= inst (20 downto 16);
    end if;
    funct <= inst (5 downto 0);
    offset <= inst (15 downto 0);
    jsec <= inst (25 downto 0);
end if;
end process fetch;      

后:

fetch: process(inst)
begin
if( inst = x"0000_0000" ) then -- end of program
    endRun <= '1';
else
    endRun <= '0';
    opcode <= inst (31 downto 26);
    rs <= inst (25 downto 21);
    rt <= inst (20 downto 16);
    funct <= inst (5 downto 0);
    offset <= inst (15 downto 0);
    jsec <= inst (25 downto 0);
end if;
end process fetch;      
   rd <= inst (15 downto 11) when (RegDst = '1') else
      inst(20 downto 16); -- RegDst mux

1 个答案:

答案 0 :(得分:2)

敏感度列表存在问题。灵敏度列表是处理后括号中的信号列表。当事件发生在其灵敏度列表中的任何信号上时,将执行一个过程。

在您的情况下,只有 inst 位于您的敏感列表中。因此,当 regDst 将从&#39; 0&#39;到&#39; 1&#39;,该过程将不会被执行(如果 inst 没有改变), rd 将不会更新。

在你的第二种方法中,语句不在一个过程中,因此不受灵敏度列表的影响(确切地说,在进程外语句中涉及的所有信号都被认为是它的敏感性列表)。如果您在敏感度列表中添加 redDst ,您将获得相同的结果:

process(inst, regDst)

请注意,灵敏度列表中缺少的信号是模拟和实现之间不匹配的常见原因,因为我知道的所有工具都会忽略它们的实现。如果您使用VHDL-2008,则可以在敏感度列表中使用关键字 all ,这意味着您的想法。

相关问题