logo资料库

Keil A51参考手册.pdf

第1页 / 共245页
第2页 / 共245页
第3页 / 共245页
第4页 / 共245页
第5页 / 共245页
第6页 / 共245页
第7页 / 共245页
第8页 / 共245页
资料共245页,剩余部分请下载后查看
Chapter 1. Introduction
What is an Assembler?
How to Develop A Program
Advantages of Modular Programming
Efficient Program Development
Multiple Use of Subprograms
Ease of Debugging and Modifying
Modular Program Development Process
Segments, Modules, and Programs
Program Entry and Exit
Assembly
Relocation and Linkage
Keeping Track of Files
Writing and Assembling Programs
Chapter 2. 8051 and MCS 251 Architecture
New Features of the MCS 251 Architecture
8051 and MCS 251 Memory Model
8051 Address Space
Program Memory
Internal Data Memory
External Memory
Memory Classes
8051 and MCS 251 Register File
Special Function Registers
Differences to the 8051
8051 Compatibility
Timing Issues
Stack Pointer (SPX)
Program Status Word
PSW Bit Definitions
Chapter 3. Writing Assembly Programs
Assembly Statements
Directives
Controls
Instructions
Comments
Symbols
Symbol Names
Labels
Operands
Special Assembler Symbols
Immediate Data
Indirect Addresses
IDATA
XDATA
CODE and CONST †
EDATA †
HDATA †
Direct Data Addresses
Direct Bit Addresses
Program Addresses
Relative Jumps
In-Block Jumps and Calls (ACALL and AJMP)
Long Jumps and Calls (LJMP and LCALL)
Extended Jumps and Calls (EJMP and ECALL)
Generic Jump and Call (JMP and CALL)
Expressions and Operators
Numbers
Characters
Character Strings
Location Counter
Operators
Arithmetic Operators
Binary Operators
Relational Operators
Class Operators
Type Operators †
Miscellaneous Operators
Operator Precedence
Expressions
Expression Classes
Relocatable Expressions
Simple Relocatable Expressions
Extended Relocatable Expressions
Chapter 4. Assembler Directives
Introduction
Segment Controls
Location Counter
Generic Segments
Stack Segment
Absolute Segments
Default Segment
SEGMENT
RSEG
BSEG, CSEG, DSEG, ISEG, XSEG
Symbol Definition
EQU, SET
CODE, DATA, IDATA, XDATA
LIT †
Memory Initialization
DB
DW
DD †
Memory Reservation
DBIT
DS
DSB †
DSW †
DSD †
Procedure Declaration †
PROC / ENDP †
LABEL †
Program Linkage
PUBLIC
EXTRN / EXTERN
NAME
Address Control
ORG
EVEN †
USING
Other Directives
END
Chapter 5. Standard Macros
Directives
Defining a Macro
Parameters
Labels
Repeating Blocks
REPT
IRP
IRPC
Nested Definitions
Nested Repeating Blocks
Recursive Macros
Operators
NUL Operator
& Operator
< and > Operators
% Operator
;; Operator
! Operator
Invoking a Macro
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
Running A251
Command Files
DOS ERRORLEVEL
Output Files
Assembler Controls
Directives for Conditional Assembly
Conditional Assembly Controls
Chapter 8. Error Messages
Fatal Errors
Fatal Error Messages
Non–Fatal Errors
Appendix A. 8051/251 Instruction Sets
MCS 251 Opcode Map
8051 Microcontroller Instructions
Appendix B. Directive Summary
Appendix F. Listing File Format
Assembler Listing File Format
Listing File Heading
Source Listing
Format for Macros, Include Files, and Save Stack
Symbol Table
Listing File Trailer
Appendix G. Program Template
Appendix H. Assembler Differences
Differences Between A51 and A251
Differences between A51 and ASM51
Differences between A251 and ASM51
Glossary
Index
A51 Assembler A251 Assembler Macro Assemblers for the 8051 and MCS® 251 Microcontrollers User’s Guide 04.95
ii Keil Software Information in this document is subject to change without notice and does not represent a commitment on the part of the manufacturer. The software described in this document is furnished under license agreement or nondisclosure agreement and may be used or copied only in accordance with the terms of the agreement. It is against the law to copy the software on any medium except as specifically allowed in the license or nondisclosure agreement. The purchaser may make one copy of the software for backup purposes. No part of this manual may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or information storage and retrieval systems, for any purpose other than for the purchaser’s personal use, without written permission. © Copyright 1988-1995 Keil Elektronik GmbH., and Keil Software, Inc. All rights reserved. Keil C51™ and dScope™ are trademarks of Keil Elektronik GmbH. Microsoft®, MS–DOS®, and Windows™ are trademarks or registered trademarks of Microsoft Corporation. IBM®, PC®, and PS/2® are registered trademarks of International Business Machines Corporation. Intel®, MCS® 51, MCS® 251, ASM–51®, and PL/M–51® are registered trademarks of Intel Corporation. Every effort was made to ensure accuracy in this manual and to give appropriate credit to persons, companies, and trademarks referenced herein. A15 D05/12/95
A51 Assembler / A251 Assembler iii Preface This manual describes how to use the A51 and A251 macro assemblers. The A51 and A251 assembler translate programs you write in assembly language into executable machine instructions. You may use the A51 assembler to assemble programs for the 8051 family of microcontrollers. You may use the A251 assembler to assemble programs for the 8051 family as well as the MCS 251 family of microcontrollers. This manual assumes that you are familiar with the MS-DOS operating system and know how to program the 8051 or MCS 251 microcontrollers. This manual is divided into the following chapters. “Chapter 1. Introduction,” describes the basics of assembly language programming. “Chapter 2. 8051 and MCS 251 Architecture,” contains an overview of the 8051 and MCS 251 hardware. “Chapter 3. Writing Assembly Programs,” describes assembler statements, operands and address descriptors, and the rules for arithmetic and logical expressions. “Chapter 4. Assembler Directives,” describes how to define segments and symbols and how to use all directives. “Chapter 5. Standard Macros,” describes the function of the standard macros and contains information for using standard macros. “Chapter 6. Macro Processing Language,” defines and describes the use of the Intel Macro Processing Language. “Chapter 7. Invocation and Controls,” describes how to invoke the assembler and how to control the assembler operation. “Chapter 8. Error Messages,” contains a list of all assembler error messages and describes their causes and how to avoid them. The Appendix includes information on the 8051 and MCS 251 instruction set, a summary of directives and controls, the differences between assembler versions, and other items of interest.
iv Preface Document Conventions This document uses the following conventions: Examples Description README.TXT Bold capital text is used for the names of executable programs, data files, source files, environment variables, and commands you enter at the MS-DOS command prompt. This text usually represents commands that you must type in literally. For example: CLS DIR BL51.EXE Courier Note that you are not required to enter these commands using all capital letters. Text in this typeface is used to represent information that displays on screen or prints at the printer. This typeface is also used within the text when discussing or describing command line items. Text in italics represents information that you must provide. For example, projectfile in a syntax string means that you must supply the actual project file name. Occasionally, italics are also used to emphasize words in the text. Elements that repeat… Ellipses (…) are used in examples to indicate an item that may be Variables Omitted code . . . !Optional Items" { opt1 | opt2 } Keys repeated. Vertical ellipses are used in source code examples to indicate that a fragment of the program is omitted. For example: void main (void) { . . . while (1); Optional arguments in command-line and option fields are indicated by double brackets. For example: C51 TEST.C PRINT !(filename)" Text contained within braces, separated by a vertical bar represents a group of items from which one must be chosen. The braces enclose all of the choices and the vertical bars separate the choices. One item in the list must be selected. Text in this sans serif typeface represents actual keys on the keyboard. For example, “Press Enter to continue.”
A51 Assembler / A251 Assembler v Contents Chapter 1. Introduction......................................................................................1 What is an Assembler?.................................................................................................. 1 How to Develop A Program ......................................................................................... 2 Advantages of Modular Programming .................................................................... 2 Efficient Program Development.............................................................................. 3 Multiple Use of Subprograms ................................................................................. 3 Ease of Debugging and Modifying.......................................................................... 3 Modular Program Development Process ...................................................................... 3 Segments, Modules, and Programs ......................................................................... 4 Program Entry and Exit........................................................................................... 4 Assembly................................................................................................................. 4 Relocation and Linkage........................................................................................... 5 Keeping Track of Files............................................................................................ 5 Writing and Assembling Programs ............................................................................... 6 Chapter 2. 8051 and MCS 251 Architecture ....................................................9 New Features of the MCS 251 Architecture ................................................................. 9 8051 and MCS 251 Memory Model ........................................................................... 10 8051 Address Space.............................................................................................. 11 Program Memory .................................................................................................. 12 Internal Data Memory ........................................................................................... 12 External Memory .................................................................................................. 12 Memory Classes .................................................................................................... 13 8051 and MCS 251 Register File................................................................................ 14 Special Function Registers .................................................................................... 16 Differences to the 8051............................................................................................... 16 8051 Compatibility ............................................................................................... 17 Timing Issues ........................................................................................................ 17 Stack Pointer (SPX) .............................................................................................. 17 Program Status Word ............................................................................................ 17 PSW Bit Definitions.............................................................................................. 18 Chapter 3. Writing Assembly Programs ........................................................19 Assembly Statements .................................................................................................. 19 Directives .............................................................................................................. 20 Controls................................................................................................................. 20 Instructions............................................................................................................ 20 Comments ................................................................................................................... 21 Symbols ...................................................................................................................... 22 Symbol Names ...................................................................................................... 22 Labels.......................................................................................................................... 23 Operands..................................................................................................................... 24 Special Assembler Symbols .................................................................................. 24
vi Contents Immediate Data .....................................................................................................25 Indirect Addresses .................................................................................................26 IDATA ..................................................................................................................26 XDATA.................................................................................................................26 CODE and CONST † ...........................................................................................26 EDATA † .............................................................................................................27 HDATA †.............................................................................................................27 Direct Data Addresses ...........................................................................................27 Direct Bit Addresses..............................................................................................28 Program Addresses................................................................................................28 Relative Jumps ......................................................................................................28 In-Block Jumps and Calls (ACALL and AJMP) ...................................................29 Long Jumps and Calls (LJMP and LCALL)..........................................................29 Extended Jumps and Calls (EJMP and ECALL) ...................................................29 Generic Jump and Call (JMP and CALL) .............................................................29 Expressions and Operators..........................................................................................30 Numbers ................................................................................................................30 Characters..............................................................................................................31 Character Strings ...................................................................................................32 Location Counter...................................................................................................32 Operators.....................................................................................................................33 Arithmetic Operators.............................................................................................33 Binary Operators ...................................................................................................34 Relational Operators..............................................................................................34 Class Operators .....................................................................................................35 Type Operators †..................................................................................................35 Miscellaneous Operators .......................................................................................36 Operator Precedence .............................................................................................37 Expressions .................................................................................................................37 Expression Classes ................................................................................................38 Relocatable Expressions........................................................................................39 Simple Relocatable Expressions............................................................................39 Extended Relocatable Expressions........................................................................40 Chapter 4. Assembler Directives .....................................................................41 Introduction.................................................................................................................41 Segment Controls ........................................................................................................42 Location Counter...................................................................................................42 Generic Segments..................................................................................................43 Stack Segment .......................................................................................................44 Absolute Segments ................................................................................................44 Default Segment ....................................................................................................45 SEGMENT............................................................................................................46 RSEG.....................................................................................................................49 BSEG, CSEG, DSEG, ISEG, XSEG.....................................................................50 Symbol Definition.......................................................................................................51
A51 Assembler / A251 Assembler vii EQU, SET ............................................................................................................. 51 CODE, DATA, IDATA, XDATA......................................................................... 52 LIT † .................................................................................................................... 54 Memory Initialization ................................................................................................. 56 DB......................................................................................................................... 56 DW........................................................................................................................ 56 DD †..................................................................................................................... 57 Memory Reservation................................................................................................... 58 DBIT ..................................................................................................................... 58 DS ......................................................................................................................... 59 DSB †................................................................................................................... 59 DSW †.................................................................................................................. 60 DSD † .................................................................................................................. 61 Procedure Declaration † ............................................................................................ 62 PROC / ENDP †................................................................................................... 62 LABEL †.............................................................................................................. 64 Program Linkage......................................................................................................... 65 PUBLIC ................................................................................................................ 65 EXTRN / EXTERN .............................................................................................. 65 NAME................................................................................................................... 66 Address Control .......................................................................................................... 67 ORG ...................................................................................................................... 67 EVEN †................................................................................................................ 68 USING .................................................................................................................. 69 Other Directives.......................................................................................................... 71 END ...................................................................................................................... 71 Chapter 5. Standard Macros............................................................................73 Directives.................................................................................................................... 74 Defining a Macro ........................................................................................................ 74 Parameters............................................................................................................. 75 Labels.................................................................................................................... 76 Repeating Blocks .................................................................................................. 77 REPT..................................................................................................................... 77 IRP ........................................................................................................................ 78 IRPC...................................................................................................................... 78 Nested Definitions................................................................................................. 79 Nested Repeating Blocks ...................................................................................... 80 Recursive Macros.................................................................................................. 80 Operators .................................................................................................................... 81 NUL Operator ....................................................................................................... 81 & Operator ............................................................................................................ 82 < and > Operators ................................................................................................. 83 % Operator............................................................................................................ 84 ;; Operator ............................................................................................................. 85 ! Operator.............................................................................................................. 85
viii Contents Invoking a Macro ........................................................................................................85 Chapter 6. Macro Processing Language .........................................................87 Overview.....................................................................................................................87 Creating and Calling MPL Macros .............................................................................87 Creating Parameterless Macros...................................................................................88 MPL Macros with Parameters.....................................................................................89 Local Symbols List......................................................................................................92 Macro Processor Language Functions ........................................................................93 Comment Function ................................................................................................93 Escape Function ....................................................................................................94 Bracket Function ...................................................................................................94 METACHAR Function .........................................................................................95 Numbers and Expressions .....................................................................................96 Numbers ................................................................................................................96 Character Strings ...................................................................................................97 SET Function.........................................................................................................98 EVAL Function .....................................................................................................99 Logical Expressions and String Comparison.........................................................99 Conditional MPL Processing ....................................................................................100 IF Function ..........................................................................................................101 WHILE Function.................................................................................................101 REPEAT Function...............................................................................................102 EXIT Function.....................................................................................................103 String Manipulation Functions..................................................................................103 LEN Function......................................................................................................104 SUBSTR Function...............................................................................................104 MATCH Function ...............................................................................................105 Console I/O Functions...............................................................................................106 Advanced Macro Processing.....................................................................................107 Literal Delimiters ................................................................................................107 Blank Delimiters..................................................................................................108 Identifier Delimiters ............................................................................................109 Literal and Normal Mode ....................................................................................109 MACRO Errors.........................................................................................................111 Chapter 7. Invocation and Controls..............................................................113 Running A251 ...........................................................................................................113 Command Files....................................................................................................114 DOS ERRORLEVEL ..........................................................................................114 Output Files .........................................................................................................114 Assembler Controls...................................................................................................115 COND / NOCOND .............................................................................................118 DATE ..................................................................................................................119 CASE †...............................................................................................................120 DEBUG...............................................................................................................121 EJECT .................................................................................................................122
分享到:
收藏