
- •Chapter 1. Introduction
- •How to Develop A Program
- •What is an Assembler?
- •Modular Programming
- •Modular Program Development Process
- •Segments, Modules, and Programs
- •Translate and Link Process
- •Filename Extensions
- •Program Template File
- •Chapter 2. Architecture Overview
- •Memory Classes and Memory Layout
- •Classic 8051
- •Extended 8051 Variants
- •Philips 80C51MX
- •Intel/Atmel WM 251
- •CPU Registers
- •CPU Registers of the 8051 Variants
- •CPU Registers of the Intel/Atmel WM 251
- •Program Status Word (PSW)
- •Instruction Sets
- •Opcode Map
- •8051 Instructions
- •Additional 251 Instructions
- •Additional 80C51MX Instructions via Prefix A5
- •Chapter 3. Writing Assembly Programs
- •Assembly Statements
- •Directives
- •Controls
- •Instructions
- •Comments
- •Symbols
- •Symbol Names
- •Labels
- •Operands
- •Special Assembler Symbols
- •Immediate Data
- •Memory Access
- •Program Addresses
- •Expressions and Operators
- •Numbers
- •Characters
- •Character Strings
- •Location Counter
- •Operators
- •Expressions
- •Chapter 4. Assembler Directives
- •Introduction
- •Segment Directives
- •Location Counter
- •Generic Segments
- •Stack Segment
- •Absolute Segments
- •Default Segment
- •SEGMENT
- •RSEG
- •BSEG, CSEG, DSEG, ISEG, XSEG
- •Symbol Definition
- •CODE, DATA, IDATA, XDATA
- •esfr, sfr, sfr16, sbit
- •LIT (AX51 & A251 only)
- •Memory Initialization
- •DD (AX51 & A251 only)
- •Reserving Memory
- •DBIT
- •DSW (AX51 & A251 only)
- •DSD (AX51 & A251 only)
- •Procedure Declaration (AX51 & A251 only)
- •PROC / ENDP (AX51 & A251 only)
- •LABEL (AX51 and A251 only)
- •Program Linkage
- •PUBLIC
- •EXTRN / EXTERN
- •NAME
- •Address Control
- •EVEN (AX51 and A251 only)
- •USING
- •Other Directives
- •_ _ERROR_ _
- •Chapter 5. Assembler Macros
- •Standard Macro Directives
- •Defining a Macro
- •Parameters
- •Labels
- •Repeating Blocks
- •REPT
- •IRPC
- •Nested Definitions
- •Nested Repeating Blocks
- •Recursive Macros
- •Operators
- •NUL Operator
- •& Operator
- •< and > Operators
- •% Operator
- •;; Operator
- •! Operator
- •Invoking a Macro
- •C Macros
- •C Macro Preprocessor Directives
- •Stringize Operator
- •Predefined C Macro Constants
- •Examples with C Macros
- •C Preprocessor Side Effects
- •Chapter 6. Macro Processing Language
- •Overview
- •Creating and Calling MPL Macros
- •Creating Parameterless Macros
- •MPL Macros with Parameters
- •Local Symbols List
- •Macro Processor Language Functions
- •Comment Function
- •Escape Function
- •Bracket Function
- •METACHAR Function
- •Numbers and Expressions
- •Numbers
- •Character Strings
- •SET Function
- •EVAL Function
- •Logical Expressions and String Comparison
- •Conditional MPL Processing
- •IF Function
- •WHILE Function
- •REPEAT Function
- •EXIT Function
- •String Manipulation Functions
- •LEN Function
- •SUBSTR Function
- •MATCH Function
- •Console I/O Functions
- •Advanced Macro Processing
- •Literal Delimiters
- •Blank Delimiters
- •Identifier Delimiters
- •Literal and Normal Mode
- •MACRO Errors
- •Chapter 7. Invocation and Controls
- •Environment Settings
- •Running Ax51
- •ERRORLEVEL
- •Output Files
- •Assembler Controls
- •Controls for Conditional Assembly
- •Conditional Assembly Controls
- •Chapter 8. Error Messages
- •Fatal Errors
- •Non–Fatal Errors
- •Chapter 9. Linker/Locator
- •Overview
- •Combining Program Modules
- •Segment Naming Conventions
- •Combining Segments
- •Locating Segments
- •Overlaying Data Memory
- •Resolving External References
- •Absolute Address Calculation
- •Generating an Absolute Object File
- •Generating a Listing File
- •Bank Switching
- •Using RTX51, RTX251, and RTX51 Tiny
- •Linking Programs
- •Command Line Examples
- •Control Linker Input with µVision2
- •ERRORLEVEL
- •Output File
- •Linker/Locater Controls
- •Locating Programs to Physical Memory
- •Classic 8051
- •Extended 8051 Variants
- •Philips 80C51MX
- •Intel/Atmel WM 251
- •Data Overlaying
- •Program and Data Segments of Functions
- •Using the Overlay Control
- •Tips and Tricks for Program Locating
- •Locate Segments with Wildcards
- •Special ROM Handling (LX51 & L251 only)
- •Bank Switching
- •Common Code Area
- •Code Bank Areas
- •Bank Switching Configuration
- •Configuration Examples
- •Control Summary
- •Listing File Controls
- •Output File Controls
- •Segment and Memory Location Controls
- •High-Level Language Controls
- •Error Messages
- •Warnings
- •Non-Fatal Errors
- •Fatal Errors
- •Exceptions
- •Chapter 10. Library Manager
- •Using LIBx51
- •Interactive Mode
- •Create Library within µVision2
- •Command Summary
- •Creating a Library
- •Adding or Replacing Object Modules
- •Removing Object Modules
- •Extracting Object Modules
- •Listing Library Contents
- •Error Messages
- •Fatal Errors
- •Errors
- •Chapter 11. Object-Hex Converter
- •Using OHx51
- •OHx51 Command Line Examples
- •Creating HEX Files for Banked Applications
- •OHx51 Error Messages
- •Using OC51
- •OC51 Error Messages
- •Intel HEX File Format
- •Record Format
- •Data Record
- •Extended 8086 Segment Record
- •Extended Linear Address Record
- •Example Intel HEX File
- •Appendix A. Application Examples
- •ASM – Assembler Example
- •Using A51 and BL51
- •Using AX51 and LX51
- •Using A251 and L251
- •CSAMPLE – C Compiler Example
- •Using C51 and BL51
- •Using C51 and LX51
- •Using C251 and L251
- •BANK_EX1 – Code Banking with C51
- •Using C51 and BL51
- •Using C51 and LX51
- •BANK_EX2 – Banking with Constants
- •Using C51 and BL51
- •Using C51 and LX51
- •Using BL51
- •Using C51 and LX51
- •Philips 80C51MX – Assembler Example
- •Philips 80C51MX – C Compiler Example
- •Appendix B. Reserved Symbols
- •Appendix C. Listing File Format
- •Assembler Listing File Format
- •Listing File Heading
- •Source Listing
- •Macro / Include File / Save Stack Format
- •Symbol Table
- •Listing File Trailer
- •Appendix D. Assembler Differences
- •Differences Between A51 and A251/AX51
- •Differences between A51 and ASM51
- •Differences between A251/AX51 & ASM51
- •Glossary
- •Index

