CCS中DATA_SECTION()用法

本文介绍 TI 编译器提供的 DATA_SECTION 指令,用于将数据对象链接到特定的数据段中。通过 C/C++ 和汇编语言示例展示了如何使用此指令,并解释了如何在 .cmd 文件中定义相应的 section。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ti的帮助文档里是这么讲的:

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]:

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


我理解的意思是:
  定义一个数据段: 
          段名为:    "section name"
          段的内容在:  symbol  里
在CCS编程中,如果我们不指定变量的存放位置,编译器会自动的给变量分配一个位置,但是如果有的时候需要把变量放在一个特定的空间内,我们应该如何操作呢,CCS提供了如下的两个指令
#pragma CODE_SECTION
#pragma DATA_SECTION
其中data_section是针对数据空间的,code_section是针对程序空间的,具体的使用办法是
#pragma DATA_SECTION(bufferB, ”my_sect”)
char bufferB[512];
在.cmd文件中建立对应的section就可以使用了.

MEMORY
{
PAGE 1: spacename : origin = 0x...., length 0x..
}
SECTIONS
{
    .my_sect  : {} >spacename PAGE 1
}

本文来自优快云博客,转载请标明出处:http://blog.youkuaiyun.com/henhen2002/archive/2009/09/30/4619701.aspx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值