3.8 Overlaying

Next: 3.9 Interrupt Service Routines Up: 3. Using SDCC Previous: 3.7 Parameters & Local Contents Index

#
3.8 Overlaying

For non-reentrant functions SDCC will try to reduce internal ram space usage by overlaying parameters and local variables of a function (if possible). Parameters and local variables of a function will be allocated to an overlayable segment if the function has no other function calls and the function is non-reentrant and the memory model is small. If an explicit storage class is specified for a local variable, it will NOT be overlaid.

Note that the compiler (not the linkage editor) makes the decision for overlaying the data items. Functions that are called from an interrupt service routine should be preceded by a #pragma nooverlay if they are not reentrant.

Also note that the compiler does not do any processing of inline assembler code, so the compiler might incorrectly assign local variables and parameters of a function into the overlay segment if the inline assembler code calls other c-functions that might use the overlay. In that case the #pragma nooverlay should be used.

Parameters and local variables of functions that contain 16 or 32 bit multiplication or division will NOT be overlaid since these are implemented using external functions, e.g.:

> `#pragma save`
> `#pragma nooverlay`
> `void set_error(unsigned char errcd)`
> `{`
> `P3 = errcd;`
> `}`
> `#pragma restore`
> `void some_isr () __interrupt (2)`
> `{`
> `...`
> `set_error(10);`
> `...`
> `}`

In the above example the parameter errcd for the function set_error would be assigned to the overlayable segment if the #pragma nooverlay was not present, this could cause unpredictable runtime behavior when called from an interrupt service routine. The #pragma nooverlay ensures that the parameters and local variables for the function are NOT overlaid.

Next: 3.9 Interrupt Service Routines Up: 3. Using SDCC Previous: 3.7 Parameters & Local Contents Index