嵌入式中的存贮位置关键字

 Memory Types

The Cx51 Compiler provides access to all 8051 memory areas. Variables may be explicitly assigned to a specific memory space (by including a memory type specifier in the declaration) or implicitly assigned (based on the memory model).

The following table summarizes the memory type specifiers you may use.

Memory TypeDescription
codeProgram memory (64 KBytes); accessed by opcode MOVC @A+DPTR.
dataDirectly addressable internal data memory; fastest access to variables (128 bytes).
idataIndirectly addressable internal data memory; accessed across the full internal address space (256 bytes).
bdataBit-addressable internal data memory; supports mixed bit and byte access (16 bytes).
xdataExternal data memory (64 KBytes); accessed by opcode MOVX @DPTR.
farExtended RAM and ROM memory spaces (up to 16MB); accessed by user defined routines or specific chip extensions (Philips 80C51MX, Dallas 390).
pdataPaged (256 bytes) external data memory; accessed by opcode MOVX @Rn.

As with the signed and unsigned attributes, you may include memory type specifiers in the variable declaration. For example:

char data var1;
char code text[] = "ENTER PARAMETER:";
unsigned long xdata array[100];
float idata x,y,z;
unsigned int pdata dimension;
unsigned char xdata vector[10][4][4];
char bdata flags;

Note

  • For compatibility with previous versions of the C51 Compiler, you may specify the memory area before the data type. For example, the following two declarations are equivalent:

    data char x;   // Old-Style Memory Type Declaration
    char data x;   // New-Style Memory Type Declaration
    

    Nonetheless, this feature should not be used in new programs because it may not be supported in future versions of the Cx51 Compiler. Be careful when using the old C51 syntax with memory-specific pointers. For example, the following two declarations are equivalent:

    data char *x;   // Old-Style Memory Type Declaration
    char *data x;   // New-Style Memory Type Declaration
    
  • Accessing the internal data memory is considerably faster than accessing the external data memory. For this reason, place frequently used variables in internal data memory. Place larger, less frequently used variables in external data memory.

If no memory type is specified for a variable, the compiler implicitly locates the variable in the default memory space determined by the memory model: SMALL, COMPACT, or LARGE. Function arguments and automatic variables that cannot be located in registers are also stored in the default memory area. Refer to Memory Models for more information.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值