Keil Software — A51/AX51/A251 Macro Assembler and Utilities |
289 |
|
|
Tips and Tricks for Program Locating
The Lx51 linker/locator supports several techniques that are required in for |
9 |
special tasks, for example in-system Flash programming or systems that use a |
RAM section for constants. The following section provides examples that show the usage of the Lx51 linker/locater in such situations.
Locate Segments with Wildcards
The Lx51 linker/locater allows in the segment controls wildcards for specifying the segment name. For example you may use such segment name specifications to locate all segments within one module into one 2KB block. In this way you can use the ACALL and AJMP instructions for function calls within this module.
BL51 myfile.obj CODE (?PR?*?myfile (0x1000))
LX51 myfile.obj SEGMENTS (?PR?*?myfile (C:0x1000))
|
290 |
Chapter 9. Linker/Locator |
|
|
|
||
|
Special ROM Handling (LX51 & L251 only) |
||
9 |
|||
The LX51 and L251 linker/locater provide the memory class SROM that is used |
|||
to handle segments or memory classes that are to be stored in ROM, but copied |
|||
|
for execution into RAM areas. This is useful for: |
||
|
|
In-system Flash programming when the Flash ROM contains also the flash |
|
|
|
programming code. With standard Flash devices it is impossible to fetch |
|
|
|
program code from the while other parts of the device are erased or |
|
|
|
programmed. The Keil Application Note 139: “In-system Flash |
|
|
|
Programming with 8051 and 251” that is available on www.keil.com or the |
|
|
|
Keil development tools CD-ROM contains a program example. |
|
|
|
For using the C251 TINY or XTINY memory model it is required to provide |
|
|
|
a NCONST memory class in the lowest 64KB memory region. However, if |
only RAM is mapped into this memory region, you can specify a different storage address for the NCONST memory class and copy the content at the program start into RAM. This allows you to use the efficient TINY or XTINY memory model while the system hardware just provides RAM in the lowest 64KB memory segment. Refer to “Use RAM for the 251 Memory Class NCONST” on page 292 for a program example.
Refer to Lx51 linker/locater controls “SEGMENTS” on page 346 and “CLASSES” on page 336 for syntax on defining segments and memory classes that have a different storage and execution address.

