- •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
36 |
Chapter 2. Architecture Overview |
|
|
CPU Registers
The following section provides an overview of the CPU registers that are available on the x51 variants.
In addition to the CPU registers R0 - R7, all x51 variants have an SFR space that is used to address on-chip peripherals and I/O ports. In the SFR area also reside
2 the CPU registers SP (stack pointer), PSW (program status word), A (accumulator, accessed via the SFR space as ACC), B, DPL and DPH (16-bit register DPTR).
CPU Registers of the 8051 Variants
The classic 8051 provides 4 register banks of 8 registers each. These register banks are mapped into the DATA memory area at address 0 – 0x1F. In addition the CPU provides a 8-bit A (accumulator) and B register and a 16-bit DPTR (data pointer) for addressing XDATA and CODE memory. These registers are also mapped into the SFR space as special function registers.
8 Bytes
Registerbank 3
D:0x18
Registerbank 2
D:0x10
Registerbank 1
D:0x08
Registerbank 0
D:0x00
DATA MEMORY
Some CPU variants provide extended DPTR and/or SP registers. Also several devices have multiple DPTR registers.
The active Registerbank is selected via the bits RB0 and RB1 in the program status word (PSW).
Universal Pointers on Philips 80C51MX
|
|
|
|
|
|
|
PR0 |
|
|
|
|
|
PR1 |
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
R0 |
R1 |
|
R2 |
|
R3 |
R4 |
|
R5 |
R6 |
R7 |
||||
|
|
DPTR |
|
CPU REGISTER |
|
|||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||
DPX |
|
DPH |
|
DPL |
|
|
A |
|
B |
|
|
PSW |
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SPX |
|
SP |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Keil Software — A51/AX51/A251 Macro Assembler and Utilities |
37 |
|
|
CPU Registers of the Intel/Atmel WM 251
The 251 architecture supports an extra 32 bytes of registers in addition to the 4 |
|
banks of 8 registers found in the classic 8051. The lower 8 byte registers are |
|
mapped between locations 00:00 - 00:0x1F. The lower 8 byte registers are |
|
mapped in this way to support 8051 microcontroller register banking. The |
|
register file can be addressed in the following ways: |
2 |
Register 0 - 15 can be used as either byte, word, or double word (Dword) |
registers.
Register 16 - 31 can be addressed as either word or Dword registers.
Register DR56 and DR60 can be addressed only as Dword registers.
There are 16 possible byte registers (R0 - R15), 16 possible word registers (WR0 - WR30) and 10 possible Dword registers (DR0 - DR28, DR56 - DR60) that can be addressed in any combination.
All Dword registers are Dword aligned; each is addressed as DRk with “k” being the lowest of the 4 consecutive registers. For example, DR4 consists of registers 4 - 7.
All word registers are word aligned; each is addressed as WRj with “j” being the lower of the 2 consecutive registers. For example WR4 consists of registers 4 - 5.
All byte registers are inherently byte aligned; each is addressed as Rm with “m” being the register number. For example R4 consists of register 4.
38 |
Chapter 2. Architecture Overview |
|
|
The following figure shows the register file format for the 251 microcontroller.
8 Bytes
Register 56 - 63
2
Register 8 - 31
Register 0 - 7
MEMORY
The 8051 CPU Registers A, B, DPL, DPH and SP are mapped into the 251 register file. The following 251 CPU registers are identical with the 8051 CPU registers:
8051 Register |
251 Register |
A (ACC) |
R11 |
B |
R10 |
DPL |
low byte of DR56 |
DPH |
2nd byte of DR56 |
SP |
low byte of DR60 |
The stack pointer register (DR60) of the 251 CPU is a 16-bit register. DR60 is used for all stack operations (PUSH, POP, CALL, RET, ect.) and can be also used for indirect addressing. Therefore the 251 provides efficient stack addressing modes for reentrant functions.
WR24 |
WR26 |
|
WR28 |
WR30 |
||||
|
|
|
|
|
|
|
|
|
WR16 |
WR18 |
|
WR20 |
WR22 |
||||
|
|
|
|
|
|
|
|
|
WR8 |
WR10 |
|
WR12 |
WR14 |
||||
|
|
|
|
|
|
|
|
|
WR0 |
WR2 |
|
WR4 |
WR6 |
||||
|
|
|
|
|
|
|
|
|
|
|
WORD REGISTER |
|
|||||
|
|
|
|
|
|
|
|
|
R8 |
R9 |
R10 |
R11 |
|
R12 |
R13 |
R14 |
R15 |
|
|
|
|
|
|
|
|
|
R0 |
R1 |
R2 |
R3 |
|
R4 |
R5 |
R6 |
R7 |
|
|
|
|
|
|
|
|
|
|
|
BYTE REGISTER |
|
|||||
|
|
|
|
Stack Pointer (SPX) |
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DR56 |
|
|
|
DR60 |
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DR24 |
|
|
|
DR28 |
|
||
|
|
|
|
|
|
|
|
|
|
DR16 |
|
|
|
DR20 |
|
||
|
|
|
|
|
|
|
|
|
|
DR8 |
|
|
|
DR12 |
|
||
|
|
|
|
|
|
|
|
|
|
DR0 |
|
|
|
DR4 |
|
||
|
|
|
|
|
||||
|
DWORD REGISTER |
|
||||||
|
|
|
|
Stack Pointer (SPX) |
||||
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DR56 |
|
|
|
DR60 |
|
||
|
|
|
|
|
|
|||
|
|
|
|
|
|
|||
|
DR24 |
|
|
WR28 |
WR30 |
|||
|
|
|
|
|
|
|
||
WR16 |
WR18 |
|
|
DR20 |
|
|||
|
|
|
|
|
|
|
||
WR8 |
WR10 |
|
R12 |
R13 |
R14 |
R15 |
||
|
|
|
|
|
|
|
|
|
WR0 |
R2 |
R3 |
|
|
DR4 |
|
||
|
|
|
|
|
|
|
|
|
EXAMPLE OF MIXED USAGE
Keil Software — A51/AX51/A251 Macro Assembler and Utilities |
39 |
|
|
Program Status Word (PSW)
The Program Status Word (PSW) contains status bits that reflect the current CPU state. The 8051 variants provide one special function register called PSW with this status information. The 251 provides two additional status flags, Z and N, that are available in a second special function register called PSW1.
|
PSW Register (all 8051 and 251 variants) |
2 |
||||||||
|
|
|
||||||||
|
|
|
|
|
|
|
|
|
|
|
|
Bit 7 |
Bit 6 |
Bit 5 |
Bit 4 |
Bit 3 |
Bit 2 |
Bit 1 |
Bit 0 |
|
|
|
CY |
AC |
F0 |
RS1 |
RS0 |
OV |
UD |
P |
|
|
|
|
|
|
|
|
|
|
|
|
|
Additional PSW1 Register (on Intel/Atmel WM 251 only)
Bit 7 |
Bit 6 |
Bit 5 |
Bit 4 |
Bit 3 |
Bit 2 |
Bit 1 |
Bit 0 |
CY |
AC |
N |
RS1 |
RS0 |
OV |
Z |
– |
|
|
|
|
|
|
|
|
The following table describes the status bits in the PSW.
|
|
Symbol |
|
Function |
|
|
|
|
|
CY |
Carry flag |
|
|
|
|
|
|
AC |
Auxiliary Carry flag (For BCD Operations) |
|
|||
|
|
F0 |
Flag 0 (Available to the user for General Purpose) |
|
|||
|
|
RS1, |
Register bank select: RS1 |
RS0 |
Working Register Bank and Address |
||
|
|
RS0 |
0 |
0 |
Bank0 |
(D:0x00 - D:0x07) |
|
|
|
|
0 |
1 |
Bank1 |
(D:0x08 - D:0x0F) |
|
|
|
|
1 |
0 |
Bank2 |
(D:0x10 - D:0x17) |
|
|
|
|
1 |
1 |
Bank3 |
(D:0x18H - D:0x1F) |
|
|
|
OV |
Overflow flag |
|
|
|
|
|
|
UD |
User definable flag |
|
|
|
|
|
|
P |
Parity flag |
|
|
|
|
|
251 ONLY |
– |
|
Reserved for future use |
|
|
|
|
Z |
|
Zero flag |
|
|
|
|
|
|
|
|
|
|
||
|
|
N |
|
Negative flag |
|
|
|