home | download | demos | platforms | restrictions | help |
What is an array?
An array is like a variable, but whereas a vaiable holds just one value at a time, an array can hold many values at the same time. To be able to identify exactly which of the values we wish to access at any one time, we refer to the number of the value within the array. This number is called the index and the value the index refers to within an array is called the element. In XCSB the element 3 of an array called FRED would be refered to as FRED[3]. The index can itself be a variable so XCSB will allow references to elements such as FRED[J].XCSB will allow an array element to be used anywhere where it will allow a simple variable.
e.g. X = BERT + 1 X = FRED[3] + 1 BERT = X + 10 FRED[3] = X + 10Many other PIC BASIC compilers do not support arrays or impose severe restrictions on their use.
Arrays are indespensible as buffers and lookup tables.
What is a data (RAM) array?
A data array (sometimes refered to as a RAM array), is an array that can have its elements modified like any other variable.What is a code space array?
A code space array (sometimes refered to as a constant array), is an array that can have its elements read from but not written to. Such arrays are used to store runtime lookup tables where the data is continually being read from but never needs to changed (once it has been set by the programmer). For instance a table of ideal height to weight ratios held in a weighing machine (controlled by a PIC). It is nonsence for the running program to try to change this information.The ability to specifically place an array in the PICs code space, removes the need to copy data from the non-volatile program area of the PIC into a RAM array when the PIC starts up, while keeping the benefits of random data access inherent in array lookups.
Some PIC BASIC compilers do not have code space arrays. Instead they rely on DATA and READ statements to scan sequentially through code space data. Unlike the values of an XCSB code space array which can be used directly in any expression, the data READ from a DATA statement needs to be loaded into a seperate variable before it can be used.
home | download | demos | platforms | restrictions | help |