External procedures and functions

Language reference ›› Procedures and functions ››
Parent Previous Next

Warning! (V1.6.2): Behaviors and conventions have changed!

Procedures and functions may be declared as external:

PROCEDURE ExternalProc1a(N: BYTE); EXTERNAL 'Externals';
FUNCTION ExternalFunc1b: BYTE; EXTERNAL 'Externals.o';

In this syntax, PMP assumes that the two procedures are implemented externally in a separate file.

If there's no file extension, '.asm' is assumed.

Allowed file extensions are '.asm' or '.o'.

For a '.asm' file extension PMP will generate an automatic check of file ages and generate an assembler call if the object file is not accurate.

Several procedures and function may reside in the same external file.

The external file cannot contain a path; the compiler output path will be used if the file extension is '.asm' and if it is '.o' the assembler output path will be used.

If there's no file name at all, PMP will not know in which file the routine is, so it is up to the programmer to add the correct file in the project's additional files list in the project's options.

External procedures and functions may have parameters; assembler instructions may access these variables and global variables as well (see naming convention in the next chapter).

Naming convention:

Procedures and functions calls, along with arguments are generated with their fully qualified names:


Would generate (PIC16):

       pagesel        Externals.ExternalFunc1b

       call        Externals.ExternalFunc1b

       bcf        STATUS, RP0                ; Select bank

       bcf        STATUS, RP1                ; Select bank

       movwf        Externals.ExternalProc1a.N                ; Store parameter

       pagesel        Externals.ExternalProc1a

       call        Externals.ExternalProc1a

       pagesel        ExternalProc2

       call        ExternalProc2

Parameters passing:

If the called routine has only one parameter by value which has a 8-bit size, it is passed in W (WREG) unless the directive {$OPTIMIZE PARAMS OFF} is used.

Else the parameters are stored into the corresponding RAM locations before the call.

The RAM locations are ALWAYS allocated even if the called routine only uses the single parameter in W (WREG).


Banking scheme is different according to the processor type:

Function result:

A <module-name>.<function-name>.RESULT variable is always generated for any function, it may be used to store temporary data before to exit.

At exit, function results must be stored in the PMP accumulator bytes, which depends on the processor type (PMP code does not use the the called function RESULT variable after function return):