User manual
mikroPascal PRO for dsPIC30/33 and PIC24
MikroElektronika
235
Linker Directives
mikroPascal PRO for dsPIC30/33 and PIC24 uses an internal algorithm to distribute objects within memory. If you need
to have a variable, constant or a routine at the specic predened address, use the linker directives absolute and
org.
Directive absolute
Directive absolute species the starting address in RAM for a variable. If the variable is multi-byte, higher bytes will
be stored at the consecutive locations.
Directive absolute is appended to declaration of a variable:
// Variable x will occupy 1 word (16 bits) at address 0x32
var x : word; absolute 0x32;
// Variable y will occupy 2 words at addresses 0x34 and 0x36
var y : longint; absolute 0x34;
Be careful when using the absolute directive, as you may overlap two variables by accident. For example:
// Variable i will occupy 1 word at address 0x42;
var i : word; absolute 0x42;
// Variable will occupy 2 words at 0x40 and 0x42; thus,
// changing i changes jj at the same time and vice versa
var jj : longint; absolute 0x40;
Directive org
Directive org species the starting address of a constant or a routine in ROM. It is appended to the constant or a
routine declaration.
To place a constant array in Flash memory, write the following:
// Constant array MONTHS will be placed starting from the address 0x800
const MONTHS : array[1..12] of byte = (31,28,31,30,31,30,31,31,30,31,30,31); org 0x800;
If you want to place simple type constant into Flash memory, instead of following declaration:
const SimpleConstant : byte = 0xAA; org 0x2000;
use an array consisting of single element:
const SimpleConstant : array[1] of byte = (0xAA); org 0x800;
In rst case, compiler will recognize your attempt, but in order to save Flash space, and boost performance, it will
automatically replace all instances of this constant in code with it’s literal value.
In the second case your constant will be placed in Flash in the exact location specied.