Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
59
Добавлен:
14.04.2015
Размер:
1.37 Mб
Скачать

Keil Software — Cx51 Compiler User’s Guide

95

 

 

Compact Model

Using the compact model, all variables, by default, reside in one page of external data memory. (This is as if they were explicitly declared using the pdata memory type specifier.) This memory model can accommodate a maximum of 256 bytes of variables. The limitation is due to the addressing scheme used, which is indirect through registers R0 and R1 (@R0, @R1). This memory model is not as efficient as the small model, therefore, variable access is not as fast. However, the compact model is faster than the large model.

When using the compact model, the Cx51 compiler accesses external memory with instructions that utilize the @R0 and @R1 operands. R0 and R1 are byte

registers and provide only the low-order byte of the address. If the compact 3 model is used with more than 256 bytes of external memory, the high-order

address byte (or page) is provided by Port 2 on the 8051. In this case, you must initialize Port 2 with the proper external memory page to use. This can be done in the startup code. You must also specify the starting address for PDATA to the linker.

Refer to “STARTUP.A51” on page 151 for more information on configuring P2 for the compact model.

Large Model

In the large model, all variables, by default, reside in external data memory (up to 64 KBytes). (This is the same as if they were explicitly declared using the xdata memory type specifier.) The data pointer (DPTR) is used for addressing. Memory access through this data pointer is inefficient, especially on variables with a length of two or more bytes. This type of data access mechanism generates more code than the small or compact models.

Memory Types

The Cx51 compiler explicitly supports the architecture of the 8051 and its derivatives and provides access to all memory areas of the 8051. Each variable may be explicitly assigned to a specific memory space.

Accessing the internal data memory is considerably faster than accessing the external data memory. For this reason, place frequently used variables in

96

Chapter 3. Language Extensions

 

 

internal data memory. Place larger, less frequently used variables in external data memory.

Explicitly Declared Memory Types

You may specify where variables are stored by including a memory type specifier in the variable declaration.

The following table summarizes the available memory type specifiers.

3

 

Memory Type

Description

 

code

Program memory (64 KBytes); accessed by opcode MOVC @A+DPTR.

 

data

Directly addressable internal data memory; fastest access to variables

 

 

 

(128 bytes).

 

 

idata

Indirectly addressable internal data memory; accessed across the full internal

 

 

 

address space (256 bytes).

 

 

bdata

Bit-addressable internal data memory; supports mixed bit and byte access

 

 

 

(16 bytes).

 

 

xdata

External data memory (64 KBytes); accessed by opcode MOVX @DPTR.

 

 

far

Extended RAM and ROM memory spaces (up to 16MB); accessed by user

 

 

 

defined routines or specific chip extensions (Philips 80C51MX, Dallas 390).

 

 

pdata

Paged (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.

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 declaration

data char x; is equivalent to char data x;

Nonetheless, this feature should not be used in new programs because it may not be supported in future versions of the Cx51 compiler.

Соседние файлы в папке HLP