User defined variables can be of type char, byte, ubyte, int, uint, long, ulong and float
- variables of type char are stored in one 8 bit RAM location and can store a value in the range 0 to 255
- variables of type byte are stored in one 8 bit RAM location and can store a value in the range -128 to +127
- variables of type ubyte are stored in one 8 bit RAM location and can store a value in the range 0 to 255
- variables of type int are stored in two consequtive 8 bit RAM locations in little endian format and can store a value in the range -32768 to +32767
- variables of type uint are stored in two consequtive 8 bit RAM locations in little endian format and can store a value in the range 0 to 65535
- variables of type long are stored in four consequtive 8 bit RAM locations in little endian format and can store a value in the range -2,147,483,648 to +2,147,483,647
- variables of type ulong are stored in four consequtive 8 bit RAM locations in little endian format and can store a value in the range 0 to 4,294,967,295
- variables of type float are stored in four consequtive 8 bit RAM locations in IEEE 754 format and can store a value in the range ...
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+3When 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.e.g. x = arr[j+3]XCSB uses six variable allocation schemesi.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]
- global
- local
- argument (formal parameters)
- constant
- constant array
- hardware control register
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 exitsConstant
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:
- a constant array cannot be written to while the program is running (it is read only)
- it is stored in non-volatile code space
- it is slower to access than a RAM array (requireing more instructions on the 14 bit PIC)
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.