100 Chapter Four
data. It always points to the first element of the list of items in the stack.
Variable temp_elemis used to hold a newly allocated element until it is
connected into the stack list. Variable last_clkis used to hold the previ-
ous value of clkto enable transitions on the clock to be detected. (This
behavior can be duplicated with attributes, which are discussed in Chapter
7,“Configurations.”)
Line 12 checks to see if a 0 to 1 transition has occurred on the clk
input. If so, then the stack needs to do a read or write depending on the
r_wbinput. Line 13 checks to see if r_wbis set up for a write to the stack.
If so, lines 14 through 17 create a new data storage element and connect
this element to the list.
Line 14 uses the predefined function NEWto allocate a record of type
element_rec and return an access value to be assigned to variable
temp_elem. This creates a structure that is shown in Figure 4-4.
Lines 15 and 16 fill in the newly allocated object with the data from
input dinand the access value to the head of the list. After line 16, the
data structures look like Figure 4-5.
Finally, in line 17, the new element is added to the head of the list. This
is shown in Figure 4-6.
Lines 18 through 22 of the model provide the behavior of the stack
when an element is read from the stack. Line 19 copies the data from the
stack element to the output port. Lines 20 through 22 disconnect the
element from the stack list and return the memory to the system.
Line 20 assigns the temp_elemaccess variable to point to the head of
the list. This is shown in Figure 4-7.
Line 21 moves the head of the list to the next element in the list. This
is shown in Figure 4-8.
Stack Element
Data
NXT
Stack Element
Data
NXT
Stack Element
Data
NXT
List_Head
Temp_Elem
Figure 4-4
Allocate New Stack
Element.