Keil C51之Strings的使用

本文探讨了在Keil C51开发环境中,字符串的默认存储位置及其如何被程序调用。同时介绍了使用STRING编译指示符来改变字符串的存储区域,并讨论了这种做法的利弊。

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

虽然一直在程序中使用strings(字符串),但并未弄清strings到底是存储在什么位置,是如何被程序调用的,此番好好查查资料,理清一下该部分知识.

通过查询Keil C51 Help->uVision Help手册,搜寻string相关主题,在名为“”STRING Compiler Directive“”的文章里,找到了相关内容:
一、首先说明下什么是string:在程序中,以成对的单引号或双引号包含的数据内容,如"Hello World",'A'这些都是字符数据。

二、在Keil中,strings默认被安排存储在代码区(By default, implicit strings are located in code memory.)

Eg:

void main (void) {
  printf ("hello world\n");
}
在这里,"hello world"就被安排到code memory(代码区)。

三、Keil提供一个编译指示符STRING用于指定strings的存放位置,其使用如下:

STRING(x),{x = CODE,XDATA,FAR},使用位置:Options - C51 - Misc controls。

Option Description 
CODE - Implicit strings are located in code space. This is the default setting of the Cx51 Compiler. (code,默认位置)
XDATA - Implicit strings are located in const xdata space. (const xdata)
FAR - Implicit strings are located in const far space. (const far)

The STRING directive changes the default location for implicitly located strings.This directive must be used carefully, since existing programs might use memory typed pointers to access strings.(STRING可以修改strings在代码中的位置,但一定要谨慎使用)

One good reason to consider changing the default location of implicit strings (to the xdata or far memory areas)to avoid using code banking. This directive is useful especially forextended 8051 devices like the NXP 80C51MX.(为了避免使用code Banking而修改strings的存放位置,是值得的)

通过对上述文字的理解和所做的相关试验,最后归纳总结如下:

1、Strings在Keil C51开发环境中,编译完成后会默认被安排在代码区(code memory);

2、使用STRING编译指示符,可以修改strings在代码中的存放位置,但一定要谨慎使用,因为这很容易导致问题;

3、修改strings存放位置到xdata或 far memory,有一个好处是可以不必使用code banking.


参考资料:http://www.keil.com/support/man/docs/c51/c51_string.htm

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值