【问题标题】:Strange behavior of VHDL if statementVHDL if 语句的奇怪行为
【发布时间】:2015-03-15 21:20:17
【问题描述】:

我在处理我的项目时遇到了 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

【问题讨论】:

    标签: if-statement vhdl


    【解决方案1】:

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

    在您的情况下,只有 inst 在您的敏感度列表中。因此,当 regDst 从 '0' 变为 '1' 时,进程将不会被执行(如果 inst 没有改变)并且 rd em> 不会更新。

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

    process(inst, regDst)
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多