Keil Software — A51/AX51/A251 Macro Assembler and Utilities |
291 |
|
|
Segment and Class Information (LX51 & L251 only)
The Lx51 linker/locater creates special symbols that can be used to obtain |
9 |
|||||
address and length information for segments or classes used in an application. |
||||||
The information is passed via external variable declarations. The Lx51 |
|
|||||
linker/locater uses symbols with the notation segmentname_p_ or |
|
|||||
_classname_p_. Question mark (?) characters in the segment name generated by |
|
|||||
the Cx51 compiler are replaced with underscore (_) characters. The postfix _p_ |
|
|||||
specifies the information that should be obtained and is explained in the |
|
|||||
following table: |
|
|||||
|
|
|
|
|
|
|
|
Postfix |
|
Description |
|
|
|
|
_l_ |
|
is the length in bytes of the segment or memory class. For a memory class this |
|
|
|
|
|
|
number includes also any gaps that are required to allocate all segments that belong to |
|
|
|
|
|
|
this memory class. |
|
|
|
|
_s_ |
|
is the start address of the segment or memory class. For a memory class this number |
|
|
|
|
|
|
refers to the first segment that belongs to this memory class. |
|
|
|
|
_e_ |
|
is the end address of the segment or memory class. For a memory class this number |
|
|
|
|
|
|
refers to the last segment that belongs to this memory class. |
|
|
|
|
_t_ |
|
is the target or execution address of the segment or memory class. For a memory |
|
|
|
|
|
|
|
|
||
|
|
|
class this number refers to the first segment that belongs to this memory class. This |
|
|
|
|
|
|
information is only available for segments or memory classes which have assigned a |
|
|
|
|
|
|
different storage and execution address. |
|
|
|
Examples:
If ?PR?FUNC1 is the segment name:
is the length in bytes of the segment ?PR?FUNC1. is the start address of the segment ?PR?FUNC1. is the end address of the segment ?PR?FUNC1.
is the target or execution address of the segment ?PR?FUNC1.
If NCONST is the memory class name:
is the length in bytes of the memory class NCONST. is the start address of the memory class NCONST. is the end address of the memory class NCONST.
is the target or execution address of the memory class NCONST.

292 Chapter 9. Linker/Locator
|
|
You may access this information in Cx51 applications as shown in the following |
|
|
|
program example: |
|
9 |
|
||
|
|
||
|
extern char _PR_FUNC1_L_; |
||
|
|
unsigned int get_length (void) { |
|
|
|
return ((unsigned int) &_PR_FUNC1_L_); // length of segment ?PR?FUNC1 |
|
|
|||
|
|
} |
|
|
|
The file SROM.H contains macro definitions for accessing segment and class |
|
|
|
information. Refer to the Keil Application Note 139: “In-system Flash |
|
|
|
Programming with 8051 and 251” for more information. |
|
|
|
Use RAM for the 251 Memory Class NCONST |
|
|
|
The C251 compiler memory model TINY or XTINY requires a NCONST |
|
|
|
memory class in the lowest 64KB memory region. If your hardware provides |
|
|
|
only RAM in this memory area, you may use the SROM memory class to store |
|
|
|
the constants somewhere in the 16MB memory space and you may copy the |
|
|
|
content of the NCONST memory class into a RAM in the lowest 64KB memory. |
|
|
|
This is shown in the following program example. Refer to the “CLASSES” |
|
|
|
control on page 336 for more information. |
|
|
|
#include <string.h> |
|
|
|
extern char huge _NCONST_S_; |
|
|
|
extern char huge _NCONST_T_; |
|
|
|
extern char near |
_NCONST_L_; |
|
|
const char text [] = "This text is accessed in the NCONST memory class"; |
|
|
|
void main (void) |
{ |
|
|
fmemcpy (&_NCONST_T_, &_NCONST_S_, (unsigned int)&_NCONST_L_); |
:
}
The C251 compiler and L251 linker/locater is invoke as follows:
C251 SAMPLE.C XTINY DEBUG
L251 SAMPLE.C CLASSES (NCONST (0x2000-0x4000)[]), SROM (0xFE0000-0xFEFFFF)