
- •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 |
113 |
|
|
Symbol Definition
The symbol definition directives allow you to create symbols that can be used to represent registers, numbers, and addresses.
Symbols defined by these directives may not have been previously defined and may not be redefined by any means. The SET directive is the only exception to this.
EQU, SET |
|
|
|
||
The EQU and SET directive assigns a numeric value or register symbol to the |
|
||||
specified symbol name. Symbols defined with EQU may not have been |
|
||||
previously defined and may not be redefined by any means. The SET directive |
|
||||
|
|||||
allows later redefinition of symbols. Statements involving the EQU or SET |
4 |
||||
directive are formatted as follows: |
|||||
|
|||||
|
|
|
|
||
symbol |
EQU |
expression |
|
|
|
symbol |
EQU |
register |
|
|
|
symbol |
SET |
expression |
|
|
|
symbol |
SET |
register |
|
|
|
where |
|
|
|
|
|
symbol |
|
is the name of the symbol to define. The expression or |
|
||
|
|
register specified in the EQU or SET directive will be |
|
||
|
|
substituted for each occurrence of symbol that is used in |
|
||
|
|
your assembly program. |
|
||
expression |
|
is a numeric expression which contains no forward |
|
||
|
|
references, or a simple relocatable expression. |
|
||
register |
|
is one of the following register names: A, R0, R1, R2, R3, |
|
||
|
|
R4, R5, R6, or R7. |
|
Symbols defined with the EQU or SET directive may be used anywhere in operands, expressions, or addresses. Symbols that are defined as a register name can be used anywhere a register is allowed. A251 replaces each occurrence of the defined symbol in your assembly program with the specified numeric value or register symbol.
Shaded directives and options are available only in AX51 and A251.

114 |
Chapter 4. Assembler Directives |
|
|
Symbols defined with the EQU directive may not be changed or redefined. You cannot use the SET directive if a symbol was previously defined with EQU and you cannot use the EQU directive if a symbol which was defined with SET.
Examples
LIMIT |
EQU |
1200 |
VALUE |
EQU |
LIMIT – 200 + 'A' |
SERIAL |
EQU |
SBUF |
ACCU |
EQU |
A |
COUNT |
EQU |
R5 |
VALUE |
SET |
100 |
VALUE |
SET |
VALUE / 2 |
COUNTER |
SET |
R1 |
TEMP |
SET |
COUNTER |
TEMP |
SET |
VALUE * VALUE |
CODE, DATA, IDATA, XDATA
4 |
The BIT, CODE, DATA, IDATA, and XDATA directives assigns an address |
|||
value to the specified symbol. Symbols defined with the BIT, CODE, DATA, |
||||
|
IDATA, and XDATA directives may not be changed or redefined. The format |
|||
|
of theses directives is: |
|
||
|
|
|
|
|
|
symbol |
BIT |
bit_address |
defines a BIT symbol |
|
symbol |
CODE |
code_address |
defines a CODE symbol |
|
symbol |
DATA |
data_address |
defines a DATA symbol |
|
symbol |
IDATA |
idata_address |
defines an IDATA symbol |
|
symbol |
XDATA |
xdata_address |
defines a XDATA symbol |
|
where |
|
|
|
|
symbol |
|
is the name of the symbol to define. The symbol name can |
|
|
|
|
be used anywhere an address of this memory class is valid. |
bit_address
code_address data_address
is the address of a bit in internal data memory in the area 20H .. 2FH or a bit address of an 8051 bit-addressable SFR.
is a code address in the range 0000H .. 0FFFFH.
is a data memory address in the range 0 to 127 or a special function register (SFR) address in the range 128 .. 255.
idata_address xdata_address
is an idata memory address in the range 0 to 255.
is an xdata memory address in the range 0 to 65535.
Shaded directives and options are available only in AX51 and A251.

Keil Software — A51/AX51/A251 Macro Assembler and Utilities |
115 |
|
|
Example
DATA_SEG |
SEGMENT BITADDRESSABLE |
|
|
|
|
RSEG |
DATA_SEG |
|
; a bit-addressable rel_seg |
|
|
CTRL: |
DS |
1 |
; a 1–byte variable (CTRL) |
|
|
ALARM |
BIT |
CTRL.0 |
; bit in a relocatable byte |
|
|
SHUT |
BIT |
ALARM+1 |
; the next bit |
|
|
ENABLE_FLAG |
BIT |
60H |
; an absolute bit |
|
|
DONE_FLAG |
BIT |
24H.2 |
; an absolute bit |
|
|
P1_BIT2 |
EQU |
90H.2 |
; a SFR bit |
|
|
RESTART |
CODE |
00H |
|
|
|
INTVEC_0 |
CODE |
RESTART + 3 |
|
|
|
INTVEC_1 |
CODE |
RESTART + 0BH |
|
|
|
INTVEC_2 |
CODE |
RESTART + 1BH |
|
|
|
SERBUF |
DATA |
SBUF |
; redfinition of SBUF |
|
|
RESULT |
DATA |
40H |
|
|
|
RESULT2 |
DATA |
RESULT + 2 |
|
|
|
PORT1 |
DATA |
90H |
; a SFR symbol |
|
|
BUFFER |
IDATA |
60H |
|
|
|
BUF_LEN |
EQU |
20H |
|
|
|
BUF_END |
IDATA |
BUFFER + BUF_LEN – 1 |
|
|
|
XSEG1 |
SEGMENT XDATA |
|
|
|
|
|
|
|
|||
RSEG |
XSEG1 |
|
|
|
4 |
DTIM: |
DS |
6 |
;reserve 6–bytes for DTIM |
|
|
TIME |
XDATA |
DTIM + 0 |
|
|
|
DATE |
XDATA |
DTIM + 3 |
|
|
|
|
|
|
|
|
|
Shaded directives and options are available only in AX51 and A251.

116 |
Chapter 4. Assembler Directives |
|
|
esfr, sfr, sfr16, sbit
The sfr, sfr16 and sbit directives are fully compatible to the Cx51 compiler and allows you to use a generic SFR register definition file for both: the Ax51 macro assembler and the Cx51 compiler. The esfr directive defines symbols in the extended SFR space of the Philips 80C51MX architecture. This directive is only available in the AX51 macro assembler. These directives have the following format:
sfr |
sfr_symbol |
= address; |
|
esfr |
sfr_symbol |
= address; |
|
sfr16 |
sfr_symbol |
= address; |
; ignored by Ax51 |
sbit |
sfr_symbol |
= bit-address; |
|
where
sfr_symbol is the name of the special function register (SFR) symbol to define.
4 address bit-address
is an SFR address in the range 0x80 – 0xFF.
is address of an SFR bit in the format address ^ bitpos or sfr_symbol ^ bitpos. address or sfr_symbol refers to an bitaddressable SFR and bitpos specifies the bit position of the SFR bit in the range 0 – 7.
Symbols defined with the esfr, sfr, or sbit directive may be used anywhere as address of a SFR or SFR bit.
Example
sfr |
P0 |
= 0x80; |
|
sfr |
P1 |
= 0x90; |
|
sbit |
P0_0 |
= P0^0; |
|
sbit |
P1_1 |
= 0x90^1; |
|
esfr |
MXCON |
= 0xFF; |
/* extended Philips 80C51MX SFR */ |
sfr16 |
T2 |
= 0xCC; |
/* ignored by Ax51 */ |
NOTE
The Ax51 assembler ignores symbol definitions that start with sfr16. This is implemented for compatibility to the Cx51 compiler.
Shaded directives and options are available only in AX51 and A251.