Instead of using memory on the stack, some targets may direct compilers to place parameters and local variables into a global memory area called OVERLAP. For targets without stack access, there is no other way to handle parameters and local variables.
The example below demonstrates the use of pragma NO_OVERLAP and NO_ENTRY to protect the Tim_PresetTimer() function. Various code sequences, particularly interrupt service routines (ISRs), call Tim_PresetTimer(). The parameters passed to Tim_PresetTimer() are placed in the overlap area. The following example protects these parameters from overwriting.
#include <hidef.h>
extern char timer[];
#pragma NO_OVERLAP
#pragma NO_ENTRY
void Tim_PresetTimer(unsigned char tIndex, unsigned char PresetValue)
{
DisableInterrupts;
asm {
STX tIndex
STA PresetValue
}
timer[tIndex] = PresetValue;
EnableInterrupts;
}
As an example the following code is given, but it looks similar for other targets:
1: #include <hidef.h>
2:
3: extern char timer[];
4:
5: #pragma NO_OVERLAP
6: #pragma NO_ENTRY
7: void Tim_PresetTimer(unsigned char tIndex, unsigned
char
PresetValue)
8: {
9: DisableInterrupts;
Function: Tim_PresetTimer
Options : -Ix:\chc05\lib\hc05c\include -Lasm=%n.lst
0000 9b SEI
10: asm {
11: STX tIndex
0001 cf0000 STX _Tim_PresetTimerp1
12: STA PresetValue
0004 c70000 STA _Tim_PresetTimerp0
13: }
14: timer[tIndex] = PresetValue;
0007 ce0000 LDX _Tim_PresetTimerp1
000a c60000 LDA _Tim_PresetTimerp0
000d d70000 STA timer,X
15: EnableInterrupts;
0010 9a CLI
16:
17: }
0011 81 RTS