Positron Compiler Documentation

Pre-Assigning Variables.

Positron8 · Revision 4.0.6.5 · PDF pages 20–22

When a variable is first created using the Dim directive, it can be given a value that will be assigned to it when the program runs. This can be useful to give variables a default value. For example:

  Dim tCat as Bit   = 1          ' Create a Bit variable and assign to it
  Dim bDog as Byte = 128        ' Create a Byte variable and assign to it
  Dim MyPin as Pin = 0          ' Create a Pin variable and assign to it
  Dim wRat as Word = 32768      ' Create a Word variable and assign to it
   Dim lRat as Long = 123456      ' Create a Long variable and assign to it
  Dim dRat as Dword = 12345678   ' Create a Dword variable and assign to it
  Dim fBoat as Float = 3.14      ' Create a Floating Point variable and assign to it

  Dim sbDog as SByte = -20        ' Create a signed Byte variable and assign to it
  Dim swRat as SWord = -12345       ' Create a signed Word variable and assign to it
  Dim sdLrg_Rat as SDword = -123456' Create a signed Dword variable and assign to it

If the above Dim directives were placed at the beginning of the program’s code, each variable will be assigned with its value when it is created.

View original PDF page 20Open page in PDFOriginal PDF page 20

Intuitive Variable Handling.

The compiler handles its System variables intuitively, in that it only creates those that it requires. Each of the compiler's built in library subroutines i.e. Print, Rsout etc, require a certain amount of System RAM as internal variables.

The compiler will increase its System RAM requirements as programs get larger, or more complex structures are used, such as complex expressions, inline commands used in conditions, Boolean logic used etc…

There are certain reserved words that cannot be used as variable names, these are the System variables used by the compiler.

The following reserved words should not be used as variable names, as the compiler will create these names when required: -

PP0, PP0H, PP1, PP1H, PP1HH, PP1HHH, PP2, PP2H, PP2HH, PP2HHH, PP3, PP3H,
PP4, PP4H, PP5, PP5H, PP6, PP6H, PP7, PP7H, PP7HH, PP7HHH, PP8, PP8H, PP9,
PP9H, GEN, GENH, GEN2, GEN2H, GEN3, GEN3H, GEN4, GEN4H, GPR, BPF, BPFH.

RAM space required. Each type of variable requires differing amounts of RAM memory for its allocation. The list below illustrates this.

FloatRequires 4 bytes of RAM.
DwordRequires 4 bytes of RAM.

SDword Requires 4 bytes of RAM.

LongRequires 3 bytes of RAM.
WordRequires 2 bytes of RAM.
SWordRequires 2 bytes of RAM.
ByteRequires 1 byte of RAM.
SByteRequires 1 byte of RAM.
PinRequires 1 byte of RAM.
BitRequires 1 byte of RAM for every 8 Bit variables created.

Each type of variable may hold a different minimum and maximum value.

• Bit type variables may hold a 0 or a 1. These are created 8 at a time, therefore declaring

a single Bit type variable in a program will not save RAM space, but it will save code space, as Bit type variables produce the most efficient use of code for comparisons etc.

• Byte type variables may hold an unsigned value from 0 to 255, and are the usual work

horses of most programs. Code produced for Byte sized variables is very low compared to signed or unsigned Word, DWord or Float types, and should be chosen if the program requires faster, or more efficient operation.

• Pin type variables are a very special type and unique to the Positron8 compiler. They

are created as an unsigned 8-bit variable, but are used to hold the mask of a Port.Pin when passing or returning from a procedure, or passing the Pin to use to a compiler command.

View original PDF page 21Open page in PDFOriginal PDF page 21

• SByte type variables may hold a 2's complemented signed value from -128 to +127.

Code produced for SByte sized variables is very low compared to SWord, Float, or SDword types, and should be chosen if the program requires faster, or more efficient operation. However, code produced is usually larger for signed variables than unsigned types.

• Word type variables may hold an unsigned value from 0 to 65535, which is usually large

enough for most applications. It still uses more memory than an 8-bit Byte variable, but not nearly as much as a Dword or SDword type.

• SWord type variables may hold a 2's complemented signed value from -32768 to

+32767, which is usually large enough for most applications. SWord type variables will use more code space for expressions and comparisons, therefore, only use signed variables when required.

• Long type variables may hold an unsigned value from 0 to 16777215, which is a huge

amount for only 3 bytes of RAM used per variable. It uses more memory than a 16-bit Word variable, but not nearly as much as a Dword or SDword type.

• Dword type variables may hold an unsigned value from 0 to 4294967295 making this

the largest of the variable family types. This comes at a price however, as Dword calculations and comparisons will use more code space within the microcontroller Use this type of variable sparingly, and only when necessary.

• SDword type variables may hold a 2's complemented signed value from -2147483648 to

+2147483647, also making this the largest of the variable family types. This comes at a price however, as SDword expressions and comparisons will use more code space than a regular Dword type. Use this type of variable sparingly, and only when necessary.

• Float type variables may theoretically hold a value from -1e37 to +1e38, making this the most versatile of the variable family types. However, more so than Dword types, this comes at a price as floating point expressions and comparisons will use more code space within the PICmicro™. Use this type of variable sparingly, and only when strictly necessary. Smaller floating point values usually offer more accuracy.

Because of the fragmented, and low amount of, RAM on the older 12-bit core and standard 14bit core devices, and also because they are no longer current devices, the Long variable type is only supported with enhanced 14-bit core devices and 18F devices.

View original PDF page 22Open page in PDFOriginal PDF page 22