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

被折叠的 条评论
为什么被折叠?



