您好,我正在尝试使用ARRAYS作为内存。我想将4个较小的ARRAYS连接成一个更大的ARRAY。我已尝试使用&符号执行此操作:
MEM_STRING(1) <= MEM_CHAR(3) & MEM_CHAR(3) & MEM_CHAR(0) & MEM_CHAR(1);
但是编译器说它找不到&amp;的定义。字符。 MEM_STRING(1)是28位,每个MEM_CHAR是7位。 我可以将每个MEM_CHAR转换为std_logic_vector,分配给一个信号然后连接,但这似乎是一个很长的路要走。还有其他办法吗?
TYPE SEG7 IS ARRAY (6 DOWNTO 0) OF std_logic;
TYPE REG_CHAR IS ARRAY (3 DOWNTO 0) OF SEG7; --Array block for characters
TYPE STRINGS IS ARRAY (27 DOWNTO 0) OF std_logic;
TYPE REG_STRINGS IS ARRAY (6 DOWNTO 0) OF STRINGS; --Array block for strings
SIGNAL MEM_CHAR : REG_CHAR; --Assign character
SIGNAL MEM_STRING : REG_STRINGS; --Assign String
这些是使用的ARRAY declerations。 最良好的问候 d
答案 0 :(得分:1)
我可以将每个MEM_CHAR转换为std_logic_vector,分配给一个信号然后连接,但这似乎是一个很长的路要走。还有其他办法吗?
MEM_CHAR和std_logic_vector并不密切相关。 MEM_CHAR的元素类型是SEG7,std_logic_vector的元素类型是std_ulogic。
您应该创建REG_CHAR类型的聚合并将其转换为STRINGS:
library ieee;
use ieee.std_logic_1164.all;
entity memchar is
end entity;
architecture foo of memchar is
TYPE SEG7 IS ARRAY (6 DOWNTO 0) OF std_logic;
TYPE REG_CHAR IS ARRAY (3 DOWNTO 0) OF SEG7; --Array block for characters
TYPE STRINGS IS ARRAY (27 DOWNTO 0) OF std_logic;
TYPE REG_STRINGS IS ARRAY (6 DOWNTO 0) OF STRINGS; --Array block for strings
SIGNAL MEM_CHAR: REG_CHAR; --Assign character
SIGNAL MEM_STRING: REG_STRINGS; --Assign String
function to_strings (REGC: REG_CHAR) return STRINGS is
variable retstr: STRINGS;
subtype strings_range is natural range STRINGS'RANGE;
variable retptr: strings_range; -- default value is STRINGS'LEFT
begin
for i in REG_CHAR'RANGE loop -- 3 downto 0
for k in SEG7'RANGE loop -- 6 downto 0
retstr(retptr) := REGC(i)(k);
if retptr /= 0 then -- quit decrementing at 0
retptr := retptr - 1;
end if;
end loop;
end loop;
return retstr;
end function;
begin
-- MEM_STRING(1) <= MEM_CHAR(3) & MEM_CHAR(3) & MEM_CHAR(0) & MEM_CHAR(1);
MEM_STRING(1) <= to_strings(REG_CHAR'(MEM_CHAR(3),
MEM_CHAR(3),
MEM_CHAR(0),
MEM_CHAR(1)
)
);
end architecture;
这个例子分析,阐述和模拟,它告诉我们聚合元素的总长度与STRINGS长度匹配。
请注意,从左到右的顺序保留在to_strings函数中。
对于所有这些迂回的定义来说,值得痛苦的是,如果没有提供Minimal, Complete, and Verifiable example的问题,那就更难了。
答案 1 :(得分:0)
如果不是:
TYPE SEG7 IS ARRAY (6 DOWNTO 0) OF std_logic;
TYPE STRINGS IS ARRAY (27 DOWNTO 0) OF std_logic;
你做了:
subtype SEG7 IS std_logic_vector(6 DOWNTO 0) ;
subtype STRINGS IS std_logic_vector(27 DOWNTO 0) ;
然后你可以这样做:
MEM_STRING(1) <= MEM_CHAR(3) & MEM_CHAR(3) & MEM_CHAR(0) & MEM_CHAR(1);
或者:
MEM_STRING(1) <= MEM_CHAR(3) & MEM_CHAR(2) & MEM_CHAR(1) & MEM_CHAR(0);
您也可以跳过创建子类型SEG7和STRINGS并完成:
--Array block for characters
TYPE REG_CHAR IS ARRAY (3 DOWNTO 0) OF std_logic_vector(6 DOWNTO 0) ;
--Array block for strings
TYPE REG_STRINGS IS ARRAY (6 DOWNTO 0) OF std_logic_vector(27 DOWNTO 0) ;
SIGNAL MEM_CHAR : REG_CHAR; --Assign character
SIGNAL MEM_STRING : REG_STRINGS; --Assign String