【问题标题】:VHDL : writing an AND functionVHDL:编写 AND 函数
【发布时间】:2014-07-26 21:00:19
【问题描述】:

所以我试图编写一个执行与门的函数,输入是门输入的向量,以及输入的数量。但是由于某种原因,编译器给了我一个错误,它由于某种原因无法识别内部使用的“和”逻辑运算符。谁能发现问题?

p.s 这是一个更大项目的一部分,该项目是一个 16counter (0-15),由 4 个链式 JK 触发器和 2 个 AND 门(使用我的“myand”函数)组成。

function myand (x: std_logic_vector; n : integer range 7 downto 0) return std_logic is
    variable result: integer :=0;
begin
    for i in 0 to n-1 loop
        result:=result and x(i);
    end loop;
    return result;
end function;

编译错误是:

Error (10327): VHDL error at counter16.vhd(16): can't determine definition of operator ""and"" -- found 0 possible definitions

我什至尝试使用 '+' 而不是 'and' 但它还是同样的错误。

【问题讨论】:

  • 并不意味着要弃用 sharth 的答案或您自己的努力,IEEE Std 1076-2008 (VHDL-2008) 为 andor、nandnorxorxnor 称为逻辑归约运算符。这些支持 std_logic_vector(std_ulogic_vector 的子类型),并且可能支持也可能不支持特定供应商的综合工具。 Recend Modelsim 和 Aldec VHDL 模拟器将支持这些 VHDL-2008 运算符。

标签: vhdl


【解决方案1】:

VHDL 的内置库没有定义运算符 and,它接受 integerstd_logic

如何解决这个问题:

  • result 应该是 std_logic 而不是 integer
  • result 应初始化为 '1' 而不是 0

【讨论】:

  • 天哪,我不敢相信我没有注意到尝试在其中输入 2 种不同的类型:P 谢谢!希望其余的现在也能正常工作
【解决方案2】:

如果在x 上使用'range 属性来获取索引值,则可以通过删除“n”参数来简化函数接口。如果将 std_logic_vector 的子范围用作参数,则只能使用该子范围调用 myand 函数。包括sharth建议,功能是:

function myand (x : std_logic_vector) return std_logic is
    variable result : std_logic := '1';
begin
    for i in x'range loop
        result := result and x(i);
    end loop;
    return result;
end function;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-23
    • 1970-01-01
    • 1970-01-01
    • 2012-12-16
    相关资源
    最近更新 更多