C51 pointers

本文介绍了C51编译器支持的变量指针声明及其使用方法,对比了内存特定指针与通用指针的不同之处,并通过示例程序展示了不同类型的指针在8051程序中的代码大小、数据大小及执行时间上的差异。

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

Pointers


The Cx51 Compiler supports the declaration of variable pointers using the * character. The Cx51 Compiler pointers may be used to perform all operations available in standard C. However, because of the unique architecture of the 8051 and its derivatives, the Cx51 Compiler provides two different types of pointers:


generic pointers
memory-specific pointers
Comparison: Memory Specific & Generic Pointers


You can significantly accelerate an 8051 C program by using memory specific pointers. The following sample program shows the differences in code & data size and execution time for various pointer declarations.


Description idata Pointer xdata Pointer Generic Pointer
Sample Program char idata *ip;
char val;
val = *ip; char xdata *xp;
char val;
val = *xp; char *p;
char val;
val = *p;
8051 Program Code
Generated MOV R0,ip
MOV val,@R0 MOV DPL,xp +1
MOV DPH,xp
MOV A,@DPTR
MOV val,A MOV R1,p + 2
MOV R2,p + 1
MOV R3,p
CALL CLDPTR
Pointer Size
Code Size
Execution Time 1 byte
4 bytes
4 cycles 2 bytes
9 bytes
7 cycles 3 bytes
11 bytes + library call
13 cycles
C51的指针,用不好,就是祸害。


 Posted by ian at 07:53  Tagged with: pointer
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值