
- •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 |
19 |
|
|
Modular Program Development Process
This section is a brief discussion of the program development process with the |
1 |
relocatable Ax51 assembler, Lx51 Linker/Locator, and the OHx51 code |
conversion program.
Segments, Modules, and Programs
In the initial design stages, the tasks to be performed by the program are defined, and then partitioned into subprograms. Here are brief introductions to the kinds of subprograms used with the Ax51 assembler and Lx51 linker/locator.
A segment is a block of code or data memory. A segment may be relocatable or absolute. A relocatable segment has a name, type, and other attributes. Segments with the same name, from different modules, are considered part of the same segment and are called partial segments. Several partial segments with the same name are combined into one segment by the Lx51 linker/locater. An absolute segment cannot be combined with other segments.
A module contains one or more segments or partial segments. A module is a source code unit that can be translated independently. It contains all symbol definitions that are used within the module. A module might be a single ASCII text file that is created by any standard text editor. However, with you may use the include assembler directive to merge several text files. The Ax51 assembler translates a source file into an object file. Each object file is one module.
After assembly of all modules of the program, Lx51 processes the object module files. The Lx51 linker/locator assigns absolute memory locations to all the relocatable segments, combining segments with the same name and type. Lx51 also resolves all references between modules. Lx51 outputs an absolute object module file with the completed program, and a map file that lists the results of the link/locate process.

20 Chapter 1. Introduction
1 |
Translate and Link Process |
Typically you will use the Ax51 assembler and the tools within the µVision2 |
|
IDE. For more information on using the µVision2 IDE refer to the User’s Guide |
µVision2: Getting Started for 8051.
However, you may invoke the Ax51 assembler also from the command line. Simply type the name of the assembler version that you want to use, for example A51 at the Windows command prompt. On this command line, you must include the name of the assembler source file to be translated, as well as any other necessary control directives required to translate your source file. Example:
A51 DEMO.A51
The assembler output for this command line is:
A51 MACRO ASSEMBLER V6.00
ASSEMBLY COMPLETE. 0 WARNING(S), 0 ERROR(S)
After assembly of all your program modules, the object modules are linked and all variables and addresses are resolved and located into an executable program by the Lx51 linker. The following example shows a simple command line for the linker:
BL51 DEMO.OBJ, PRINT.OBJ
The linker generates an absolute object file as well as a map file that contains detailed statistic information and screen messages. The output of the linker is:
BL51 LINKER/LOCATER V4.00
LINK/LOCATE RUN COMPLETE. 0 WARNING(S), 0 ERROR(S)
Then you might convert the executable program into an Intel HEX file for PROM programming. This is done with the OHx51 hex conversion utility with the following invocation:
OH51 DEMO
The output of the hex conversion utility is:
OBJECT TO HEX FILE CONVERTER OH51 V2.40
GENERATING INTEL HEX FILE: DEMO.HEX
OBJECT TO HEX CONVERSION COMPLETED.

