- •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 |
27 |
|
|
Chapter 2. Architecture Overview
This chapter gives you an overview of the 8051 architecture and the variants of the 8051. It reviews the memory layout of the classic 8051, extended 8051 variants, the Philips 80C51MX, and the 251 architecture. Also described are the register sets and the CPU instructions of the various CPU variants.
2
Memory Classes and Memory Layout
This section introduces the different memory classes (also known as memory types) that are used during programming of the 8051 and variants. Memory classes are used to identify the different physical memory regions of the microcontroller architecture that can be represented in a memory layout.
An overview of the different physical memory regions in an x51 system is provided below:
Program Memory: in the classic 8051 this is a 64KB space that is called CODE. This region is typically a ROM space that is used for program code and constants. With the BL51 you may expand the physical program code memory to 32 code banks with 64KB each. Constants are fetched with the MOVC instruction. In extended 8051 variants and the 251 you may have program memory of up to 16MB that is called ECODE and HCONST.
Internal Data Memory: in the classic 8051 this is the on-chip RAM space with a maximum of 256 Bytes that contains register banks, BIT space, direct addressable DATA space, and indirect addressable IDATA space. This region should be used for frequently used variables. In the 80C51MX and the 251 this space is expanded to up to 64KB with an EDATA space.
External Data Memory: in classic 8051 devices this area, called XDATA, is off-chip RAM with a space of up to 64KB. However several new 8051 devices have additional on-chip RAM that is mapped into the XDATA space. Usually you need to enable this additional on-chip RAM via dedicated SFR registers. In extended variants and the 251 you may have external data memory of up to 16MB that is called HDATA.
28 |
Chapter 2. Architecture Overview |
|
|
Classic 8051
The following table shows the memory classes used for programming the classic 8051 architecture. These memory classes are available when you are using the A51 macro assembler and the BL51 linker/locater.
2 |
|
|
|
|
|
|
Memory Class |
Address Range |
Description |
|
|
|
DATA |
D:00 – D:7F |
Direct addressable on-chip RAM. |
|
|
|
BIT |
D:20 – D:2F |
bit-addressable RAM; accessed bit instructions. |
|
|
|
|
IDATA |
I:00 – I:FF |
Indirect addressable on-chip RAM; can be |
|
|
|
||||
|
|
|
|
accessed with @R0 or @R1. |
|
|
|
XDATA |
X:0000 – X:FFFF |
64 KB RAM (read/write access). Accessed with |
|
|
|
|
|
MOVX instruction. |
|
|
|
CODE |
C:0000 – C:FFFF |
64 KB ROM (only read access possible). Used |
|
|
|
|
|
for executable code or constants. |
|
|
|
BANK 0 |
B0:0000 – B0:FFFF |
Code Banks for expanding the program code |
|
|
|
… BANK 31 |
B31:0000 – B31:FFFF |
space to 32 x 64KB ROM. |
|
NOTE
The memory prefix D: I: X: C: B0: .. B31: cannot be used at Ax51 assembler or BL51 linker/locater level. The memory prefixes are only listed for better understanding. Several Debugging tools, for example the µVision2 Debugger, are using memory prefixes to identify the memory class of the address.
Keil Software — A51/AX51/A251 Macro Assembler and Utilities |
29 |
|
|
Classic 8051 Memory Layout
The classic 8051 memory layout, shown in the following figure, is familiar to 8051 users the world over.
DATA FF
F8
2
|
|
|
98 |
|
|
|
|
8051 |
|
C:FFFF |
Bx:FFFF |
|
Bit |
|
SFR |
addressable |
|||
|
|
|||
|
|
SPACE |
90 |
|
|
|
|
CODE |
BANK 0 |
|
88 |
|
|
||
... BANK 31 |
|
|
|
|
DATA |
|
|
|
|
80 |
|
|
|
80 |
|
|
|
D:0x7F |
|
C:0000 |
Bx:0000 |
|
|
|
I:0x100 |
|
|
|
IDATA |
|
|
|
256 BYTE |
|
|
|
|
DATA |
|
|
|
128 BYTE |
|
|
I:0x80 |
|
|
X:FFFF |
|
|
2F |
|
|
8051 |
|
|
|
|
|
|
|
|
Bitspace |
|
DATA |
|
20 |
|
|
1F |
|
|
128 BYTE |
|
|
XDATA |
|
|
|
|
|
4 Register |
|
|
|
|
|
|
|
|
Banks |
X:0000 |
D:0 |
|
0 |
The memory code banks overlap the CODE space. The size of the code banks is selected with the Lx51 directive BANKAREA.
30 |
Chapter 2. Architecture Overview |
|
|
Extended 8051 Variants
Several new variants of the 8051 extend the code and/or xdata space of the classic 8051 with address extension registers. The following table shows the memory classes used for programming the extended 8051 devices. These memory classes are available for classic 8051 devices when you are using memory banking with the LX51 linker/locater. In addition to the code banking
2 known from the BL51 linker/locater, the LX51 linker/locator supports also data banking for xdata and code areas with standard 8051 devices.
Memory Class |
Address Range |
Description |
DATA |
D:00 – D:7F |
Direct addressable on-chip RAM. |
BIT |
D:20 – D:2F |
bit-addressable RAM; accessed bit instructions. |
IDATA |
I:00 – I:FF |
Indirect addressable on-chip RAM; can be |
|
|
accessed with @R0 or @R1. |
XDATA |
X:0000 – X:FFFF |
64 KB RAM (read/write access). Accessed with |
|
|
MOVX instruction. |
HDATA |
X:0000 – X:FFFFFF |
16 MB RAM (read/write access). Accessed with |
|
|
MOVX instruction and extended DPTR. |
CODE |
C:0000 – C:FFFF |
64 KB ROM (only read access possible). Used |
|
|
for executable code or constants. |
ECODE |
C:0000 – C:FFFFFF |
16 MB ROM (only read access possible). Used |
|
|
for constants. In some modes of the Dallas 390 |
|
|
architecture also program execution is possible. |
BANK 0 |
B0:0000 – B0:FFFF |
Code Banks for expanding the program code |
… BANK 31 |
B31:0000 – B31:FFFF |
space to 32 x 64KB ROM. |
NOTES
The memory prefixes D: I: X: C: B0: .. B31: cannot be used at Ax51 assembler level. The memory prefix is only listed for better understanding. The Lx51 linker/locater and several Debugging tools, for example the µVision2 Debugger, are using memory prefixes to identify the memory class of the address.
If you are using the Dallas 390 contiguous mode the address space for CODE can be C:0000 - C:0xFFFFFF.
Keil Software — A51/AX51/A251 Macro Assembler and Utilities |
31 |
|
|
Extended 8051 Memory Layout
The extended 8051 memory layout, shown in the following figure, expands the address space for variables to a maximum of 16MB.
|
|
DATA FF |
|
2 |
|
C:3FFFFF |
|
F8 |
|
|
BANK 63 |
|
|
|
|
C:3F0000 |
|
|
|
|
|
|
98 |
8051 |
HCONST |
|
|
|
|
C:20000 |
|
|
Bit |
|
16MB |
|
|
||
max. |
|
SFR |
90 |
addressable |
|
|
SPACE |
|
|
|
BANK 1 |
|
|
|
|
|
|
|
|
|
C:10000 |
|
88 |
|
|
DATA |
80 |
|
CODE |
80 |
||
D:0x7F |
|
||
BANK 0 |
|
||
C:0000 |
|
|
|
|
I:0x100 |
|
|
|
IDATA |
|
|
|
256 BYTE |
|
|
|
DATA |
|
|
|
128 BYTE |
|
|
HDATA |
I:0x80 |
|
|
16MB |
|
2F |
|
max. |
|
||
|
|
||
|
|
8051 |
|
X:FFFF |
|
Bitspace |
|
DATA |
20 |
||
|
|||
|
1F |
||
|
128 BYTE |
||
|
|
||
XDATA |
|
4 Register |
|
|
Banks |
||
|
|
||
X:0000 |
D:0 |
0 |
|
|
|
In several variants the DPTR register is expanded to a 24-bit register with an DPX SFR. Fox example, the Dallas 390 and provides new operating modes where this addressing is enabled. You may even use the HCONST and HDATA memory classes with classic 8051 devices by using the memory banking available in LX51.