- •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 |
93 |
|
|
Expressions
An expression is a combination of operands and operators that must be calculated by the assembler. An operand with no operators is the simplest form of an expression. An expression can be used in most places where an operand is required.
Expressions have a number of attributes that are described in the following sections.
Expression Classes
Expressions are assigned classes based on the operands that are used. The |
3 |
||
following classes apply to expressions: |
|||
Expression Class |
Description |
|
|
N NUMB |
A classless number. |
|
|
C ADDR |
A CODE address symbol. |
|
|
D ADDR |
A DATA address symbol. |
|
|
I ADDR |
An IDATA address symbol. |
|
|
X ADDR |
An XDATA address symbol. |
|
|
B ADDR |
A BIT address symbol. |
|
|
|
|
|
|
CO ADDR |
A CONST address symbol. |
|
|
EC ADDR |
An ECONST address symbol. |
|
|
CE ADDR |
An ECODE address symbol. |
|
|
ED ADDR |
An EDATA address symbol. |
|
|
EB ADDR |
An EBIT address symbol. |
|
|
HD ADDR |
An HDATA address symbol. |
|
|
HC ADDR |
An HCONST address symbol. |
|
|
Shaded directives and options are available only in AX51 and A251.
94 |
Chapter 3. Writing Assembly Programs |
|
|
Typically, expressions are assigned the class NUMBER because they are composed only of numeric operands. You may assign a class to an expression using a class operand. An address symbol value is automatically assigned the class of the segment where it is defined. When a value has a class, a few rules apply to how expressions are formed:
1. |
The result of a unary operation has the same class as its operand. |
|
2. |
The result of all binary operations except + and – will be a NUMBER type. |
|
3. |
If only one of the operands of an addition or subtraction operation has a class, |
|
3 |
the result will have that class. If both operands have a class, the result will be |
|
a NUMBER. |
||
|
This means that a class value (i.e. an addresses symbol) plus or minus a number (or a number plus a class value) give a value with class.
Examples
data_address - 10 |
gives a data_address value |
10 + edata_address |
gives an edata_address value |
(data_address - data_address) |
gives a classless number |
code_address + (data_address - data_address) |
gives a code_address value |
Expressions that have a type of NUMBER can be used virtually anywhere. Expressions that have a class can only be used where a class of that type is valid.
Shaded directives and options are available only in AX51 and A251.
Keil Software — A51/AX51/A251 Macro Assembler and Utilities |
95 |
|
|
Relocatable Expressions |
|
|
Relocatable expressions are so named because they contain a reference to a |
|
|
relocatable or external symbol. These types of expressions can only be partially |
|
|
calculated by the assembler since the assembler does not know the final location |
|
|
of relocatable segments. The final calculations are performed by the linker. |
|
|
A relocatable expression normally contains only a relocatable symbol, however, |
|
|
it may contain other operands and operators as well. A relocatable symbol can |
|
|
be modified by adding or subtracting a constant value. |
|
|
Examples for valid relocatable expression |
|
|
3 |
||
relocatable_symbol + absolute_expression |
||
|
||
relocatable_symbol - absolute_expression |
|
|
absolute_expression + relocatable_symbol |
|
|
There are two basic types of relocatable expressions: simple relocatable |
|
|
expressions and extended relocatable expressions. |
|
Shaded directives and options are available only in AX51 and A251.
96 |
Chapter 3. Writing Assembly Programs |
|
|
Simple Relocatable Expressions
Simple relocatable expressions contain symbols that are defined in a relocatable segment. Segment and external symbols are not allowed in simple relocatable expressions.
Simple relocatable expression can be used in four contexts:
|
1. |
As an operand to the ORG directive. |
|||||
|
2. |
As an operand to a symbol definition directive (i.e. EQU, SET) |
|||||
3 |
|||||||
3. |
As an operand to a data initialization directive (DB, DW or |
|
|
||||
DD) |
|||||||
|
|||||||
|
4. |
As an operand to a machine instruction |
|||||
|
|||||||
|
|
Examples for simple relocatable expressions |
|||||
|
|
|
|
|
|
||
|
|
REL1 + ABS1 * 10 |
|
|
|
||
|
|
REL2 - ABS1 |
|
|
|
||
|
|
REL1 + (REL2 - REL3) |
assuming REL2 and REL3 refer to the same segment. |
||||
|
|
Invalid form of simple relocatable expressions |
|||||
|
|
|
|
||||
|
|
(REL1 + ABS1) * 10 |
relocatable value may not be multiplied. |
||||
|
|
(EXT1 - ABS1) |
this is a general relocatable expression |
||||
|
|
REL1 + REL2 |
you cannot add relocatable symbols. |
||||
Shaded directives and options are available only in AX51 and A251.
Keil Software — A51/AX51/A251 Macro Assembler and Utilities |
97 |
|
|
Extended Relocatable Expressions
The extended relocatable expressions have generally the same rules that apply to simple relocatable expressions. Segment and external symbols are allowed in extended relocatable expressions. Extended relocatable expressions may be used only in statements that generate code as operands; these are:
As an operand to a data initialization directive (DB, DW or DD)
As an operand to a machine instruction
Examples for extended relocatable expressions
REL1 + ABS1 * 10 |
|
3 |
EXT1 - ABS1 |
|
|
LOW (REL1 + ABS1) |
|
|
WORD2 (SEG1) |
|
|
Invalid form of simple relocatable expressions |
||
|
|
|
(SEG1 + ABS1) * 10 |
relocatable value may not be multiplied. |
|
(EXT1 - REL1) |
you can add/subtract only absolute quantities |
|
LOW (REL1) + ABS1 |
LOW may be applied only to the |
|
|
final relocatable expression |
|
Shaded directives and options are available only in AX51 and A251.
98 Chapter 3. Writing Assembly Programs
Examples with Expressions
|
EXTRN CODE (CLAB) |
; entry in CODE space |
||||||||
|
EXTRN DATA (DVAR) |
; variable in DATA space |
||||||||
|
MSK |
EQU |
0F0H |
; define a symbol to replace 0xF0 |
||||||
|
VALUE |
EQU |
MSK - 1 |
; another constant symbolic value |
||||||
|
|
LVAL |
EQU |
12345678H |
; LVAL get the value 12345678H |
|
|
|
||
|
?PR?FOO SEGMENT CODE |
|
|
|
|
|
|
|||
|
|
|
RSEG |
?PR?FOO |
|
|
|
|
|
|
|
ENTRY: |
MOV |
A,#40H |
; load register with constant |
||||||
|
|
|
MOV |
R5,#VALUE |
; load constant symbolic value |
|||||
|
|
|
||||||||
3 |
|
|
MOV |
R3,#(0x20 AND MASK) |
; examples for calculations |
|||||
|
|
MOV |
R7,#LOW (VALUE + 20H) |
|
|
|
|
|
|
|
|
|
MOV |
R6,#1 OR (MSK SHL 4) |
|
|
|
|
|
|
|
|
|
MOV |
R0,DVAR+20 |
; load content from address DVAR+20 |
||||||
|
|
|
MOV |
R1,#LOW (CLAB+10) |
; load low byte of address CLAB+10 |
|||||
|
|
|
||||||||
|
|
|
MOV |
WR4,#WORD2 (LVAL) |
; load high word of LVAL |
|
|
|
|
|
|
|
|
MOV |
DR0,#ENTRY |
; load low word of addr. ENTRY to DR0 |
|
||||
|
|
|
MOVH |
DR0,#WORD2 (ENTRY) |
; load high word of addr. ENTRY to DR0 |
|||||
|
|
|
MOV |
R4,@DR0 |
; load content of ENTRY to R4 |
|
|
|||
; |
|
|
|
|
|
|
|
|
||
|
|
|
MOV |
R5,80H |
; load DATA addr. 80H (= SFR P0) to R5 |
|||||
|
|
|
MOV |
R5,EDATA 80H |
; load EDATA address 80H to R5 |
|
|
|||
|
|
|
SETB |
30H.2 |
; set bit at 30H.2 (long address) |
|
||||
|
|
|
SETB |
20H.2 |
; set bit at 20H.2 (short address) |
|||||
END
Shaded directives and options are available only in AX51 and A251.
