- •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 |
159 |
|
|
Segment Naming Conventions
Objects generated by the Cx51 compiler (program code, program data, and constant data) are stored in segments which are units of code or data memory. A segment may be relocatable or may be absolute. Each relocatable segment has a type and a name. This section describes the conventions used by the Cx51 comiler for naming these segments.
Segment names include a module_name which is the name of the source file in which the object is declared. In order to accommodate a wide variety of existing software and hardware tools, all segment names are converted and stored in uppercase.
Each segment name has a prefix that corresponds to the memory type used for the segment. The prefix is enclosed in question marks (?). The following is a list of the standard segment name prefixes:
|
Segment Prefix |
Memory Type |
Description |
|
|
|
?PR? |
program |
Executable program code |
|
|
|
?CO? |
code |
Constant data in program memory |
|
|
|
?BI? |
bit |
Bit data in internal data memory |
|
|
|
?BA? |
bdata |
Bit-addressable data in internal data memory |
|
|
|
?DT? |
data |
Internal data memory |
|
|
|
?FD? |
far |
Far memory (RAM space) |
|
|
|
?FC? |
const far |
Far memory (constant ROM space) |
|
|
|
6 |
||||
|
?ID? |
idata |
Indirectly-addressable internal data memory |
|
|
|
?PD? |
pdata |
Paged data in external data memory |
|
|
|
?XD? |
xdata |
Xdata memory (RAM space) |
|
|
|
?XC? |
const xdata |
Xdata memory (constant ROM space) |
|
|
|
|
160 |
Chapter 6. Advanced Programming Techniques |
|
|
Data Objects
Data objects are the variables and constants you declare in your C programs. The Cx51 compiler generates a separate segment for each memory type for which a variable is declared. The following table lists the segment names generated for different variable data objects.
Segment Name |
Description |
?BA?module_name |
Bit-addressable data objects |
?BI?module_name |
Bit objects |
?CO?module_name |
Constants (strings and initialized variables) |
?DT?module_name |
Objects declared in data |
?FC?module_name |
Objects declared in const far (requires OMF2 directive) |
?FD?module_name |
Objects declared in far (requires OMF2 directive) |
?ID?module_name |
Objects declared in idata |
?PD?module_name |
Objects declared in pdata |
?XC?module_name |
Objects declared in const xdata (requires OMF2 directive) |
?XD?module_name |
Objects declared in xdata |
6
Keil Software — Cx51 Compiler User’s Guide |
161 |
|
|
Program Objects
Program objects include the code generated for C program functions by the Cx51 compiler. Each function in a source module is assigned a separate code segment using the ?PR?function_name?module_name naming convention. For example, the function error_check in the file SAMPLE.C would result in a segment name of ?PR?ERROR_CHECK?SAMPLE.
Segments are also created for local variables that are declared within the body of a function. These segment names follow the above conventions and have a different prefix depending upon the memory area in which the local variables are stored.
Function arguments were historically passed using fixed memory locations. This is still true for routines written in PL/M-51. However, Cx51 can pass up to 3 function arguments in registers. Other arguments are passed using the traditional fixed memory areas. Memory space is reserved for all function arguments regardless of whether or not some of these arguments may be passed in registers. The parameter areas must be publicly known to any calling module. So, they are publicly defined using the following segment names:
?function_name?BYTE ?function_name?BIT
For example, if func1 is a function that accepts both bit arguments as well as arguments of other data types, the bit arguments are passed starting at ?FUNC1?BIT, and all other parameters are passed starting at ?FUNC1?BYTE.
Refer to “Interfacing C Programs to Assembler” on page 163 for examples of the 6 function argument segments.
Functions that have parameters, local variables, or bit variables contain all additional segments for these variables. These segments can be overlaid by the BL51 Linker/Locator.
162 |
Chapter 6. Advanced Programming Techniques |
|
|
They are created as follows based on the memory model used.
Small model segment naming conventions
|
Information |
Segment Type |
Segment Name |
|
|
Program code |
code |
?PR?function_name?module_name |
|
|
Local variables |
data |
?DT?function_name?module_name |
|
|
Local bit variables |
bit |
?BI?function_name?module_name |
|
|
|
|
||
|
Compact model segment naming conventions |
|
||
|
Information |
Segment Type |
Segment Name |
|
|
Program code |
code |
?PR?function_name?module_name |
|
|
Local variables |
pdata |
?PD?function_name?module_name |
|
|
Local bit variables |
bit |
?BI?function_name?module_name |
|
|
|
|
||
|
Large model segment naming conventions |
|
||
|
Information |
Segment Type |
Segment Name |
|
|
Program code |
code |
?PR?function_name?module_name |
|
|
Local variables |
xdata |
?XD?function_name?module_name |
|
|
Local bit variables |
bit |
?BI?function_name?module_name |
|
The names for functions with register parameters and reentrant attributes are 6 modified slightly to avoid run-time errors. The following table lists deviations
from the standard segment names.
Declaration |
Symbol |
Description |
void func (void) … |
FUNC |
Names of functions that have no arguments or |
|
|
whose arguments are not passed in registers are |
|
|
transferred to the object file without any changes. |
|
|
The function name is converted to uppercase. |
void func1 (char) … |
_FUNC1 |
For functions with arguments passed in registers, |
|
|
the underscore character (‘_’) is prefixed to the |
|
|
function name. This identifies those functions that |
|
|
transfer arguments in CPU registers. |
void func2 (void) reentrant |
_?FUNC2 |
For functions that are reentrant, the string “_?” is |
… |
|
prefixed to the function name. This is used to |
|
|
identify reentrant functions. |
|
|
|