User manual

Table Of Contents
mikroC PRO for PIC32
MikroElektronika
145
Linker Directives
The mikroC PRO for PIC32 uses an internal algorithm to distribute objects within memory. If you need to have a variable
or routine at specic predened address, use the linker directives absolute and org.
When using these directives, be sure to use them in proper memory segments, i.e. for functions it is the KSEG0 and
for variables it is the KSEG1. Linker directives are used with the virtual addresses.
Directive absolute
Directive absolute species the starting address in RAM for a variable or a starting address in ROM for a constant.
If the variable or constant is multi-byte, higher bytes will be stored at the consecutive locations.
Directive absolute is appended to declaration of a variable or constant:
// Variable x will occupy 1 byte at address 0xA0000000:
short x absolute 0xA0000000;
// Variable y will occupy 2 bytes at addresses 0xA0000000 and 0xA0000001:
int y absolute 0xA0000000;
// Const array elements will be placed on the consecutive locations starting from
0xBD000000:
const short ConstantArray[] = {1,2,3} absolute 0xBD000000;
Note:
If you want to place simple type constant into Flash memory, instead of following declaration:
const short SimpeConstant = 0xAA absolute 0xBD000000;
use an array consisting of single element:
const short SimpleConstant[] = {0xAA} absolute 0xBD000000;
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 specied.
Be careful when using the absolute directive, as you may overlap two variables by accident. For example:
// Variable i will occupy 1 byte at address 0xA0000003
char i absolute 0xA0000003;
// Variable will occupy 4 bytes at 0xA0000000, 0xA0000001, 0xA0000002, 0xA0000003;
thus,
// changing i changes jjjj highest byte at the same time, and vice versa
long jjjj absolute 0xA0000000;