Chinaunix首页 | 论坛 | 博客
  • 博客访问: 643606
  • 博文数量: 175
  • 博客积分: 2457
  • 博客等级: 大尉
  • 技术积分: 1488
  • 用 户 组: 普通用户
  • 注册时间: 2011-07-13 20:31
文章分类

全部博文(175)

文章存档

2012年(22)

2011年(153)

分类: 嵌入式

2011-07-30 10:24:29

The DATA_SECTION pragma allocates space for the symbol in a section called section name. 
The syntax for the pragma in C is:
#pragma DATA_SECTION (symbol, "section name");
The syntax for the pragma in C++ is:
#pragma DATA_SECTION ( "section name");
The DATA_SECTION pragma is useful if you have data objects that you want to link into an area separate from the .bss section.
This directive is illustrated in the following example.
Using the DATA_SECTION Pragma
a)    C source file
#pragma DATA_SECTION(bufferB, "my_sect")
char bufferA[512];
char bufferB[512]:
// 执行完此三条语句之后,数组bufferB被分配到段名为 "my_sect"的自定义段中

b)    C++ source file
char bufferA[512];
#pragma DATA_SECTION("my_sect")
char bufferB[512];

c)    Assembly source file

           .global _bufferA
           .bss     _bufferA,512,4
           .global _bufferB
_bufferB: .usect   "my_sect",512,4

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

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

// 从红色标记可以看出,在加入#pragma CODE_SECTION(funcA, codeA)语句之后,main()函数和_funcB函数被

// 分配到 ".text" 段中,而_funcA函数被分配到 "codeA" 段中。

阅读(7861) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~