next up previous contents index
Next: 3.7 Interrupt Service Routines Up: 3. Using SDCC Previous: 3.5 Parameters & Local   Contents   Index

3.6 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 overlayed.

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 overlayed 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 using 1  
{ 
    ... 
    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 ISR. The #pragma NOOVERLAY ensures that the parameters and local variables for the function are NOT overlayed.


next up previous contents index
Next: 3.7 Interrupt Service Routines Up: 3. Using SDCC Previous: 3.5 Parameters & Local   Contents   Index
Johan Knol
2001-07-13