【问题标题】:Syntax issue with a nested if statement in VHDLVHDL中嵌套if语句的语法问题
【发布时间】:2015-02-14 19:43:21
【问题描述】:

Modelsim 告诉我嵌套 if 语句存在语法问题,我无法确定问题所在。任何帮助都会很棒!

when ZERO =>
        if X_REG = '0' then 
            zero_sig <= '1';
            if zero_count = '15' then
               nextState <= ONE;
            else
               nextState <= ZERO;
            end if;
        else
            nextState <= ZERO;
            zero_reset <= '1';
        end if;

【问题讨论】:

  • 至少zero_count='15' 看起来不对。另外,使缩进匹配if 结构。
  • 更直接一点 - '15' 不是字符文字,对于这些信号和/或变量中的任何一个,声明也不可见。 5 是无关的,还是有相等性测试 zero_count 和整数文字?没有声明,您的示例是不完整的。需要解决的问题似乎都围绕着这种平等条件。

标签: vhdl modelsim nested-if


【解决方案1】:

假设zero_count 是数字(例如整数)类型:

when ZERO =>
    if (X_REG = '0') then 
        zero_sig <= '1';
        if (zero_count = 15) then
           nextState <= ONE;
        else
           nextState <= ZERO
        end if;
    else
        nextState <= ZERO;
        zero_reset <= '1';
    end if;

是的,我知道括号不是必需的,但恕我直言,它们使 VHDL 代码更“可读”。

【讨论】:

  • 大卫对原始问题的评论解释了这一行更改背后的原因。
猜你喜欢
  • 1970-01-01
  • 2015-12-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多