【问题标题】:How do I find the array index with its highest value with vhdl?如何使用 vhdl 找到具有最高值的数组索引?
【发布时间】:2019-08-27 04:53:31
【问题描述】:

我想找到具有最高值的数组索引。因此,是否可以简单地使用 vhdl 属性?如果有,怎么做?

TYPE x_Array IS ARRAY (0 TO 3) OF STD_LOGIC_VECTOR(2 DOWNTO 0);      
SIGNAL y : x_Array;

示例:

x_Array(0) = "000"
x_Array(1) = "011"
x_Array(2) = "111"
x_Array(3) = "101"


index <= x_Array'high;    -- is this correct or..?

问题: 如何在 vhdl 中获取 2 的索引(x_Array(2) 具有最高值 (7))?

【问题讨论】:

  • 对不起 - 我不明白。你想知道最高指数吗?在这种情况下,答案是肯定的:使用'HIGH。或者您想知道具有最高值的元素的索引吗?在这种情况下,答案是:不。
  • 定义的数组没有最高值的元素。
  • @MatthewTaylor 我编辑了我的问题。我想知道值最高的元素的索引。
  • 编辑后:定义的数组仍然没有最高值的元素。

标签: vhdl


【解决方案1】:

正如所写,您的问题没有意义:std_logic_vector 需要解释才能被视为数字。

所以让我们假设你知道这一点并写了明智的

library ieee;
use ieee.numeric_std.all;
use ieee.std_logic_1164.all;
type x_array is array(integer range <>) of unsigned(2 downto 0);      
signal y : x_array(0 to 3);

只写函数

function maxindex(a : x_array) return integer is
  variable index : integer := 0;
  unsigned foundmax : unsigned(2 downto 0) := (others => '0');
begin
  for i in 0 to a'high loop
    if a(i) > foundmax then
      index := i;
      foundmax := a(i);
    end if;
  end loop
  return index;
end function;

并根据需要申请。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-12
    • 2013-05-06
    • 2018-04-25
    • 2016-08-21
    • 2014-05-19
    • 1970-01-01
    • 2012-11-25
    相关资源
    最近更新 更多