1 根据自己指定顺序分别指定变量地址,如下代码所示。意想的地址分配应该是从a开始,h的地址最大。
#pragma DATA_SECTION (a,"ramgs0")
#pragma DATA_SECTION (b,"ramgs0")
#pragma DATA_SECTION (c,"ramgs0")
#pragma DATA_SECTION (d,"ramgs0")
#pragma DATA_SECTION (e,"ramgs0")
#pragma DATA_SECTION (f,"ramgs0")
#pragma DATA_SECTION (g,"ramgs0")
#pragma DATA_SECTION (h,"ramgs0")
float c = 1.0;
float a = 1.0;
float b = 1.0;
float d = 1.0;
float e = 40000.345;
int f = 2;
int g = 1;
char h = 'a';
实际运行结果:
显然上面结果不符合要求,这个问题怎么解决?
Brian Wang0:
把定义的顺序调整一下就可以了。另外定义一般直接写到DATA_SECTION()语句后面。
1 根据自己指定顺序分别指定变量地址,如下代码所示。意想的地址分配应该是从a开始,h的地址最大。
#pragma DATA_SECTION (a,"ramgs0")
#pragma DATA_SECTION (b,"ramgs0")
#pragma DATA_SECTION (c,"ramgs0")
#pragma DATA_SECTION (d,"ramgs0")
#pragma DATA_SECTION (e,"ramgs0")
#pragma DATA_SECTION (f,"ramgs0")
#pragma DATA_SECTION (g,"ramgs0")
#pragma DATA_SECTION (h,"ramgs0")
float c = 1.0;
float a = 1.0;
float b = 1.0;
float d = 1.0;
float e = 40000.345;
int f = 2;
int g = 1;
char h = 'a';
实际运行结果:
显然上面结果不符合要求,这个问题怎么解决?
wenwei zhuo:
回复 Brian Wang0:
试过了,都不行。应该是内存对齐方式决定的。我用struct解决这个问题。
1 根据自己指定顺序分别指定变量地址,如下代码所示。意想的地址分配应该是从a开始,h的地址最大。
#pragma DATA_SECTION (a,"ramgs0")
#pragma DATA_SECTION (b,"ramgs0")
#pragma DATA_SECTION (c,"ramgs0")
#pragma DATA_SECTION (d,"ramgs0")
#pragma DATA_SECTION (e,"ramgs0")
#pragma DATA_SECTION (f,"ramgs0")
#pragma DATA_SECTION (g,"ramgs0")
#pragma DATA_SECTION (h,"ramgs0")
float c = 1.0;
float a = 1.0;
float b = 1.0;
float d = 1.0;
float e = 40000.345;
int f = 2;
int g = 1;
char h = 'a';
实际运行结果:
显然上面结果不符合要求,这个问题怎么解决?
Seven Han:
回复 wenwei zhuo:
关于#pragma用法请参考文档:www.ti.com/lit/spru514