VHDL Programming

(C. Jardin) #1

Data Types 97


PROCESS(X)

TYPE fifo_element_t IS ARRAY(0 TO 3)
OF std_logic; --line 1

TYPE fifo_el_access IS
ACCESS fifo_element_t; --line 2

VARIABLE fifo_ptr : fifo_el_access := NULL; --line 3
VARIABLE temp_ptr : fifo_el_access := NULL; --line 4
BEGIN

temp_ptr := new fifo_element_t; --Ok line 5
temp_ptr.ALL := (‘ 0 ’, ‘ 1 ’, ‘ 0 ’, ‘ 1 ’); --Ok line 6

temp_ptr.ALL := (‘ 0 ’, ‘ 0 ’, ‘ 0 ’, ‘ 0 ’); --Ok line 7
temp_ptr.ALL(0) := ‘ 0 ’; --Ok line 8

fifo_ptr := temp_ptr; --Ok line 9
fifo_ptr.ALL := temp_ptr.ALL; --Ok line 10
END PROCESS;

In line 2, an access type is declared using the type declared in line 1.
Lines 3 and 4 declare two access type variables of fifo_el_accesstype
from line 2. This process now has two access variable objects that can be
used to access objects of type fifo_element_t.
Line 5 calls the predefined function NEW, which allocates enough memory
for a variable of type fifo_element_tand returns an access value to
the memory allocated. The access value returned is then assigned to
variable temp_ptr. Variable temp_ptris now pointing to an object of type
fifo_element_t. This value can be read from or assigned to using variable
assignment statements.
In line 6, a value is assigned to the object pointed to by temp_ptr. Line
7 shows another way to assign a value using an access value. The key-
word .ALLspecifies that the entire object is being accessed. Subelements
of the object can be assigned by using a subelement name after the access
variable name. Line 8 shows how to reference a subelement of an array
pointed to by an access value. In this example, the first element of the
array will have a value assigned to it.
In the next few statements, we examine how access values can be
copied among different objects. In line 9, the access value of temp_ptris
assigned to fifo_ptr. Now both temp_ptrand fifo_ptrare pointing to
the same object. This is shown in Figure 4-3.
Both temp_ptrand fifo_ptrcan be used to read from and assign to
the object being accessed.
Line 10 shows how one object value can be assigned to another using
access types. The value of the object pointed to by temp_ptris assigned
to the value pointed to by fifo_ptr.
Free download pdf