MPASM USER'S GUIDE Preface Welcome Microchip Technology is committed to providing useful and innovative solutions to your microcontroller designs. MPASM is the first Universal Assembler available for Microchip's entire product line of microcontrollers. MPASM will generate solid code with a directive language rich in potential. Feature List and Product Information MPASM provides a universal solution for developing assembly code for the PIC16C5X, PIC16CXX, PIC17CXX, and future microcontroller offerings. Notable features include: ù PIC16C5X, PIC16CXX, and PIC17CXX Instruction Set ù Command Line Interface ù Command Shell Interface ù Rich Directive Language ù Flexible Macro Language ù PICMASTER Compatibility ù MPSIM Compatibility ù MPSLED Compatibility Use of the Microchip MPASM Universal Assembler requires an IBM PC/AT or compatible computer, running MS-DOS V4.1 or greater. Migration Path Users of MPALC and ASM17 will find that much of their existing code will assemble with MPASM with little or no editing. This provides a simple migration path. Appendices C and D describe some of the simple changes you may need to implement to assemble existing code. But more importantly, because the program is universal, an application developed for the PIC16C54 can be easily translated into a program for the PIC16C71. This would simply require changing the instruction mnemonics that are not the same between the machines (assuming that register and peripheral usage were similar). The rest of the directive and macro language will be the same. MPASM was developed in conjunction with Byte Craft Limited, recognized as a world leader in microcontroller language tools. MPASM USER'S GUIDE Chapter 1. Introduction Product Definition MPASM is a DOS based PC application that provides a platform for developing assembly language code for Microchip microcontrollers including the PIC16C5X, PIC16CXX and PIC17CXX families. Generically, MPASM will refer to the entire development platform including the macro assembler and utility functions. Specifically: MPASM - refers to the macro assembler that generates relocatable object code from assembly source code. MPLINK - refers to the linker that translates relocatable objects to executable binary code at absolute memory locations. MPLIB - refers to the librarian utility that allows relocatable objects to be grouped together in one file, or library, for convenience. These libraries can be referenced via MPLINK as an object file output from MPASM. Documentation Layout The documentation is intended to describe how to use the assembler, and its environment. It also provides some basic information about specific Microchip microcontrollers and their instruction sets, but detailed discussion of these issues is deferred to the data sheets for specific microcontrollers. In particular: Chapter 1: Introduction - Introduces the user to MPASM. It describes the User's Guide layout, general conventions and terms, as well as a brief discussion of installation, and platform requirements. Chapter 2: Environment and Usage - This chapter describes the assembler's Command Line Interface (CLI), and shell interface. Also discussed here are the files used by MPASM, both input and output, including object file formats. Chapter 3: Directive Language - This chapter describes native directive language of MPASM. This language should be familiar to previous users of either Microchip or Byte Craft development system. Chapter 4: Macro Language - This chapter describes the macro language of MPASM. Macros are best learned by example; several will be offered for consideration. Chapter 5: Expression Syntax and Operation - This chapter describes the expression syntax of MPASM, including operator precedence, radix override notation, examples and discussion. Chapter 6: MPLIB - MPASM Librarian - This chapter describes the purpose, use and CLI of the librarian utility provided as part of the MPASM development environment. It will also provide examples and discussion. Chapter 7: MPLINK - MPASM Linker - This chapter describes the purpose, use and CLI of the linker utility provided with MPASM. It also describes the script language provided to specify where relocated objects should be placed in memory. This document offers the following General Reference sections: Appendix A: Object code formats, a brief overview. Appendix B: Customer Support - Provides information about accessing the Microchip Bulletin Board for the latest revisions of products, user forums and non-urgent questions about applying Microchip products. Appendix C: MPALC Conversion Guide. A short description designed to assist users of MPALC to move their code to MPASM. Appendix D: ASM17 Conversion Guide. A short description designed to assist users of ASM17 to move their code to MPASM. Appendix E: Error and Warning Messages. A list of the error messages generated by MPASM, with descriptions. Quick Reference Guide: This section provides a quick reference to the instruction set for each family of microprocessors as well as quick references to the directive and macro language, possibly for "tear-out." TABLE 1: DOCUMENTATION CONVENTIONS Character Represents -------------------------------------------------------------- Square Brackets ( [] ) Optional Arguments Angle Brackets ( <> ) Delimiters for special keys: , , or additional options. Pipe Character ( | ) Choice of mutually exclusive arguments; an OR selection. Lowercase characters Type of data Terms In order to provide a common frame of reference, the following terms are defined: PIC16/17 PIC16/17 refers to any Microchip microcontroller, including the representatives of the PIC16C5X, PIC16CXX, and PIC17CXX families. Source Code This is the file of PIC16/17 instructions and MPASM directives and macros that will be translated into executable code. This code is suitable for use by a PIC16/17 or Microchip development system product like an emulator, a simulator or a programmer. It is an ASCII file that can be created using any ASCII text editor. Assemble The act of executing the MPASM macro assembler to translate source code to relocatable object code. Mnemonics These are instructions that are translated directly into machine code. These are used to perform arithmetic and logical operations on data residing program or data memory of a PIC16/17. They also have the ability to move data in and out of registers and memory as well as conditionally branch to specified program addresses. Directives Directives provide control of the assembler's operation by telling MPASM how to treat mnemonics, data references and format the listing file. Directives make coding easier and provide custom output according to specific needs. Macro A macro consists of a sequence of assembler commands. Passing arguments to a macro allows for flexible functionality. Relocatable Object A unit of intermediate code that may not have an absolute base address in PIC16/17 memory. This base address may be assigned at link time. Linking Linking, or to link, refers to the translation of relocatable objects to machine code suitable for execution by a PIC16/17. Absolute addresses may be assigned to relocated objects at this time. Listing A listing is an ASCII text file that shows the machine code generated for each assembly instruction, MPASM directive, or macro encountered in a source file. An absolute listing file shows the collection of relocated objects, together with their absolute addresses in PIC16/17 memory (relative addresses will be shown in listings output directly from the macro assembler). PC Any IBM or compatible Personal Computer. DOS Disk Operating System that provides the basis for most applications that run on PCs. Recommended Reading This manual is intended to provide a reference to using the MPASM development environment. It is not intended to replace reference material regarding specific PIC16/17 microcontrollers. Therefore, you are urged to read the Data Sheets for the PIC16/17 specified by your application. If this is your first microcontroller application, you are encouraged to review the Microchip "Embedded Control Handbook." You will find a wealth of information about applying PIC16/17s. The application notes described within are available from the Microchip BBS (see Appendix B). All of these documents are available from your local sales office or from your Microchip Field Application Engineer (FAE). System Requirements MPASM will run on any PC/AT or compatible computer, running DOS V4.1 or greater. The distribution is provided on 3.5", double density (720k) floppy diskettes. No special display or ancillary devices are required. Warranty Registration NOTE: Upon receiving the diskette you should complete and return the Warranty Registration Card enclosed with the disk, and mail it promptly. Doing so will help to ensure that you receive product updates and notification of interim releases that become available. Installation Never use the original diskette as your working copy. Make a backup copy of the MPASM distribution disk using the DOS "DISKCOPY" program, then label the new copy and store the original in a safe place. It is recommended that you execute MPASM from your hard disk. To do this, create a new directory (MKDIR) for the assembler and copy all files from the backup distribution diskette to that directory (MPASM, and its accompanying utility programs and source examples are distributed at the root level of the distribution diskette). If you want to be able to run MPASM from any directory (without fully qualifying the path to the executable program), you must add the new directory to the DOS PATH environment variable. For information on using DISKCOPY or any DOS command, and DOS environment variables, refer to your IBM DOS User's Guide. Compatibility Issues MPASM is compatible with all Microchip development systems currently in production. This includes MPSIM (PIC16/17 software core simulator), PICMASTER, PRO MASTER (the Microchip Universal Programmer), and the Microchip low-cost development programmer. It is not compatible with certain older Microchip In-Circuit Emulators. Microchip Technology is sensitive to your investment in PIC16/17 firmware. Whenever possible, we endeavor to protect that investment and remain backward compatible as new products are developed and released. MPASM is intended to be backward compatible with source code developed with MPALC and ASM17. In order to provide the largest coverage in backward compatibility, you may encounter small discrepancies in the directive and macro syntax. Whenever practical, MPASM will attempt to make a rational decision as to your coding intent, and flag older syntax as warnings. Unfortunately, this is not always possible. Specifically, MPASM no longer supports the "." (dot) directives within the macro language. This is offset by the fact that almost all directives can be executed within or without a macro. Also, ASM17 provided a pseudo implementation of `C' preprocessor directives (those directives preceded by a "#" (pound sign)). MPASM handles these directives in context, and flags the context with warnings when appropriate. MPASM USER'S GUIDE Chapter 2. Environment and Usage Introduction MPASM provides a universal platform for developing code for PIC16/17s. The product is represented by several programs: MPASM, MPLINK, and MPLIB. Each of these programs has its own Command Line Interface; the former two can be accessed through the MPASM shell while MPLIB can only be accessed through its CLI. This chapter is dedicated to describing the MPASM CLI and the MPASM shell. Highlights The points that will be highlighted in this chapter are: ù MPASM Command Line Interface ù MPASM Shell Interface ù MPASM Input Files ù MPASM and Associated Output Files Terms Command Line Interface Command Line Interface or CLI refers to executing a program with options. In the case of MPASM, executing MPASM with any command line options or just the file name will invoke the assembler. In the absence of any command line options, a prompted input interface (shell) will be executed. Shell The MPASM shell is a prompted input interface to the macro assembler and linker. It is a DOS Text Graphics screen where the user fills in the appropriate assembly and linker options. Alpha Character Alpha characters are those characters, regardless of case, that are normally contained in the alphabet: (a, b, ..., z, A, B, ..., Z). Alpha Numeric Alpha Numeric characters include Alpha characters and numbers: ( 0, 1, ..., 9). Command Line Interface MPASM can be invoked through the CLI as follows: MPASM [/