Syntax:
type array_name is array (index_description) of element_type;
Possibilities for index_description:
index_range | integer range
index_type | enumeration type as index
index_type range index_range | general description
index_type range <> unconstrained type;
range must be specified in variable/signal declaration
Certain characteristics of arrays are explained in the following examples:
Example:
type INSTRUCTION is
(ADD, SUB, LDA, LDB, STA, STB, OUTA);
subtype FLAGS is integer range (0 to 7);
...
- array of flag values
type INSTR_FLAG is array (INSTRUCTION) of FLAGS;
Example:
...
process ...
type T_SHIFT_MEM is array (0 to 7) of integer;
variable SHIFT_MEM : T_SHIFT_MEM;
begin
... DATA_OUT <= SHIFT_MEM(7); for I in 7 downto 0 loop
SHIFT_MEM(I) := SHIFT_MEM(I-1);
end loop;
SHIFT_MEM(0) := DATA_IN;
end process;
Example:
- the declaration within the package STANDARD:
type BIT_VECTOR is array (NATURAL range <>) of BIT;
...
- now the index range becomes restricted:
variable BYTE: BIT_VECTOR (0 to 7);
Example:
type AVEC is array (0 to 3) of bit;
type BVEC is array (3 downto 0) of bit;
...
variable AV: AVEC;
variable BV: BVEC;
...
AV := "
0101"
;
AV(0)='0' AV(1)='1' AV(2)='0' AV(3)='1'
BV := "
0101"
;
BV(0)='1' BV(1)='0' BV(2)='1' BV(3)='0'
Syntax for named association:
[typ_name'] optional type qualifier
(selector => expression{,
selector => expression}[,
others => expression] )
Example:
variable C: BIT_VECTOR (0 to 3);
variable H, I, J, K: bit;
possible assignments
C := "
1010"
; 4-bit string
C := H & I & J & K; concatenation
C := ('1', '0', '1', '0'); aggregate
array aggregates
C := ('1', I, '0', J or K); positional association
C := (0=>'1', 3=>J or K, 1=>I, 2=>'0'); named association
C := ('1', I, others => '0'); mixed
An aggregate is a set of comma-separated elements enclosed in
parenthesis.
Example:
variable A: BIT_VECTOR (3 downto 0);
variable B: BIT_VECTOR (8 downto 1);
...
B(6 downto 3) := A;
Example:
type MEMORY is array (0 to 7, 0 to 3) of bit;
... 8x4 bit array
constant ROM: MEMORY := ( ('0','0','0','0'),
('0','0','0','1'),
('0','0','1','0'),
('0','0','1','1'),
('0','1','0','0'),
('0','1','0','1'),
('0','1','1','0'),
('0','1','1','1'));
variable DATA_BIT: bit;
...
- access to one element:
DATA_BIT := ROM (5,3); is '1'
It is possible to declare an array type which is an array of an
other array type. Note the difference in adressing a
two-dimensional array of the above the example and an array of an
array like the example below.
Example:
type WORD is array (0 to 3) of bit; a 4-bit storage element
type MEMORY is array (0 to 7) of WORD; 8x 4-bit array
...
constant ROM: MEMORY := ( ('0','0','0','0'),
('0','0','0','1'),
...
('0','1','1','1'));
variable DATA: WORD;
variable DATA_BIT: bit;
variable ADDR, INDEX: integer;
...
DATA := ROM (ADDR);
DATA_BIT := ROM (ADDR)(INDEX);
Example:
subtype BYTE is BIT_VECTOR (7 downto 0);
subtype of the unconstrained type BIT_VECTOR
The following array types are predefined in the appropriate packages:
In order to use logic or arithmetic operators with the type STD_LOGIC_VECTOR it is necessary to specify
whether the value should be interpreted as unsigned or signed (see 5 on page ). Where
appropriate, this must be done by type conversion functions (see
2.5.3 on page
) or by declaring
the data object of the adequate type. The following two
data types are predefined in the package STD_LOGIC_ARITH
or NUMERIC_STD:
Example:
type TWO_DIGIT is numbers from -99 to +99
record SIGN: bit;
MSD : integer range 0 to 9;
LSD : integer range 0 to 9;
end record;
...
process ...
variable ACNTR, BCNTR: TWO_DIGIT;
begin
ACNTR.SIGN := '1'; access to a element
ACNTR.MSD := 1;
ACNTR.LSD := ACNTR.MSD;
...
BCNTR := TWO_DIGIT'('0',3,6); aggregate, type qualified
...
end process;