The following code is an example of how to maintain an array of 8 data values in DM. Each time a new data point is added the old values are shifted to the "right". The values in the updated array are then averaged.
I suggest that you cut and paste this code into a custom function and run it in simulation.
' Update Array of 8 32-bit data values and compute running average.
'
' DM[1..16] holds 8 32-bit values. As DM[] is only 16-bits wide,
' it takes two entries in DM[] to hold a each 32-bit value.
'
' On entry, variable V holds the 32-bit value to be added to the array.
' On Exit, A holds the avearage of the 8 array values.
' Variables V and I are modified.
' Insert newest entry on the left, DM[1], and slide all old values right, towards
' DM[16]. Oldest value is discarded.
'
FOR I = 13 to 1 STEP -2 ' Shift old data
DM[I+2] = DM
DM[I+3] = DM[I+1]
NEXT
' Insert New Data Value into beginning of the array
'
DM[1] = V ' lower 16 bits of value V
DM[2] = getHIGH16(V)
' Sum value of array elements into A
'
A = 0
for I = 1 to 15 STEP +2
V = DM
SETHIGH16 V,DM[I+1]
A = A + V
NEXT
' Compute average value
'
A = A / 8
[/color]
Good Luck,
Gary D