The CODE_SECTION pragma allocates space for the func in a section named section name. The CODE_SECTION pragma is useful if you have code objects that you want to link into an area separate from the .text section. The syntax of the pragma in C is:
#pragma CODE_SECTION (func, "section name")
The syntax of the pragma in C++ is:
#pragma CODE_SECTION ("section name")
The following example demonstrates the use of the CODE_SECTION pragma.
Using the CODE_SECTION Pragma
a) C source file char bufferA[80]; char bufferB[80];
#pragma CODE_SECTION(funcA, "codeA")
char funcA(int i); char funcB(int i);
void main() { char c; c = funcA(1); c = funcB(2); }
char funcA (int i) { return bufferA; }
char funcB (int j) { return bufferB[j]; } b) Assembly source file
.sect ".text" .global _main
;*************************************************************** ;* FNAME: _main FR SIZE: 2 * ;* * ;* FUNCTION ENVIRONMENT * ;* * ;* FUNCTION PROPERTIES * ;* 0 Parameter, 1 Auto, 0 SOE * ;***************************************************************
_main:
ADDB SP,#2 MOVB AL,#1 ; |12| LCR #_funcA ; |12| ; call occurs [#_funcA] ; |12| MOV *-SP[1],AL ; |12| MOVB AL,#1 ; |13| LCR #_funcB ; |13| ; call occurs [#_funcB] ; |13| MOV *-SP[1],AL ; |13| SUBB SP,#2 LRETR ; return occurs
.sect "codeA" .global _funcA ;*************************************************************** ;* FNAME: _funcA FR SIZE: 1 * ;* * ;* FUNCTION ENVIRONMENT * ;* * ;* FUNCTION PROPERTIES * ;* 0 Parameter, 1 Auto, 0 SOE * ;***************************************************************
_funcA: ADDB SP,#1 MOV *-SP[1],AL ; |17| MOVZ AR6,*-SP[1] ; |18| ADD AR6,#_bufferA ; |18| SUBB SP,#1 ; |18| MOV AL,*+XAR6[0] ; |18| LRETR ;return occurs
.sect ".text" .global _funcB
;*************************************************************** ;* FNAME: _funcB FR SIZE: 1 * ;* * ;* FUNCTION ENVIRONMENT * ;* * ;* FUNCTION PROPERTIES * ;* 0 Parameter, 1 Auto, 0 SOE * ;***************************************************************
_funcB: ADDB SP,#1 MOV *-SP[1],AL ; |22| MOVZ AR6,*-SP[1] ; |23| ADD AR6,#_bufferB ; |23| SUBB SP,#1 ; |23| MOV AL,*+XAR6[0] ; |23| LRETR ;return occurs
|