
- •Chapter 1. Introduction
- •Books About the C Language
- •Chapter 2. Compiling with C51
- •Environment Settings
- •Running C51
- •DOS ERRORLEVEL
- •C51 Output Files
- •Control Directives
- •Directive Categories
- •Reference
- •Chapter 3. Language Extensions
- •Keywords
- •8051 Memory Areas
- •Program Memory
- •Internal Data Memory
- •External Data 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
- •Dallas 80C320, 80C520, and 80C530
- •Siemens 80C517 and 80C537
- •Data Pointers
- •Library Routines
- •Philips/Signetics 8xC750, 8xC751, and 8xC752
- •Customization Files
- •STARTUP.A51
- •START751.A51
- •INIT.A51
- •INIT751.A51
- •PUTCHAR.C
- •GETKEY.C
- •CALLOC.C
- •FREE.C
- •INIT_MEM.C
- •MALLOC.C
- •REALLOC.C
- •Optimizer
- •General Optimizations
- •8051 Specific 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 Pointers
- •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
- •PBYTE
- •PWORD
- •XBYTE
- •XWORD
- •Routines by Category
- •Buffer Manipulation
- •Character Conversion and Classification
- •Data Conversion
- •Math
- •Memory Allocation
- •Stream Input and Output
- •String Manipulation
- •Miscellaneous
- •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
- •Appendix A. Differences from ANSI C
- •Compiler-related Differences
- •Library-related Differences
- •Appendix B. Version 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
- •Trouble with the bdata Memory Type
- •Using Monitor-51
- •Function Pointers
- •Glossary
- •Index

Keil Software — C51 Compiler User’s Guide |
125 |
|
|
Optimizer
The C51 compiler is an optimizing compiler. This means that the compiler takes certain steps to ensure that the code that is generated and output to the object file is the most efficient (smaller and/or faster) code possible. The compiler analyzes the generated code to produce more efficient instruction sequences. This ensures that your C51 program runs as quickly as possible.
The C51 compiler provides six different levels of optimizing. Each increasing level includes the optimizations of the levels below it.
Level Description
0Constant Folding: The compiler performs calculations that reduce expressions to numeric constants, where possible. This includes calculations of run-time addresses.
Simple Access Optimizing: The compiler optimizes access of internal data and bit addresses in the 8051 system.
Jump Optimizing: The compiler always extends jumps to the final target. Jumps to jumps are deleted.
1Dead Code Elimination: Unused code fragments and artifacts are eliminated.
Jump Negation: Conditional jumps are closely examined to see if they can be streamlined or eliminated by the inversion of the test logic.
2Data Overlaying: Data and bit segments suitable for static overlay are identified and internally marked. The BL51 Linker/Locator has the capability, through global data flow analysis, of selecting segments which can then be overlaid.
3Peephole Optimizing: Redundant MOV instructions are removed. This includes
|
unnecessary loading of objects from the memory as well as load operations with |
|
|
|
|
|
constants. Complex operations are replaced by simple operations when memory |
6 |
|
space or execution time can be saved. |
|
4 |
Register Variables: Automatic variables and function arguments are located in |
|
|
registers when possible. Reservation of data memory for these variables is omitted. |
|
|
Extended Access Optimizing: Variables from the IDATA, XDATA, PDATA and |
|
|
|
|
|
CODE areas are directly included in operations. The use of intermediate registers is |
|
|
not necessary most of the time. |
|
|
Local Common Subexpression Elimination: If the same calculations are performed |
|
|
repetitively in an expression, the result of the first calculation is saved and used further |
|
|
whenever possible. Superfluous calculations are eliminated from the code. |
|
|
Case/Switch Optimizing: Code involving switch and case statements is optimized as |
|
|
jump tables or jump strings. |
|
5 |
Global Common Subexpression Elimination: Identical sub expressions within a |
|
|
function are calculated only once when possible. The intermediate result is stored in a |
|
|
register and used instead of a new calculation. |
|
|
Simple Loop Optimizing: Program loops that fill a memory range with a constant are |
|
|
converted and optimized. |
|

126 |
Chapter 6. Advanced Programming Techniques |
|
|
Level Description
6Loop Rotation: Program loops are rotated if the resulting program code is faster and more efficient.
General Optimizations
Optimization |
Description |
|
|
Constant Folding |
Several constant values occurring in an expression or |
|
address calculation are combined as a constant. |
Jump Optimizing |
Jumps are inverted or extended to the final target address |
|
when the program efficiency is thereby increased. |
Dead Code Elimination |
Code which cannot be reached (dead code) is removed from |
|
the program. |
Register Variables |
Automatic variables and function arguments are located in |
|
registers when possible. Reservation of data memory for |
|
these variables is omitted. |
Parameter Passing Via Registers |
A maximum of three function arguments can be passed in |
|
registers. |
Global Common Subexpression |
Identical subexpressions or address calculations that occur |
Elimination |
multiple times in a function are recognized and calculated |
|
only once when possible. |
|
|
8051-Specific Optimizations
|
|
Optimization |
|
Description |
|
|
|
|
|
6 |
|
Peephole Optimization |
|
Complex operations are replaced by simplified operations when |
|
|
|
memory space or execution time can be saved as a result. |
|
|
|
|
|
|
|
|
Extended Access Optimizing |
Constants and variables are included directly in operations. |
|
|
|
Data Overlaying |
|
Data and bit segments of functions are identified as |
|
|
|
|
OVERLAYABLE and are overlaid with other data and bit |
|
|
|
||
|
|
|
|
segments by the BL51 Linker/Locator. |
|
|
Case/Switch Optimizing |
|
Any switch and case statements are optimized by using a jump |
|
|
|
|
table or string of jumps. |
|
|
Options for Code Generation |
||
|
|
|
|
|
|
|
Optimization |
Description |
|
|
|
|
|
|
|
|
OPTIMIZE(SIZE) |
Common C operations are replaced by subprograms. Program code |
|
|
|
|
is thereby reduced. |
|
|
|
NOAREGS |
C51 no longer uses absolute register access. Program code is |
|
|
|
|
independent of the register bank. |
|
|
|
|
|
|

Keil Software — C51 Compiler User’s Guide |
127 |
||
|
|
|
|
|
|
|
|
|
Optimization |
Description |
|
|
|
|
|
|
NOREGPARMS |
Parameter passing is always performed in local data segments. The |
|
|
|
program code is compatible to earlier versions of C51. |
|
|
|
|
|
6