我正在尝试创建一个减少长度的std_logic_vectors数组。我尝试用一个通用的std_logic_vector创建一个数组,然后使用generate语句来生成向量。
architecture behavioral of dadda_mul_32bit is
type and_planes is array (0 to 31) of std_logic_vector;
begin
generate_and_plane:
for i in 0 to 31 generate
and_planes(i) <= and_vector(a, b(i), i);
end generate generate_and_plane;
end behavioral;以及返回泛型std_logic_vector的函数:
function and_vector(vec: std_logic_vector; x: std_logic; length: natural) return std_logic_vector is
variable result: std_logic_vector(length - 1 downto 0);
begin
for i in 0 to length - 1 loop
result(i) := vec(i) and x;
end loop;
return result;
end function;我是否不正确地使用generate语句?
发布于 2017-08-13 21:58:27
and_planes是一个类型而不是一个信号,所以您不能分配给它!更多的是,您正在创建一个部分受限的类型,它需要在一个对象(例如信号)声明中受到约束。
VHDL不支持粗糙数组。(每个元素大小不同的数组)。如果你需要这个来模拟,你可以像C中那样使用访问类型和模拟粗糙的数组,如果你需要它来合成,那么你可以用一个一维数组和一些函数来模拟一个粗糙的数组来计算嵌套向量的边界。
请看我的回答:
顺便说一句。VHDL-2008增加了一个过载:"and"(std_logic, std_logic_vector),因此不需要任何函数来计算向量中每一个位的位数。
-- slice 'a' and gate it by 'b(i)'
and_planes(i) <= a(i downto 0) and b(i); https://stackoverflow.com/questions/45664647
复制相似问题