Keil Software — A51/AX51/A251 Macro Assembler and Utilities |
21 |
|
|
An example listing file generated by the assembler is shown on the following page.
A51 MACRO ASSEMBLER |
ASSEMBLER DEMO PROGRAM |
|
07/07/2000 18:32:30 PAGE 1 |
1 |
|||||
MACRO ASSEMBLER A51 V6.01 |
|
|
|
|
|
||||
OBJECT MODULE PLACED IN demo.OBJ |
|
|
|
|
|
||||
ASSEMBLER INVOKED BY: C:\KEIL\C51\BIN\A51.EXE DEMO.A51 DEBUG |
|
||||||||
LOC |
OBJ |
|
LINE |
SOURCE |
|
|
|
|
|
|
|
|
1 |
$title |
(ASSEMBLER DEMO PROGRAM) |
|
|||
|
|
|
2 |
; A simple Assembler Module for Demonstration |
|
||||
|
|
|
3 |
|
|
|
|
|
|
|
|
|
4 |
; Symbol Definition |
|
|
|||
000D |
|
5 |
CR |
EQU |
13 |
|
; Carriage?Return |
|
|
000A |
|
6 |
LF |
EQU |
10 |
|
; Line?Feed |
|
|
|
|
|
7 |
|
|
|
|
|
|
|
|
|
8 |
; Segment Definition |
|
|
|||
|
|
|
9 |
?PR?DEMO |
SEGMENT |
CODE ; Program Part |
|
||
|
|
|
10 |
?CO?DEMO |
SEGMENT |
CODE ; Constant Part |
|
||
|
|
|
11 |
|
|
|
|
|
|
|
|
|
12 |
; Extern Definition |
|
|
|||
|
|
|
13 |
EXTRN CODE (PRINTS, DEMO) |
|
||||
|
|
|
14 |
|
|
|
|
|
|
|
|
|
15 |
; The Program Start |
|
|
|||
---- |
|
|
16 |
|
CSEG |
AT |
0 |
; Reset Vector |
|
0000 |
020000 |
F |
17 |
|
JMP |
Start |
|
|
|
|
|
|
18 |
|
|
|
|
|
|
---- |
|
|
19 |
|
RSEG |
?PR?DEMO |
; Program Part |
|
|
0000 |
900000 |
F |
20 |
START: |
MOV |
DPTR,#Txt |
; Demo Text |
|
|
0003 |
120000 |
F |
21 |
|
CALL |
PRINTS |
; Print String |
|
|
|
|
|
22 |
; |
|
|
|
|
|
0006 |
020000 |
F |
23 |
|
JMP |
DEMO |
|
; Demo Program |
|
|
|
|
24 |
|
|
|
|
|
|
|
|
|
25 |
; The Text Constants |
|
|
|||
---- |
|
|
26 |
|
RSEG |
?CO?DEMO |
; Constant Part |
|
|
0000 |
48656C6C |
|
27 |
Txt: |
DB |
'Hello World',CR,LF,0 |
|
||
0004 |
6F20576F |
|
|
|
|
|
|
|
|
0008 |
726C640D |
|
|
|
|
|
|
|
|
000C |
0A00 |
|
|
|
|
|
|
|
|
|
|
|
28 |
|
|
|
|
|
|
|
|
|
29 |
|
END |
|
|
; End of Module |
|
SYMBOL TABLE LISTING |
|
|
|
|
|
|
|
||
------ ----- ------- |
|
|
|
|
|
|
|
||
N A M E |
|
T Y P E |
V A L U E |
ATTRIBUTES |
|
|
|||
?CO?DEMO . . . . . |
C SEG |
000EH |
|
REL=UNIT |
|
|
|||
?PR?DEMO . . . . . |
C SEG |
0009H |
|
REL=UNIT |
|
|
|||
CR . . . . . . . . |
N NUMB |
000DH |
A |
|
|
|
|
||
DEMO . . . . . . . |
C ADDR |
----- |
|
EXT |
|
|
|
||
LF . . . . . . . . |
N NUMB |
000AH |
A |
|
|
|
|
||
PRINTS . . . . . . |
C ADDR |
----- |
|
EXT |
|
|
|
||
START. . . . . . . |
C ADDR |
0000H |
R |
SEG=?PR?DEMO |
|
|
|||
TXT. . . . . . . . |
C ADDR |
0000H |
R |
SEG=?CO?DEMO |
|
|
|||
REGISTER BANK(S) USED: 0 |
|
|
|
|
|
|
|||
ASSEMBLY COMPLETE. |
0 WARNING(S), 0 ERROR(S) |
|
|
|
|
22 |
|
|
Chapter 1. Introduction |
||
|
|
|
|
|
||
|
|
Filename Extensions |
||||
1 |
||||||
|
Typically, the filename extension is used to indicate the contents of each file. |
|||||
|
The following table lists the file name extensions that are used in the 8051 tool |
|||||
|
|
chain. |
|
|
||
|
|
|
|
|
||
|
|
Extension |
Content and Description |
|
||
|
|
.A51 |
|
Source code file: contains ASCII text that is the input for the Ax51 assembler. |
|
|
|
|
.ASM |
|
|
||
|
|
.SRC |
|
|
||
|
|
.C |
|
C source code file: contains ASCII text that is the input for the Cx51 ANSI C |
|
|
|
|
.C51 |
|
compiler. |
|
|
|
|
.INC |
|
Include file: contains ASCII text that is merged into an source code file with the |
|
|
|
|
.H |
|
include directive. Also these files are input files for Ax51 or Cx51. |
|
|
|
|
.OBJ |
Relocatable object file: is the output of the Ax51 or Cx51 that contains the program |
|
||
|
|
|
|
code and control information. Several relocatable object files are typically input files |
|
|
|
|
|
|
for the Lx51 Linker/Locater. |
|
|
|
|
.LST |
|
Listing object file: is generated by Ax51 or Cx51 to document the translation |
|
|
|
|
|
|
process. A listing file typically contains the ASCII program text and diagnostic |
|
|
|
|
|
|
information about the source module. Appendix F describes the format of the Ax51 |
|
|
|
|
|
|
listing file. |
|
|
|
|
. |
(none) |
Absolute object file: is the output of the Lx51. Typically it is a complete program |
|
|
|
|
.ABS |
that can be executed on the x51 CPU. |
|
||
|
|
.M51 |
|
Linker map file: is the listing file generated from Lx51. A map file contains |
|
|
|
|
.MAP |
information about the memory usage and other statistic information. |
|
||
|
|
.HEX |
Hex file: is the output file of the OHx51 object hex converter in Intel HEX file |
|
||
|
|
.H86 |
|
format. HEX files are used as input file for PROM programmers or other utility |
|
|
|
|
|
|
programs. |
|