- •Chapter 1. Introduction
- •Support for all 8051 Variants
- •Books About the C Language
- •Chapter 2. Compiling with the Cx51 Compiler
- •Environment Variables
- •Running Cx51 from the Command Prompt
- •ERRORLEVEL
- •Cx51 Output Files
- •Control Directives
- •Directive Categories
- •Reference
- •Chapter 3. Language Extensions
- •Keywords
- •Memory Areas
- •Program Memory
- •Internal Data Memory
- •External Data Memory
- •Far Memory
- •Special Function Register Memory
- •Memory Models
- •Small Model
- •Compact Model
- •Large Model
- •Memory Types
- •Explicitly Declared Memory Types
- •Implicit Memory Types
- •Data Types
- •Bit Types
- •Special Function Registers
- •sbit
- •Absolute Variable Location
- •Pointers
- •Generic Pointers
- •Pointer Conversions
- •Abstract Pointers
- •Function Declarations
- •Function Parameters and the Stack
- •Passing Parameters in Registers
- •Function Return Values
- •Specifying the Memory Model for a Function
- •Specifying the Register Bank for a Function
- •Register Bank Access
- •Interrupt Functions
- •Reentrant Functions
- •Chapter 4. Preprocessor
- •Directives
- •Stringize Operator
- •Predefined Macro Constants
- •Chapter 5. 8051 Derivatives
- •Analog Devices MicroConverter B2 Series
- •Atmel 89x8252 and Variants
- •Dallas 80C320, 420, 520, and 530
- •Arithmetic Accelerator
- •Data Pointers
- •Library Routines
- •Philips 8xC750, 8xC751, and 8xC752
- •Philips 80C51MX Architecture
- •Philips and Atmel WM Dual DPTR
- •Customization Files
- •STARTUP.A51
- •INIT.A51
- •XBANKING.A51
- •Basic I/O Functions
- •Memory Allocation Functions
- •Optimizer
- •General Optimizations
- •Options for Code Generation
- •Segment Naming Conventions
- •Data Objects
- •Program Objects
- •Interfacing C Programs to Assembler
- •Function Parameters
- •Parameter Passing in Registers
- •Parameter Passing in Fixed Memory Locations
- •Function Return Values
- •Using the SRC Directive
- •Register Usage
- •Overlaying Segments
- •Example Routines
- •Small Model Example
- •Compact Model Example
- •Large Model Example
- •Data Storage Formats
- •Bit Variables
- •Signed and Unsigned Long Integers
- •Generic and Far Pointers
- •Floating-point Numbers
- •Accessing Absolute Memory Locations
- •Absolute Memory Access Macros
- •Linker Location Controls
- •The _at_ Keyword
- •Debugging
- •Chapter 7. Error Messages
- •Fatal Errors
- •Actions
- •Errors
- •Syntax and Semantic Errors
- •Warnings
- •Chapter 8. Library Reference
- •Intrinsic Routines
- •Library Files
- •Standard Types
- •va_list
- •Absolute Memory Access Macros
- •CBYTE
- •CWORD
- •DBYTE
- •DWORD
- •FARRAY, FCARRAY
- •FVAR, FCVAR,
- •PBYTE
- •PWORD
- •XBYTE
- •XWORD
- •Routines by Category
- •Buffer Manipulation
- •Character Conversion and Classification
- •Data Conversion
- •Math Routines
- •Memory Allocation Routines
- •Stream Input and Output Routines
- •String Manipulation Routines
- •Miscellaneous Routines
- •Include Files
- •8051 Special Function Register Include Files
- •ABSACC.H
- •ASSERT.H
- •CTYPE.H
- •INTRINS.H
- •MATH.H
- •SETJMP.H
- •STDARG.H
- •STDDEF.H
- •STDIO.H
- •STDLIB.H
- •STRING.H
- •Reference
- •Compiler-related Differences
- •Library-related Differences
- •Appendix B. Version Differences
- •Version 6.0 Differences
- •Version 5 Differences
- •Version 4 Differences
- •Version 3.4 Differences
- •Version 3.2 Differences
- •Version 3.0 Differences
- •Version 2 Differences
- •Appendix C. Writing Optimum Code
- •Memory Model
- •Variable Location
- •Variable Size
- •Unsigned Types
- •Local Variables
- •Other Sources
- •Appendix D. Compiler Limits
- •Appendix E. Byte Ordering
- •Recursive Code Reference Error
- •Problems Using the printf Routines
- •Uncalled Functions
- •Using Monitor-51
- •Trouble with the bdata Memory Type
- •Function Pointers
- •Glossary
- •Index
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.
