- •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
88 |
Chapter 3. Writing Assembly Programs |
|
|
Operators
The Ax51 assembler provides several classes of operators that allow you to compare and combine operands and expressions. These operators are described in the sections that follow.
Arithmetic Operators
Arithmetic operators perform arithmetic functions like addition, subtraction, multiplication, and division. These operators require one or two operands depending on the operation. The result is always a 16-bit value. Overflow and
3 underflow conditions are not detected. Division by zero is detected and causes an assembler error.
Operator |
Syntax |
|
|
Description |
+ |
+ expression |
|
Unary plus sign |
|
– |
– expression |
|
Unary minus sign |
|
+ |
expression |
+ |
expression |
Addition |
– |
expression |
– |
expression |
Subtraction |
* |
expression |
* |
expression |
Multiplication |
/ |
expression |
/ |
expression |
Integer division |
MOD |
expression |
MOD expression |
Remainder |
|
( and ) |
(expression) |
|
Specify order of execution |
|
Binary Operators
Binary operators are used to complement, shift, and perform bit–wise operations on the binary value of their operands.
Operator |
Syntax |
|
|
Description |
NOT |
NOT expression |
|
Bit–wise complement |
|
SHR |
expression |
SHR |
count |
Shift right |
SHL |
expression |
SHL |
count |
Shift left |
AND |
expression |
AND expression |
Bit–wise AND |
|
OR |
expression |
OR expression |
Bit–wise OR |
|
XOR |
expression |
XOR expression |
Bit–wise exclusive OR |
|
Shaded directives and options are available only in AX51 and A251.
Keil Software — A51/AX51/A251 Macro Assembler and Utilities |
89 |
|
|
Relational Operators
The relational operators compare two operands. The result of the comparison is a TRUE or FALSE. A FALSE result has a value of 0000h. A TRUE result has a non–zero value.
The following table lists the relational operators and provides a brief description of each.
|
Operator |
Syntax |
|
|
|
|
Result |
|
|
|
|
|
|
GTE |
expression1 |
GTE |
expression2 |
True if |
expression1 |
is greater than or equal to |
|
|
|||
|
3 |
|||||||||||
|
|
|
|
|
|
|
expression2 |
|
|
|
||
|
LTE |
expression1 |
LTE |
expression2 |
True if |
expression1 |
is less than or equal to |
|
||||
|
|
|
|
|
|
|
expression2 |
|
|
|
||
|
NE |
expression1 |
NE |
expression2 |
True if |
expression1 |
is not equal to expression2 |
|
|
|||
|
EQ |
expression1 |
EQ |
expression2 |
True if |
expression1 |
is equal to |
expression2 |
|
|
||
|
LT |
expression1 |
LT |
expression2 |
True if |
expression1 |
is less than |
expression2 |
|
|
||
|
GT |
expression1 |
GT |
expression2 |
True if |
expression1 |
is greater than expression2 |
|
|
|||
|
>= |
expression1 |
>= |
expression2 |
True if |
expression1 |
is greater than or equal to |
|
|
|||
|
|
|
|
|
|
|
expression2 |
|
|
|
|
|
|
<= |
expression1 |
<= |
expression2 |
True if |
expression1 |
is less than or equal to |
|
|
|||
|
|
|
|
|
|
|
expression2 |
|
|
|
|
|
|
<> |
expression1 |
<> |
expression2 |
True if |
expression1 |
is not equal to expression2 |
|
|
|||
|
= |
expression1 |
= |
expression2 |
True if |
expression1 |
is equal to |
expression2 |
|
|
||
|
< |
expression1 |
< |
expression2 |
True if |
expression1 |
is less than |
expression2 |
|
|
||
|
> |
expression1 |
> |
expression2 |
True if |
expression1 |
is greater than expression2 |
|
|
|||
Shaded directives and options are available only in AX51 and A251.
90 |
Chapter 3. Writing Assembly Programs |
|
|
Class Operators
The class operator assigns a memory class to an expression. This is how you associate an expression with a class. The Ax51 assembler generates an error message if you use an expression with a class on an instruction which does not support this class, for example, when you use an XDATA expression as a direct address.
The following table lists the class operators and provides a brief description of each.
3 |
|
Operator |
Syntax |
Description |
|
|
BIT |
BIT expression |
Assigns the class BIT to the expression. |
|
|
|
CODE |
CODE expression |
Assigns the class CODE to the expression. |
|
|
|
|
CONST |
CONST expression |
Assigns the class CONST to the expression. |
|
|
|
||||
|
|
DATA |
DATA expression |
Assigns the class DATA to the expression. |
|
|
|
EBIT |
EBIT expression |
Assigns the class EBIT to the expression. |
|
|
|
ECODE |
ECODE expression |
Assigns the class ECODE to the expression. |
|
|
|
ECONST |
ECONST expression |
Assigns the class ECONST to the expression. |
|
|
|
EDATA |
EDATA expression |
Assigns the class EDATA to the expression. |
|
|
|
IDATA |
IDATA expression |
Assigns the class IDATA to the expression. |
|
|
|
|
|
|
|
|
|
HCONST |
HCONST expression |
Assigns the class HCONST to the expression. |
|
|
|
HDATA |
HDATA expression |
Assigns the class HDATA to the expression. |
|
|
|
XDATA |
XDATA expression |
Assigns the class XDATA to the expression. |
|
Type Operators
The type operator assigns a data type to an expression. The A251 assembler generates an error if you attempt to use an instruction with the incorrect data type. For example, this happens when you use a WORD expression as an argument in a byte-wide instruction of the 251.
Operator |
Syntax |
Description |
BYTE |
BYTE expression |
Assigns the type BYTE to the expression. |
WORD |
WORD expression |
Assigns the class WORD to the expression. |
DWORD |
DWORD expression |
Assigns the class DWORD to the expression. |
NEAR |
NEAR expression |
Assigns the class NEAR to the expression. |
FAR |
FAR expression |
Assigns the class FAR to the expression. |
Shaded directives and options are available only in AX51 and A251.
Keil Software — A51/AX51/A251 Macro Assembler and Utilities |
91 |
|
|
Miscellaneous Operators
Ax51 provides operators that do not fall into the previously listed categories. These operators are listed and described in the following table.
Operator |
Syntax |
|
Description |
|
|
|
|||
LOW |
LOW |
expression |
Low–order byte of expression |
|
|
|
|||
HIGH |
HIGH |
expression |
High–order byte of expression |
|
|
|
|||
BYTE0 |
BYTE0 |
expression |
Byte 0 of expression. See table below. (identical |
|
|
||||
|
|
|
|
|
with LOW). |
|
|
|
|
BYTE1 |
BYTE1 |
expression |
Byte 1 of expression. See table below. (identical |
|
|
||||
|
|||||||||
|
|
|
|
|
with HIGH). |
|
|
3 |
|
BYTE2 |
BYTE2 |
expression |
Byte 2 of expression. See table below. |
|
|||||
BYTE3 |
BYTE3 |
expression |
Byte 3 of expression. See table below. |
|
|||||
WORD0 |
WORD0 expression |
Word 0 of expression. See table below. |
|
|
|||||
WORD2 |
WORD2 expression |
Word2 of expression. See table below. |
|
|
|||||
MBYTE |
MBYTE |
expression |
AX51 only: memory type information for C51 |
|
|
||||
|
|
|
|
|
run-time libraries. Returns the memory type that |
|
|
||
|
|
|
|
|
is used in the C51 run-time library to access |
|
|
||
|
|
|
|
|
variables defined with the far memory type. |
|
|
||
The following table shows how the byte and word operators impact a 32-bit |
|
||||||||
value. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MSB |
|
|
|
|
|
|
LSB |
|
|
BYTE3 |
|
|
|
BYTE2 |
BYTE1 |
|
BYTE0 |
|
|
|
WORD2 |
|
WORD0 |
|
|
|
|||
|
|
|
|
|
HIGH |
|
LOW |
|
|
The following table shows how the byte and word operators impact a 32-bit value.
Shaded directives and options are available only in AX51 and A251.
92 |
Chapter 3. Writing Assembly Programs |
|
|
Operator Precedence
All operators are evaluated in a certain, well–defined order. This order of evaluation is referred to as operator precedence. Operator precedence is required in order to determine which operators are evaluated first in an expression. The following table lists the operators in the order of evaluation. Operators at level 1 are evaluated first. If there is more than one operator on a given level, the leftmost operator is evaluated first followed by each subsequent operator on that level.
|
|
Level |
Operators |
|
3 |
|
|||
|
1 |
( ) |
|
|
|
2 |
NOT, HIGH, LOW, BYTE0, BYTE1, BYTE2, BYTE3, WORD0, WORD2 |
|
|
|
3 |
BIT, CODE, CONST, DATA, EBIT, EDATA, ECONST, ECODE, HCONST, |
|
|
|
|
|
HDATA, IDATA, XDATA |
|
|
|
|
|
|
|
|
4 |
BYTE, WORD, DWORD, NEAR, FAR |
|
|
|
5 |
+ (unary), – (unary) |
|
|
|
6 |
*, /, MOD |
|
|
|
7 |
+, – |
|
|
|
8 |
SHR, SHL |
|
|
|
9 |
AND, OR, XOR |
|
|
|
10 |
>=, <=, =, <>, <, >, GTE, LTE, EQ, NE, LT, GT |
|
Shaded directives and options are available only in AX51 and A251.
