JAL manual - language - variables

previous up next


declaration

A variable declaration introduces a name which corresponds to a storage location. Optionally the name can be bound to a specific location, otherwise the compiler allocates a suitable location.

Optionally a value can be assigned to the variable, which has the same effect as an equivalent assignment immediately following the declaration. The initial value does not need to be a constant expression.

As single variable declaration can introduce a number of variables, all of the same type.

examples:

   var byte x, y = 3, z = f( 14 )    -- scratch variables


location

A variable declaration can specify the location of the variable. The location is interpreted as a byte register address and (for bit variables) the bit within the register, 0 being the first bit. Both address expressions must be compile-time constant. A variable name can be used as byte address, which is interpreted as the byte address of that variable.

The addressing of variables ignores the banking used in some target architectures. Each address indicates a different addressable file register. The compiler takes care of the translation to the banked address.

examples:

   var byte volatile port_a at 0x06    -- pic IO port A
   var bit  volatile status_z at 3 : 2 -- pic zero flag


volatile

A variable can be declared volatile, which expresses that the variable does not posess normal variable semantics. For non-volatile variables the compiler assumes that

For a volatile variable:

For non-volatile variables the compiler can optimize to its heart's content as long as observable effects (on volatile variables) remain identical. This can include deleting unnecessary assignments.

examples:

   var volatile byte FSR    at 4     -- indirection address register
   var volatile byte INDF   at 0     -- indirection data register
   var volatile byte count           -- a count which is used across resets         


alias

A variable can be declared to be an alias for another variable. This is used much like a constant declaration to hide the actual identity of an identifier from subsequent code. An alias variable inherits the address of the aliased variable, not the volatility.

examples:

   -- fragment of the i2cp library file,
   -- which defines the pins used by the i2c library
   var byte volatile i2c_clock    is pin_a3
   var byte volatile i2c_data_in  is pin_a4
   var byte volatile i2c_data_out is pin_a4_direction

previous up next