Entry and Exit Code

The entry code of a function consists of a sequence of instructions responsible for handling the actual parameters, saving registers, and allocating stack space for that function. Entry code generation can be disabled if the parameters, the registers and the stack space are handled explicitly from inline-assembly code or if they are not required at all in the function.

The exit code of a function is responsible with restoring registers and deallocating stack space for that function. Exit code generation can be disabled if the registers and the stack space are handled explicitly from inline-assembly code or if they are not required at all in the function.

In order to disable entry/exit code generation, you need to use the NO_ENTRY/ NO_EXIT pragma, however not by itself, but in pair with the NO_EXIT/ NO_ENTRY pragma, since the stack frame can get corrupted otherwise.

The following example demonstrates incorrect use of the entry/exit code pragmas.

Listing: Example - Incorrect use of Entry/Exit Code Pragmas
long func(char p1, int p2)
{

int a;

long b, c;

a = p1;

b = p2;

c = a + b;

return c; 

}

Without #pragma NO_ENTRY and #pragma NO_EXIT, the compiler generates this code:

Listing: Compiler Output without #pragma NO_ENTRY and #pragma NO_EXIT
42: long func(char p1, int p2)
LEA       S,(#-13,S)  ; entry code : allocates stack space (sets the 
stack pointer)

ST        D0,(0,S)    ; entry code : stores the first argument ('p1'), 
which was passed in D0

ST        D2,(1,S)    ; entry code : stores the second argument ('p2'), 
which was passed in D2

46: a = p1;

LD        D0,(0,S)

TFR       D0,D2

ST        D2,(11,S)

47: b = p2;

LD        D2,(1,S)

SEX       D2,D6

ST        D6,(7,S)

48: c = a + b;

LD        D2,(11,S)

SEX       D2,D6

ADD       D6,(7,S)

ST        D6,(3,S)

   49: return c;

LD        D6,(3,S)   ; exit code: returns the result value in D6 
(according to the calling convention)

   50: }

LEA       S,(13,S)   ; exit code: deallocates stack space (restores the 
stack pointer)

RTS

With #pragma NO_ENTRY and #pragma NO_EXIT, the compiler generates this code:

Listing: Compiler Output with #pragma NO_ENTRY and #pragma NO_EXIT
42: long func(char p1, int p2)
TFR       D0,D3

ST        D3,(8,S)

47: b = p2;

SEX       D2,D6

ST        D6,(4,S)

48: c = a + b;

LD        D2,(8,S)

SEX       D2,D6

ADD       D6,(4,S)

ST        D6,(0,S)

49: return c;

LD        D6,(0,S)

   50: }

RTS       

which will not work, because it does not set the stack pointer as it should.