VARIABLES

User defined variables can be of type char, byte, ubyte, int, uint, long, ulong and float
here is more infomation on signed and unsigned numbers
 

The '[' and ']' characters together form the array operator. They are used to apply an index to an array and reference an element of the array.

The following example shows the array called arr, the array operator [ ] and the index which is the expression j+3
e.g.
	x = arr[j+3]
When the array operator is applied to a normal variable, it performs array indexing on the variable as if the variable has been defined as an array. Omitting the array operator from an array reference is equivalent to applying an index of 0.
i.e.
	int	arr[10], x, y

the following expressions are equivalent
	x = arr[0]
	x = arr

the following expressions are equivalent
	x = y
	x = y[0]
XCSB uses six variable allocation schemes
NOTE: the underlying XCASM assembler also supports PORT variables. these are variables which are not hardware control registers but which the assembler treats as not optimisable. PORT variables are typically used as control structures between an interrupt service routine and a device driver e.g. a mailbox. the XCSB HWREG statement uses a sub-set of the PORT variable facilities available in the XCASM assembler.

Global

Global valiables can be seen and used by all functions including functions used to service interrupts. Global variables retain their values unless explicitly modified by the user program.

Local

Local variables can only be seen and used by the function in which they are defined. If a local variable name is the same as an existing global variable or constant name then the local varible takes presidence within the body of the funcion while it is active (this is known as the scope of the variable).

When the function calls another function the variable retains its integrity unless explicitly modified by the called function via a reference passed by the calling function.

When the function exits, ALL RAM used by its local variables is available for reuse by other functions. Consequently a local variable may be modified between calls to the same function (the value of the variable is said to be undefined). If the integrity of a variable is to be maintained between function calls, use a global variable instead.

Argument (formal parameter)

Formal parameters behave like local variable in that the RAM used to store arguments is reused once a function exits

Constant

A constant does not require a RAM location store its value. A constant is a symbolic name assigned to a value at compile time. The compiler passes it to the assembler as a constant which the assembler then embeds directly into the generated code.

Constant Array

A constant array appears to the programmer like a normal RAM array, however:

Hardware Control Register

A hardware control register is like a global variable of type char except that the compiler will not perform certain types of optimisations on it.