VHDL:可以用数组作为参数调用函数,它可以返回一个数组吗?

时间:2016-12-07 08:53:10

标签: arrays function vhdl

我确信它可以完成,但是在类型命名中陷入困境。

VHDL函数=      函数 function_name 参数:类型)返回类型

    *parameters* = a label for an input parameter to the function.
    *type* = the type of the parameter, like std_logic, std_logic_vector, string or other.   

VHDL数组=      类型 type_name element_type 的数组(范围

    *range* = The range of elements the array is going to occupy.
    *element_type* = The type of each element in the array. "type" is like the type discussed for the function.

数组定义了自己的类型。

如何将其指定为函数的参数类型?

当在函数中使用数组时,如何将其指定为函数的返回值?

有人可以提供一些或一些例子吗?

提前致谢。

1 个答案:

答案 0 :(得分:2)

VHDL的一大优点是它是一种经过深思熟虑且一致的语言。如果做某事是有道理的,你通常可以;如果你可以在一个地方做某事,你通常可以在另一个地方做。函数的所有输入都必须有一个类型;函数的返回值必须具有类型。如你所说,数组是一种类型。因此,函数的输入和返回值可以是数组。这是一个例子:

  type MY_ARRAY is array (0 to 9) of integer;

  function MY_ARRAY_FUNC (I : MY_ARRAY) return MY_ARRAY is
  begin
    return (9,8,7,6,5,4,3,2,1,0);
  end function;

https://www.edaplayground.com/x/njv

相关问题