Linker Directives

mikroPascal PRO for PIC uses internal algorithm to distribute objects within memory. If you need to have a variable or a routine at the specific predefined address, use the linker directives absolute and org.

Directive absolute

Directive absolute specifies 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:

var x : word; absolute $32;
// Variable x will occupy 1 word (16 bits) at address $32

    y : longint; absolute $34;
// Variable y will occupy 2 words at addresses $34 and $36

Be careful when using absolute directive, as you may overlap two variables by accident. For example:

var  i : word; absolute $42;
// Variable i will occupy 1 word at address $42;

     jj : longint; absolute $40;
// Variable will occupy 2 words at $40 and $42; thus,
// changing i changes jj at the same time and vice versa

Directive org

Directive org specifies the starting address of a routine in ROM. It is appended to the declaration of a routine. For example:

procedure proc(par : byte); org 0x200;
begin
// Procedure will start at address 0x200;
...
end;

org directive can be used with main routine too. For example:

program Led_Blinking; 

begin org 0x800;             // main procedure starts at 0x800
 ...
end.
  Note : For PIC18 family, you must specify an even address when using the org directive.

Directive orgall

Use the orgall directive to specify the address above which all routines, constants will be placed. Example:

begin
  orgall(0x200) // All the routines, constants in main program will be above the address 0x200
  ...
end.
Copyright (c) 2002-2012 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code