fpga_feixiang 发表于 2018-7-4 16:08:36

VHDL中数组的定义和使用

一维数组(又叫向量),直接定义,如: avariable DATA:std_logic_vector(3 downto 0);---DATA是四位向量,
变量赋值:
DATA:="1111";

DATA(3):='1;



二维数组:

type matrix_type IS array (7 downto 0) of std_logic_vector (7 downto 0);

signal matix : matrix_type; -----matix 是二维8*8数组,
信号赋值:
matrix(3)(4)<='1';

matrix(2)<="11111111";

matrix(1 downto 0)(2)<="11";
--定义matrix_index 为数组

TYPE matrix_index is array (3 downto 0) of std_logic_vector(7 downto 0);

SIGNAL a: matrix_index;--定义了数组a,即数组元素为a,a,a,a

constant R : matrix_index:=( x"15", x"0F", x"0A", x"06");--定义了常数数组R

--使用时跟C语言中一样,加下标就可以了,上面是用downto定义了方向,故R是最后一项,如在R数组中R=X"06",R=X"15
页: [1]
查看完整版本: VHDL中数组的定义和使用