Generated by Foxit PDF Creator © Foxit Software http://www.foxitsoftware.com For evaluation only.

MPASM™ Assembler, MPLINK™ Object Linker MPLIB™ Object Librarian User’s Guide

2009 Microchip Technology Inc.

DS33014K

Generated by Foxit PDF Creator © Foxit Software http://www.foxitsoftware.com For evaluation only.

Note the following details of the code protection feature on Microchip devices: • • Microchip products meet the specification contained in their particular Microchip Data Sheet. Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the intended manner and under normal conditions. There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data Sheets. Most likely, the person doing so is engaged in theft of intellectual property. Microchip is willing to work with the customer who is concerned about the integrity of their code. Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not mean that we are guaranteeing the product as “unbreakable.”

• •

Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our products. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.

Information contained in this publication regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer’s risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.

Trademarks The Microchip name and logo, the Microchip logo, Accuron, dsPIC, KEELOQ, KEELOQ logo, MPLAB, PIC, PICmicro, PICSTART, rfPIC, SmartShunt and UNI/O are registered trademarks of Microchip Technology Incorporated in the U.S.A. and other countries. FilterLab, Linear Active Thermistor, MXDEV, MXLAB, SEEVAL, SmartSensor and The Embedded Control Solutions Company are registered trademarks of Microchip Technology Incorporated in the U.S.A. Analog-for-the-Digital Age, Application Maestro, CodeGuard, dsPICDEM, dsPICDEM.net, dsPICworks, dsSPEAK, ECAN, ECONOMONITOR, FanSense, In-Circuit Serial Programming, ICSP, ICEPIC, Mindi, MiWi, MPASM, MPLAB Certified logo, MPLIB, MPLINK, mTouch, nanoWatt XLP, PICkit, PICDEM, PICDEM.net, PICtail, PIC32 logo, PowerCal, PowerInfo, PowerMate, PowerTool, REAL ICE, rfLAB, Select Mode, Total Endurance, TSHARC, WiperLock and ZENA are trademarks of Microchip Technology Incorporated in the U.S.A. and other countries. SQTP is a service mark of Microchip Technology Incorporated in the U.S.A. All other trademarks mentioned herein are property of their respective companies. © 2009, Microchip Technology Incorporated, Printed in the U.S.A., All Rights Reserved. Printed on recycled paper.

Microchip received ISO/TS-16949:2002 certification for its worldwide headquarters, design and wafer fabrication facilities in Chandler and Tempe, Arizona; Gresham, Oregon and design centers in California and India. The Company’s quality system processes and procedures are for its PIC® MCUs and dsPIC® DSCs, KEELOQ® code hopping devices, Serial EEPROMs, microperipherals, nonvolatile memory and analog products. In addition, Microchip’s quality system for the design and manufacture of development systems is ISO 9001:2000 certified.

DS33014K-page ii

2009 Microchip Technology Inc.

Generated by Foxit PDF Creator © Foxit Software http://www.foxitsoftware.com For evaluation only.

ASSEMBLER/LINKER/LIBRARIAN USER’S GUIDE Table of Contents
Preface ........................................................................................................................... 1 PIC1X MCU Language Tools and MPLAB IDE ............................................................ 9 Part 1 – MPASM Assembler Chapter 1. MPASM Assembler Overview
1.1 Introduction ................................................................................................... 23 1.2 MPASM Assembler Defined ......................................................................... 23 1.3 How MPASM Assembler Helps You ............................................................ 23 1.4 Assembler Migration Path ............................................................................ 23 1.5 Assembler Compatibility Issues ................................................................... 24 1.6 Assembler Operation .................................................................................... 24 1.7 Assembler Input/Output Files ....................................................................... 26

Chapter 2. Assembler Interfaces
2.1 Introduction ................................................................................................... 33 2.2 MPLAB IDE Interface ................................................................................... 33 2.3 Windows Interface ........................................................................................ 34 2.4 Command Line Interface .............................................................................. 35

Chapter 3. Expression Syntax and Operation
3.1 Introduction ................................................................................................... 37 3.2 Text Strings .................................................................................................. 37 3.3 Reserved Words and Section Names .......................................................... 39 3.4 Numeric Constants and Radix ...................................................................... 39 3.5 Arithmetic Operators and Precedence ......................................................... 40

Chapter 4. Directives
4.1 Introduction ................................................................................................... 43 4.2 Directives by Type ........................................................................................ 43 4.3 ¿½½»­­Á±ª® - Begin an Object File Overlay Section in Access RAM (PIC18 MCUs) ............................................................................... 46 4.4 ÁÁ¾¿¼®¿³ - Identify Unimplemented RAM ................................................. 46 4.5 ÁÁ¾¿¼®±³ - Identify Unimplemented ROM ................................................ 47 4.6 ¾¿²µ·­»´ - Generate Indirect Bank Selecting Code (PIC12/16 MCUs) ................................................................................... 48 4.7 ¾¿²µ­»´ - Generate Bank Selecting Code ................................................ 50 4.8 ½¾´±½µ - Define a Block of Constants ........................................................ 52 4.9 ½±¼» - Begin an Object File Code Section .................................................. 54 4.10 ½±¼»Á°¿½µ - Begin an Object File Packed Code Section (PIC18 MCUs) ........................................................................................ 55

2009 Microchip Technology Inc.

DS33014K-page iii

http://www.foxitsoftware.com Assembler/Linker/Librarian User’s Guide

Generated by Foxit PDF Creator © Foxit Software For evaluation only.

4.11 4.12 4.13 4.14 4.15 4.16 4.17 4.18 4.19 4.20 4.21 4.22 4.23 4.24 4.25 4.26 4.27 4.28 4.29 4.30 4.31 4.32 4.33 4.34 4.35 4.36 4.37 4.38 4.39 4.40 4.41 4.42 4.43 4.44 4.45 4.46 4.47 4.48 4.49 4.50 4.51 4.52 4.53

ÁÁ½±²º·¹ - Set Processor Configuration Bits ......................................... 55 ½±²º·¹ - Set Processor Configuration Bits (PIC18 MCUs) ...................... 57 ½±²­¬¿²¬ - Declare Symbol Constant .................................................... 58 ¼¿ - Store Strings in Program Memory (PIC12/16 MCUs) ......................... 59 ¼¿¬¿ - Create Numeric and Text Data ...................................................... 60 ¼¾ - Declare Data of One Byte .................................................................. 62 ¼» - Declare EEPROM Data Byte .............................................................. 64 ý¼»º·²» - Define a Text Substitution Label ............................................. 65 ¼¬ - Define Table (PIC12/16 MCUs) .......................................................... 67 ¼¬³ - Define Table (Extended PIC16 MCUs Only) .................................... 67 ¼© - Declare Data of One Word ................................................................. 68 »´­» - Begin Alternative Assembly Block to ·º Conditional .................... 68 »²¼ - End Program Block .......................................................................... 69 »²¼½ - End an Automatic Constant Block ................................................. 69 »²¼·º - End Conditional Assembly Block ................................................. 70 »²¼³ - End a Macro Definition .................................................................. 70 »²¼© - End a ©¸·´» Loop ....................................................................... 71 »¯« - Define an Assembler Constant ........................................................ 71 »®®±® - Issue an Error Message .............................................................. 72 »®®±®´»ª»´ - Set Message Level .......................................................... 73 »¨·¬³ - Exit from a Macro ........................................................................ 75 »¨°¿²¼ - Expand Macro Listing ............................................................... 77 »¨¬»®² - Declare an Externally Defined Label ......................................... 78 º·´´ - Specify Program Memory Fill Value .............................................. 80 ¹´±¾¿´ - Export a Label ........................................................................... 82 ·¼¿¬¿ - Begin an Object File Initialized Data Section .............................. 82 ·¼¿¬¿Á¿½­ - Begin an Object File Initialized Data Section
in Access RAM (PIC18 MCUs) ............................................................... 84 ÁÁ·¼´±½­ - Set Processor ID Locations .................................................. 85 ·º - Begin Conditionally Assembled Code Block ...................................... 86 ·º¼»º - Execute If Symbol has Been Defined .......................................... 88 ·º²¼»º - Execute If Symbol has not Been Defined ................................. 89 ý·²½´«¼» - Include Additional Source File .............................................. 90 ´·­¬ - Listing Options ............................................................................... 91 ´±½¿´ - Declare Local Macro Variable ..................................................... 92 ³¿½®± - Declare Macro Definition ............................................................. 94 ÁÁ³¿¨®¿³ - Define Maximum RAM Location ........................................... 95 ÁÁ³¿¨®±³ - Define Maximum ROM Location .......................................... 96 ³»­­¹ - Create User Defined Message .................................................... 96 ²±»¨°¿²¼ - Turn off Macro Expansion .................................................... 98 ²±´·­¬ - Turn off Listing Output .............................................................. 98 ±®¹ - Set Program Origin .......................................................................... 99 °¿¹» - Insert Listing Page Eject .............................................................. 101 °¿¹»­»´ - Generate Page Selecting Code (PIC10/12/16 MCUs) ......... 102

DS33014K-page iv

2009 Microchip Technology Inc.

Generated by Foxit PDF Creator © Foxit Software http://www.foxitsoftware.com For evaluation only.

Table of Contents

4.54 °¿¹»­»´© - Generate Page Selecting Code Using WREG Commands (PIC10/12/16 MCUs) ......................................................... 103 4.55 °®±½»­­±® - Set Processor Type ......................................................... 104 4.56 ®¿¼·¨ - Specify Default Radix ................................................................ 105 4.57 ®»­ - Reserve Memory ............................................................................ 106 4.58 ­»¬ - Define an Assembler Variable ........................................................ 108 4.59 ­°¿½» - Insert Blank Listing Lines .......................................................... 109 4.60 ­«¾¬·¬´» - Specify Program Subtitle .................................................... 109 4.61 ¬·¬´» - Specify Program Title ................................................................ 110 4.62 «¼¿¬¿ - Begin an Object File Uninitialized Data Section ........................ 110 4.63 «¼¿¬¿Á¿½­ - Begin an Object File Access Uninitialized Data Section (PIC18 MCUs) ......................................................................... 111 4.64 «¼¿¬¿Á±ª® - Begin an Object File Overlaid Uninitialized Data Section ......................................................................................... 113 4.65 «¼¿¬¿Á­¸® - Begin an Object File Shared Uninitialized Data Section (PIC12/16 MCUs) ................................................................................. 115 4.66 ý«²¼»º·²» - Delete a Substitution Label .............................................. 116 4.67 ª¿®·¿¾´» - Declare Symbol Variable .................................................... 117 4.68 ©¸·´» - Perform Loop While Condition is True ...................................... 118

Chapter 5. Assembler Examples, Tips and Tricks
5.1 Introduction ................................................................................................. 121 5.2 Example of Displaying Count on Ports ....................................................... 122 5.3 Example of Port B Toggle and Delay Routines .......................................... 123 5.4 Example of Calculations with Variables and Constants ............................. 130 5.5 Example of a 32-Bit Delay Routine ............................................................ 132 5.6 Example of SPI Emulated in Firmware ....................................................... 134 5.7 Example of Hexadecimal to ASCII Conversion .......................................... 136 5.8 Other Sources of Examples ....................................................................... 137 5.9 Tips and Tricks ........................................................................................... 137

Chapter 6. Relocatable Objects
6.1 Introduction ................................................................................................. 141 6.2 Header Files ............................................................................................... 141 6.3 Program Memory ........................................................................................ 142 6.4 Low, High and Upper Operators ................................................................. 142 6.5 RAM Allocation ........................................................................................... 145 6.6 Configuration Bits and ID Locations ........................................................... 146 6.7 Accessing Labels From Other Modules ..................................................... 146 6.8 Paging and Banking Issues ........................................................................ 147 6.9 Generating the Object Module ................................................................... 148 6.10 Code Example .......................................................................................... 148

2009 Microchip Technology Inc.

DS33014K-page v

................................... 179 10......... 171 9.......................................................................................................................................................................................1 Introduction ............................4 How MPLINK Linker Helps You .......... 152 7................. 186 11...........................................................................1 Introduction ..............................5 Linker Platforms Supported ...1 Introduction .....................2 Standard Linker Scripts .................... 171 9............... 183 11...3 Command Line Interface ................................2 MPLINK Linker Defined .......................................6 Logical Section Definition ......................... 172 9........................... Linker Interfaces 10............... 171 9..........................................4 Linker Script Caveats ......... 180 Chapter 11...................................... Macro Language 7...................5 Memory Region Definition ............... Chapter 7......................3 Assembler Warnings ............ 183 11........................................................................3 Linker Script Command Line Information ........................................ 165 8. 151 7.......... 179 10.............. 155 8............ 181 11............................foxitsoftware..... 152 7................. ...............3 Macro Directives Defined .............. 181 11............................................................................. 179 10.....................4 Command Line Example ............................. MPLINK Linker Overview 9.........2 Macro Syntax ....................................7 Linker Input/Output Files ........................................ 155 8................................ 151 7.. 167 Part 2 – MPLINK Object Linker Chapter 9................ 172 9.......5 Assembler Limitations ................. 162 8.....................................................................................................................................................................................3 How MPLINK Linker Works ................... 153 Chapter 8......................................http://www.......................................................................................................................................................................................................1 Introduction .2 Assembler Errors ....2 MPLAB IDE Interface ............................. Warnings..................................5 Macro Invocation ......6 Linker Operation .................................. Messages...1 Introduction .................................................................. 172 9.............4 Assembler Messages ...... 182 11...............................4 Macro Definition ..................6 Macro Code Examples .................................... 173 Chapter 10.......................................... Linker Scripts 11..................... 187 DS33014K-page vi 2009 Microchip Technology Inc..............7 STACK Definition ....................................................... and Limitations 8...... Errors.................................................................................................................................................................................. 186 11.............................................................................. 152 7..................................................................................8 Conditional Linker Statements ..com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only...

................. 239 16..2 What is MPLIB Librarian .......................................1 Introduction ................1 Introduction .............................................................................. 194 12.......................................................................................... 240 Chapter 17....... 192 12............................3 Linker Allocation Algorithm ............... 231 14.............................. Sample Applications 13........ 191 12...........4 Relocation Example ........................2 MPLAB IDE Interface ............ Errors.............................................................................. Table of Contents Chapter 12............................................ 236 15.................................................... 217 Chapter 14........................ 241 17.................. 237 Chapter 16... 235 15.................. 195 13.....1 Introduction ...........................................6 Other Errors......................4 Sample Application 2 – Placing Code and Setting Config Bits .................. 235 15...3 Library File Errors ...............................4 COFF File Errors ...............................7 Common Problems ...........foxitsoftware...... 236 15................... Linker Processing 12.....2 Linker Parse Errors .......... 194 Chapter 13........................................................................6 Reserved Section Names .................................................3 Linker Errors ................... 240 16..................................... 242 2009 Microchip Technology Inc.......................................................................... Errors 17................................................................................. Warnings and Common Problems 14..........3 Sample Application 1 ...................................... 225 14..................Templates and Linker Scripts ........... 223 14..............................2 Librarian Parse Errors ......................com For evaluation only..............5 Initialized Data .................................................................................. 230 14..............................5 Sample Application 3 – Using a Boot Loader ................................................................... Warnings and Messages ...4 Linker Warnings ........................................................................................................... MPLIB Librarian Overview 15.................5 COFF File Errors ............................................................. 206 13..........Generated by Foxit PDF Creator © Foxit Software http://www......................... 191 12... Librarian Interfaces 16.............. 230 14........................................................................................................................................1 Introduction ............ 241 17..............4 Command Line Examples and Tips ...........................................................1 Introduction . 223 14.......................................4 How MPLIB Librarian Helps You ... DS33014K-page vii ......3 How MPLIB Librarian Works .....................................1 Introduction . 241 17.. 200 13............................. 203 13........................ 231 Part 3 – MPLIB Object Librarian Chapter 15. 193 12........................2 Linker Processing Overview ..........................2 How to Build the Sample Applications ...... 195 13.............................................................................................. 235 15................... 239 16..............................................................................................................................6 Sample Application 4 – Configuring External Memory .....................6 Librarian Input/Output Files ..............................................5 Librarian Operation ........................3 Command Line Options ..............

................................................................... 267 B..........4 14-Bit Instruction Width Instruction Set ....................269 Index ......................4 mp2hex............com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only...............................................................................1 Introduction ............................... 251 A.... 247 19..................... 245 18........................................6 12-Bit/14-Bit Instruction Width Pseudo-Instructions ........ Errors and Warnings 19.................................... 247 19.............http://www.... 251 A.....................2 ASCII Character Set ... 268 Glossary ..................8 PIC18 Device Instruction Set ............. 256 A........................ 246 18............... 247 19...3 Utilities Operation ..9 PIC18 Device Extended Instruction Set ..............3 COFF To COD Conversion Errors ................................................................................... 248 Part 5 – Appendices Appendix A..................................... 261 A....................................... ...................... 245 18...........2 Key to 12/14-Bit Instruction Width Instruction Sets ..........4 COFF To COD Converter Warnings ............................................................................................ 267 B...........2 Hex File Errors ....... Useful Tables B................. Part 4 – Utilities Chapter 18...................................................................................................exe Utility ......................................................................................... Utilities Overview and Usage 18.................7 Key to PIC18 Device Instruction Set .........................exe Utility ........ 246 Chapter 19...............3 Hexadecimal to Decimal Conversion ...............................1 Introduction ............ 253 A............foxitsoftware.....................................1 Introduction ................................................................................... 260 A.....5 COD File Errors ...........1 Introduction .............................................................................288 DS33014K-page viii 2009 Microchip Technology Inc............................3 12-Bit Instruction Width Instruction Set ................... 254 A........................5 14-Bit Instruction Width Extended Instruction Set ......................283 Worldwide Sales and Service ................................................................ 259 A........................................... 247 19............................................................ 245 18................................................................................................................................................... Instruction Sets A..............................................2 What are Utilities ...................................5 mp2cod........................................ 265 Appendix B..............................................

2009 Microchip Technology Inc. DS33014K-page 1 .com) to obtain the latest documentation available. and this manual is no exception. This is how most developers will use these tools.com For evaluation only. For a detailed discussion about basic MPLAB IDE functions. All of these tools can work within the MPLAB® Integrated Development Environment (IDE). and then Topics to open a list of available on-line help files. refer to MPLAB IDE documentation. Items discussed include: • • • • • • Document Layout Conventions Used Recommended Reading The Microchip Web Site Development Systems Customer Change Notification Service Customer Support DOCUMENT LAYOUT This document describes how to use the MPASM™ assembler. the MPLINK™ object linker. so some actual dialogs and/or tool descriptions may differ from those in this document.microchip.Generated by Foxit PDF Creator © Foxit Software http://www. where “XXXXX” is the document number and “A” is the revision level of the document.foxitsoftware. For the most up-to-date information on development tools. in front of the page number. Documents are identified with a “DS” number. PIC1X MCU Language Tools Overview – provides an overview of how to use all of the tools in this manual together under the MPLAB IDE. see the MPLAB® IDE on-line help. ASSEMBLER/LINKER/LIBRARIAN USER’S GUIDE Preface NOTICE TO CUSTOMERS All documentation becomes dated. The numbering convention for the DS number is “DSXXXXXA”. Select the Help menu. and the MPLIB™ object librarian to develop code for PIC® microcontroller (MCU) applications. Microchip tools and documentation are constantly evolving to meet customer needs. INTRODUCTION This chapter contains general information that will be useful to know before using Assembler/Linker/Librarian User’s Guide. This number is located on the bottom of each page. Please refer to our web site (www.

“Directives” – lists each MPASM assembler directive alphabetically and describes the directive in detail. . “Linker Processing” – describes how the linker processes files. . . • Chapter 6.Sample Application 2 – explains how to place program code in different memory regions. how to declare external memory through #pragma code directive. gives an overview of operation and discusses input/output files. Warnings. Warnings and Common Problems” – contains a descriptive list of the errors and warnings generated by the MPLINK linker. warnings. “Linker Interfaces” – reviews how to use the MPLINK linker with MPLAB IDE and describes how to use the linker on the command line. • Chapter 4. what it does and how it works with other tools. • Chapter 2. Part 2 – “MPLINK Object Linker” • Chapter 9.http://www. Also. • Chapter 7. • Chapter 1. “Relocatable Objects” – describes how to use the MPASM assembler in conjunction with MPLINK object linker. • Chapter 5. • Chapter 14. as well as common problems and tool limitations. “Macro Language” – describes how to use the MPASM assembler’s built-in macro processor.com Assembler/Linker/Librarian User’s Guide Part 1 – “MPASM Assembler” Generated by Foxit PDF Creator © Foxit Software For evaluation only. • Chapter 13. . • Chapter 3. • Chapter 11.Sample Application 4 – explains how to create new linker script memory section. “Expression Syntax and Operation” – provides guidelines for using complex expressions in MPASM assembler source files.Sample Application 1 – explains how to find and use template files and when to modify the generic linker script file.Sample Application 3 – explains how to partition memory for a boot loader and how to compile code that will be loaded into external RAM and executed. what it does and how it works with other tools. Messages. “Errors.foxitsoftware. as well as tool limitations. and Limitations” – contains a descriptive list of the errors. and how to access external memories using C pointers. DS33014K-page 2 2009 Microchip Technology Inc. “Assembler Interfaces” – reviews how to use the MPASM assembler with MPLAB IDE and describes how to use the assembler on the command line or in a Windows shell interface. “Errors. “Sample Applications” – provides examples of how to use the linker to create applications. how to place data tables in ROM memory and how to set configuration bits in C. • Chapter 12. with examples. • Chapter 10. and messages generated by the MPASM assembler. • Chapter 8. Tips and Tricks” – provides examples of how to use the MPASM assembler directives together in applications. . “MPLINK Linker Overview” – describes what the MPLINK object linker is. Also. “Assembler Examples. “Linker Scripts” – discusses how to generate and use linker scripts to control linker operation. “MPASM Assembler Overview” – describes what the MPASM assembler is. gives an overview of operation and discusses input/output files.

ASCII Character Set – lists the ASCII Character Set. Also. . “Utilities Overview and Usage” – lists the available utilities and describes their usage. Preface Part 3 – “MPLIB Object Librarian” • Chapter 15.Hexadecimal to Decimal Conversions – shows how to convert from hexadecimal to decimal numbers. • Chapter 19.com For evaluation only. • Appendix B. DS33014K-page 3 . “Errors” – contains a descriptive list of the errors generated by the MPLIB librarian. what it does and how it works with other tools. “Instruction Sets” – lists PIC MCU device instruction sets. “Librarian Interfaces” – reviews how to use the MPLIB librarian with MPLAB IDE and describes how to use the librarian on the command line. “MPLIB Librarian Overview” – describes what the MPLIB object librarian is. Part 4 – “Utilities” • Chapter 18.Generated by Foxit PDF Creator © Foxit Software http://www. 2009 Microchip Technology Inc. “Useful Tables” – provides some useful tables for code development. gives an overview of operation and discusses input/output files. Part 5 – “Appendices” • Appendix A. . “Errors and Warnings” – contains a descriptive list of the errors generated by the utilities. • Chapter 17. • Chapter 16.foxitsoftware.

com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only.. <F1> Represents Examples DS33014K-page 4 2009 Microchip Technology Inc. CONVENTIONS USED The following conventions may appear in this documentation: DOCUMENTATION CONVENTIONS Description Arial font: Italic characters Initial caps Referenced books Emphasized text A window A dialog A menu selection Quotes Underlined.. . the Output window the Settings dialog select Enable Programmer “Save project before build” File>Save Click OK Click the Power tab Press <Enter>... italic text with right angle bracket Bold characters Text in angle brackets < > Courier font: Plain Courier Sample source code Filenames File paths Keywords Command-line options Bit values Constants Italic Courier Square brackets [ ] Curly brackets and pipe character: { | } Ellipses. where º·´» can be any valid filename ³°¿­³©·² ű°¬·±²­Ã º·´» ű°¬·±²­Ã »®®±®´»ª»´ ¥ð¤ï£ ª¿®Á²¿³» Åô ª¿®Á²¿³»òòòà ª±·¼ ³¿·² øª±·¼÷ ¥ òòò £ A field name in a window or dialog A menu path A dialog button A tab A key on the keyboard MPLAB IDE User’s Guide .. an OR selection Replaces repeated text Represents code supplied by user ý¼»º·²» ÍÌßÎÌ ¿«¬±»¨»½ò¾¿¬ ½æij½½ïèĸ Á¿­³ô Á»²¼¿­³ô ­¬¿¬·½ óÑ°¿õô óÑ°¿ó ðô ï ð¨ÚÚô ŽßŽ º·´»ò±. A variable argument Optional arguments Choice of mutually exclusive arguments.http://www.is the only compiler..foxitsoftware.

readme. 2009 Microchip Technology Inc. Applications notes demonstrate how various PIC MCU’s may be used.com For evaluation only.foxitsoftware. Preface RECOMMENDED READING This documentation describes how to use Assembler/Linker/Librarian User’s Guide. debug output format (COFF) information is also available in help. DS33014K-page 5 .lkr For the latest tool information and known issues. C Compiler User’s Guides and Libraries The MPLINK linker and MPLIB librarian also work with the MPLAB C Compiler for PIC18 MCUs (formerly MPLAB C18). On-line Help Files Comprehensive help files are available for MPASM assembler and MPLINK object linker/MPLIB object librarian.Generated by Foxit PDF Creator © Foxit Software http://www. Other useful documents are listed below. For more information on the compiler. see: • MPLAB® C Compiler for PIC18 MCUs Getting Started (DS51295) • MPLAB® C Compiler for PIC18 MCUs User's Guide (DS51288) • MPLAB® C Compiler for PIC18 MCUs Libraries (DS51297) MPLAB IDE Documentation Information on the integrated development environment MPLAB IDE may be found in: • MPLAB® IDE User’s Guide (DS51519) – Comprehensive user’s guide • On-line help file – The most up-to-date information on MPLAB IDE PIC MCU Data Sheets and Application Notes Data sheets contain information on device operation. In addition. as well as electrical specifications. The following Microchip documents are available and recommended as supplemental reference resources. Readme Files . see the MPASM assembler readme file (λ¿¼³» º±® ÓÐßÍÓ ß­­»³¾´»®ò¸¬³) or the MPLINK object linker/MPLIB object librarian readme file (λ¿¼³» º±® ÓÐÔ×ÒÕ Ô·²µ»®ò¸¬³).asm and readme. Find both of these types of documents for your device on the Microchip website. These ASCII text files may be found in the Readme folder of the MPLAB IDE installation directory.

MPLINK™ and MPLAB LINK30 object linkers. Accessible by using your favorite Internet browser.com. updates. application notes and sample programs. online discussion groups. listings of Microchip sales offices.foxitsoftware. DS33014K-page 6 2009 Microchip Technology Inc. listing of seminars and events. MPLAB IDE Project Manager. design resources. technical support requests.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. the web site contains the following information: • Product Support – Data sheets and errata. MPLAB ICD 2. To register. as well as general editing and debugging features. access the Microchip web site at www. user’s guides and hardware support documents. • Programmers – The latest information on Microchip programmers. Microchip consultant program member listing • Business of Microchip – Product selector and ordering guides. and MPLIB™ and MPLAB LIB30 object librarians. revisions or errata related to a specified product family or development tool of interest.http://www. These include the MPLAB C18 and MPLAB C30 C compilers. Subscribers will receive e-mail notification whenever there are changes. The Development Systems product group categories are: • Compilers – The latest information on Microchip C compilers and other language tools. latest software releases and archived software • General Technical Support – Frequently Asked Questions (FAQs). .microchip. • Emulators – The latest information on Microchip in-circuit emulators. latest Microchip press releases. MPLAB Editor and MPLAB SIM simulator.microchip. • In-Circuit Debuggers – The latest information on the Microchip in-circuit debugger. THE MICROCHIP WEB SITE Microchip provides online support via our web site at www. distributors and factory representatives DEVELOPMENT SYSTEMS CUSTOMER CHANGE NOTIFICATION SERVICE Microchip’s customer notification service helps keep customers current on Microchip products. the Windows® Integrated Development Environment for development systems tools. click on Customer Change Notification and follow the registration instructions. MPASM™ and MPLAB ASM30 assemblers.This includes the MPLAB ICE 2000 and MPLAB ICE 4000. This web site is used as a means to make files and information easily available to customers. These include the MPLAB PM3 and PRO MATE II device programmers and the PICSTART® Plus and PICkit™ 1 development programmers. This list is focused on the MPLAB IDE. • MPLAB® IDE – The latest information on Microchip MPLAB IDE.com.

A listing of sales offices and locations is included in the back of this document.com 2009 Microchip Technology Inc. representative or field application engineer (FAE) for support. Local sales offices are also available to help customers. DS33014K-page 7 .foxitsoftware.Generated by Foxit PDF Creator © Foxit Software http://www. Technical support is available through the web site at: http://support.com For evaluation only. Preface CUSTOMER SUPPORT Users of Microchip products can receive assistance through several channels: • • • • Distributor or Representative Local Sales Office Field Application Engineer (FAE) Technical Support Customers should contact their distributor.microchip.

http://www. . DS33014K-page 8 2009 Microchip Technology Inc.foxitsoftware.com Assembler/Linker/Librarian User’s Guide NOTES: Generated by Foxit PDF Creator © Foxit Software For evaluation only.

Generated by Foxit PDF Creator © Foxit Software http://www.foxitsoftware.com For evaluation only.

ASSEMBLER/LINKER/LIBRARIAN USER’S GUIDE PIC1X MCU Language Tools and MPLAB IDE
INTRODUCTION
The MPASM assembler, the MPLINK object linker and the MPLIB object librarian are typically used together under MPLAB IDE to provide GUI development of application code for PIC1X MCU devices (PIC10/12/16/18 MCUs). The operation of these 8-bit language tools with MPLAB IDE is discussed here. Topics covered in this chapter: • • • • • MPLAB IDE and Tools Installation MPLAB IDE Setup MPLAB IDE Projects Project Setup Project Example

MPLAB IDE AND TOOLS INSTALLATION
In order to use the PIC® MCU language tools with MPLAB IDE, you must first install MPLAB IDE. The latest version of this free software is available at our website (http://www.microchip.com) or from any sales office (back cover). When you install MPLAB IDE, you will be installing the MPASM assembler, the MPLINK object linker and the MPLIB object librarian as well. The language tools will be installed, by default, in the directory: • ÝæÄЮ±¹®¿³ Ú·´»­ÄÓ·½®±½¸·°ÄÓÐßÍÓ Í«·¬» The executables for each tool will be: • • • • MPASM Assembler - ³°¿­³©·²ò»¨» MPLINK Object Linker - ³°´·²µò»¨» MPLIB Object Librarian - ³°´·¾ò»¨» Other Utilities

All device include (header) files are also in this directory. For more on these files, see MPASM assembler documentation. All device linker script files are in the ÔÕÎ subdirectory. For more on these files, see MPLINK object linker documentation. Code examples and template files are also included in subdirectories for your use. Template files are provided for absolute code (ݱ¼») and relocatable code (Ѿ¶»½¬) development.

2009 Microchip Technology Inc.

DS33014K-page 9

http://www.foxitsoftware.com Assembler/Linker/Librarian User’s Guide

Generated by Foxit PDF Creator © Foxit Software For evaluation only.

MPLAB IDE SETUP
Once MPLAB IDE is installed on your PC, check the settings below to ensure that the language tools are properly recognized under MPLAB IDE. 1. From the MPLAB IDE menu bar, select Project>Set Language Tool Locations to open a dialog to set/check language tool executable location. FIGURE 1: SET LANGUAGE TOOL LOCATIONS

2. In the dialog, under “Registered Tools”, select “Microchip MPASM Toolsuite”. Click the “+” to expand. 3. Select “Executables”. Click the “+” to expand. 4. Select “MPASM Assembler (³°¿­³©·²ò»¨»)”. Under “Location”, a path to the executable file should be displayed. If no path is displayed, enter one or browse to the location of this file. The default location is listed in “MPLAB IDE and Tools Installation”. 5. Select “MPLINK Object Linker (³°´·²µò»¨»)”. Under “Location”, a path to the executable file should be displayed. If no path is displayed, enter one or browse to the location of this file. The default location is listed in “MPLAB IDE and Tools Installation”. 6. Select “MPLIB Object Librarian (³°´·¾ò»¨»)”. Under “Location”, a path to the executable file should be displayed. If no path is displayed, enter one or browse to the location of this file. The default location is listed in “MPLAB IDE and Tools Installation”. 7. Click OK.

DS33014K-page 10

2009 Microchip Technology Inc.

http://www.foxitsoftware.com PIC1X MCU Language Tools andFor evaluation only. MPLAB IDE

Generated by Foxit PDF Creator © Foxit Software

MPLAB IDE PROJECTS
A project in MPLAB IDE is a group of files needed to build an application, along with their associations to various build tools. Below is a generic MPLAB IDE project. FIGURE 2: PROJECT RELATIONSHIPS

MPLAB® IDE Project
°®±¹ò¿­³ ³¿·²ò½

Source files ASSEMBLER/ COMPILER

MPASM™ assembler

MPLAB C18

°®±¹ò´­¬

°®±¹ò±

³¿·²ò±

°®»½±³°ò±

List and object files

LIBRARIAN and library file

³¿¬¸ò´·¾

¼»ª·½»ò´µ®

LINKER and linker script file*

°®±¹ò½±º

°®±¹ò³¿°

LINKER output files

Utility and output file
°®±¹ò¸»¨

SIMULATORS EMULATORS DEBUGGERS PROGRAMMERS

2009 Microchip Technology Inc.

DS33014K-page 11

http://www.foxitsoftware.com Assembler/Linker/Librarian User’s Guide

Generated by Foxit PDF Creator © Foxit Software For evaluation only.

In this MPLAB IDE project, an assembly source file (°®±¹ò¿­³) is shown with its associated assembler (MPASM assembler). MPLAB IDE will use this information to generate the object file °®±¹ò± for input into the MPLINK object linker. For more information on the assembler, see the MPASM assembler documentation. The C source file ³¿·²ò½ is also shown with its associated MPLAB C18 C compiler. MPLAB IDE will use this information to generate an object file (³¿·²ò±) for input into the MPLINK object linker. For more information on the compiler, see the MPLAB C18 C compiler documentation listed in Recommended Reading. In addition, precompiled object files (°®»½±³°ò±) may be included in a project, with no associated tool required. MPLAB C18 requires the inclusion of a precompiled standard code module ½ðïè·ò±, for example. For more information on available Microchip precompiled object files, see the MPLAB C18 C compiler documentation. Some library files (³¿¬¸ò´·¾) are available with the compiler. Others may be built using the librarian tool (MPLIB object librarian). For more information on the librarian, see the MPLIB librarian documentation. For more information on available Microchip libraries, see the MPLAB C18 C compiler documentation. The object files, along with library files, are used to generate the project output files via the linker (MPLINK object linker). Depending on your project, you may or may not need to add a linker script file (¼»ª·½»ò´µ®). For more information on using linker script files and the linker, see the MPLINK linker documentation. The main output file generated by the MPLINK linker is the COF file (°®±¹ò½±º). The linker then uses the utility MP2HEX to generate the Hex file (°®±¹ò¸»¨), used by simulators, emulators, debuggers and programmers. For more information on linker output files, see the MPLINK linker documentation. For more information on utilities, see the related documentation. For more on projects, and related workspaces, see MPLAB IDE documentation.

DS33014K-page 12

2009 Microchip Technology Inc.

http://www.foxitsoftware.com PIC1X MCU Language Tools andFor evaluation only. MPLAB IDE

Generated by Foxit PDF Creator © Foxit Software

PROJECT SETUP
To set up an MPLAB IDE project for the first time, it is advisable to use the built-in Project Wizard (Project>Project Wizard.) In this wizard, you will be able to select a language toolsuite that uses MPASM assembler, e.g., the Microchip MPASM Toolsuite. For more on the wizard, and MPLAB IDE projects, see MPLAB IDE documentation. Once you have a project set up, you may then set up properties of the tools in MPLAB IDE. 1. From the MPLAB IDE menu bar, select Project>Build Options>Project to open a dialog to set/check project build options. Note: MPASM assembler does not recognize include path information specified in MPLAB IDE.

2. Click on the tool tab to modify tool settings. - Build Options Dialog, MPASM Assembler Tab - Build Options Dialog, MPLAB C17 Tab (If Installed) - Build Options Dialog, MPLAB C18 Tab (If Installed) - Build Options Dialog, MPLINK Linker Tab - Build Options Dialog, MPASM/C17/C18 Suite Tab

Build Options Dialog, MPASM Assembler Tab
Select a category, and then set up assembler options. For additional options, see MPASM assembler documentation, Chapter 2. “Assembler Interfaces”. General Category
Generate Command Line Disable case sensitivity The assembler will not distinguish between upper- and lower-case letters. Note: Disabling case sensitivity will make all labels uppercase. Enable PIC18F extended instruction support. Set the default radix, either Hexadecimal, Decimal or Octal. Add macro directive definitions. Restore tab default settings. Enter options in a command-line (non-GUI) format.

Extended mode Default Radix Macro Definitions Restore Defaults Use Alternate Settings Text Box

Output Category
Generate Command Line Diagnostics level Select to display errors only; errors and warnings; or errors, warnings and messages. These will be shown in the Output window. Create an cross-reference file. A cross-reference file contains a

Generate cross-reference file Hex file format (for single-file assemblies)

listing of all symbols used in the assembly code.
When assembling a single file, the assembler may be used to generate a hex file. Choose the format here. When assembling multiple files, the assembler generates object files which must be linked with the linker to generate a hex file. Choose the hex file format for the linker in this case. Restore tab default settings. Enter options in a command-line (non-GUI) format.

Restore Defaults Use Alternate Settings Text Box

2009 Microchip Technology Inc.

DS33014K-page 13

com) for details. A subset of command-line options may be specified in MPLAB IDE in the Build Options dialog. Add macro directive definitions.microchip. Level 0 – None. These will be shown in the Output window. near ram – data memory 256 near rom – program memory 8K. MPLAB C17 Tab (If Installed) Although the MPLAB C17 C compiler works with MPLAB IDE. warnings and messages. This compiler supports PIC17C MCU devices. DS33014K-page 14 2009 Microchip Technology Inc. For additional options. it must be acquired separately. Build Options Dialog. See the Microchip website (www. Default storage class Macro Definitions Restore Defaults Use Alternate Settings Text Box Memory Model Category Generate Command Line Small Medium Compact Large Restore Defaults Use Alternate Settings Text Box Enter options in a command-line (non-GUI) format. Level 2 – Equivalent to óѲî. Enter options in a command-line (non-GUI) format.foxitsoftware. errors and warnings. or errors. Level 1 – Equivalent to óѲï. Consider migrating to PIC18X MCU devices. near ram – data memory 256 far rom – program memory > 8K.Select the level of bank selection optimization. Restore tab default settings. MPLAB C17 tab. Other Optimizations Restore Defaults Use Alternate Settings Text Box Enter options in a command-line (non-GUI) format. see the MPLAB C17 C Compiler User’s Guide (DS51290). and then set up compiler options. . Restore tab default settings. near rom – program memory 8K. Select a category.http://www. either ANSI-standard auto or static. far ram – data memory > 256 Restore tab default settings. also available on the Microchip website. Select individual optimizations.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. far ram – data memory > 256 far rom – program memory > 8K. Optimization Category Generate Command Line Bank Selection Optimiza. General Category Generate Command Line Diagnostics level Select to display errors only. Removes MOVLB tion instruction in instances where it can be determined that the Bank Select register already contains the correct value. Note: PIC17C MCUs are end-of-life devices. Select the storage class.

For “Enable All” and “Custom” optimizations. warnings and messages. Enable optimizations for debugging.foxitsoftware. Enable all optimizations. Enable PIC18F extended instruction support. Optimization Category Generate Command Line Disable Debug Enable All Custom Procedural Abstraction passes Restore Defaults Use Alternate Settings Text Box Enter options in a command-line (non-GUI) format. Restore tab default settings. See the Microchip website (www.microchip. Choose from large (all RAM banks) or small (access RAM only). Select a data (data memory/RAM) model. This compiler supports PIC18X MCU devices. MPLAB C18 tab. set the desired number of passes for procedural abstraction. see the MPLAB C18 C Compiler User’s Guide (DS51288). Select a stack model. Select the storage class.com PIC1X MCU Language Tools andFor evaluation only. Select a category. Select to make ‘char’ types unsigned (0-256) instead of the default signed (-128 to 127). For additional options. Choose from single bank or multiple bank. A subset of command-line options may be specified in MPLAB IDE in the Build Options dialog. Default storage class Enable integer promotions Treat ‘char’ as unsigned Extended mode Macro Definitions Restore Defaults Use Alternate Settings Text Box Memory Model Category Generate Command Line Code Model Data Model Stack Model Restore Defaults Use Alternate Settings Text Box Enter options in a command-line (non-GUI) format. 2009 Microchip Technology Inc. it must be acquired separately. MPLAB IDE Generated by Foxit PDF Creator © Foxit Software Build Options Dialog. Restore tab default settings. Add macro directive definitions. Enter options in a command-line (non-GUI) format. or errors. General Category Generate Command Line Diagnostics level Select to display errors only. Enable optimization and select individual optimizations. MPLAB C18 Tab (If Installed) Although the MPLAB C18 C compiler works with MPLAB IDE.com) for details.http://www. static (ANSI standard) or overlay (non-extended mode). Disable optimization. Choose from small ( 64K bytes) or large (>64K bytes). The full version may be purchased. also available on the Microchip website. Select to enable integer promotions (ISO-mandated arithmetic performed at ·²¬ precision or greater). These will be shown in the Output window. Restore tab default settings. or a student (limited-feature) version may be downloaded for free. either auto (ANSI standard). DS33014K-page 15 . errors and warnings. and then set up compiler options. Select a code (program memory/ROM) model.

Build library target (invoke MPLIB) DS33014K-page 16 2009 Microchip Technology Inc.) To set linker options. A map file provides information on the absolute location of source code symbols in the final output. etc. a generic device-family library (for the selected device) may be built. Enter a root directory for saving output files.. Build Options Dialog. MPLINK Linker Tab Select a category. Output file root Restore Defaults Use Alternate Settings Text Box Build Options Dialog.g. For additional options. and then set up linker options.) For a library build. MPLINK Linker Tab. “Linker Interfaces”. Chapter 16. All Options Category Generate Command Line Build normal target (invoke MPLINK) The files in the project will be built for normal output using the MPLINK linker (hex file. All Options Category Generate Command Line Hex file format Generate map file Choose the linker hex file format or suppress output of the hex file.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. for the selected device PIC18F8720. Chapter 10. see Build Options Dialog. For more on libraries. Restore tab default settings. see MPLIB object librarian documentation. “Librarian Interfaces”. Enter options in a command-line (non-GUI) format. The files in the project will be built into a library using the MPLIB librarian (lib file. see MPLINK object linker documentation. indicating used/unused memory. Create a map file. the generic device-family library would be PIC18. . MPASM/C17/C18 Suite Tab Select a category. It also provides information on memory use.http://www.foxitsoftware. e. and then set up output build options.

select Project>Project Wizard to launch the wizard. find the following directory: ÝæÄЮ±¹®¿³ Ú·´»­ÄÓ·½®±½¸·°ÄÓÐßÍÓ Í«·¬»ÄÛÈßÓÐÔÛ Select Û¨¿³°´»ò¿­³ and Û¨¿³°´»îò¿­³. the project name is Û¨¿³°´»ò³½°. Click Finish to complete the project creation and setup. 1. MPLAB IDE Generated by Foxit PDF Creator © Foxit Software PROJECT EXAMPLE In this example. 5. Enter “Example” for the name of the project. Then Browse to select a location for your project. Click Next> to continue. see MPLAB IDE documentation.foxitsoftware. FIGURE 3: EXAMPLE PROJECT TREE 2009 Microchip Technology Inc. Click Next> to continue. If anything is in error. 3. Refer to “MPLAB IDE Setup”. use <Back to go back and correct the entry. Review the summary of information. Set up the language tools. In the file listing box on the left of the dialog. Click Next> to continue. if you haven’t already. Therefore. Click Next> at the Welcome screen. The workspace name is Û¨¿³°´»ò³½©. For more on workspaces and projects. Add files to the project. you will create an MPLAB IDE project with multiple assembly files. Click Add>> to add these files to the project. DS33014K-page 17 . Select PIC16F84A as the Device. 2. Click Next> to continue. you will need to use the MPASM assembler and the MPLINK linker to create the final output executable (ò¸»¨) file. • • • • • • Run the Project Wizard Set Build Options Build the Project Build Errors Output Files Further Development Run the Project Wizard In MPLAB IDE. and all the project files are listed under their respective file type.com PIC1X MCU Language Tools andFor evaluation only. the Project window should contain the project tree. Once the Project Wizard has completed.http://www. 4.

Click on the MPLINK Linker tab. Review the previous steps in this example. examine the Build tab of the Output window for syntax errors in the source code. Build the Project Select Project>Build All to build the project. Click OK on the bottom of the dialog to accept the build options and close the dialog. FIGURE 4: OUTPUT WINDOW – BUILD TAB Build Errors If the build did not complete successfully. check these items: 1. Click on the MPASM Assembler tab. check that the “Build normal target (invoke MPLINK)” is selected. For “Categories: (All Options)”. in the project tree and select “Build All” from the pop-up menu. check that the “Hex File Format” is set to “INHX32”. For “Categories: Output”. . Correct the error. Note: You also may right-click on the project name. “Example. Then check the checkbox for “Generate cross-reference file”. 2. 2.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. Set Build Options Select Project>Build Options>Project to open the Build Options dialog. and then try to build again. 4. The Output window should appear at the end of the build and display the build results. Then check the checkbox for “Generate map file”. 3. Make sure you have set up the language tools correctly and have all the correct project files and build options. If you modified the sample source code. Select Project>Save Project to save the current configuration of the Example project. double-click on the error to go to the source code line that contains that error. For “Categories: (All Options)”.mcp”. 1. DS33014K-page 18 2009 Microchip Technology Inc. For “Categories: General”. 5. check that the “Diagnostics level” includes all errors.foxitsoftware. warnings and messages. check that the “Default Radix” is set to “Hexadecimal”.http://www. If you find any. Click on the MPASM/C17/C18 Suite tab.

7. Select “Example. “Example. several debug tools exist that work with MPLAB IDE to help you do this.xrf”. Further Development Usually.7 “Map File (. You do not view this file for debugging. you will need a debug tool to help you develop your code. Select File>Open.*)” to see all project files. Repeat steps 1 and 2. When MPASM assembler is used with MPLINK linker. For more on this file. This is the primary output file. 6. Therefore. Repeat steps 1 and 2.lst”. 5. DS33014K-page 19 .http://www. Section 1. Click Open to view the linker listing file in an MPLAB IDE editor window. In the Open dialog. For more on this file.hex”. Repeat steps 1 and 2. Notice that there is only one hex file. find the project directory. your application code will contain errors and not build the first time. Once you have developed your code. 2009 Microchip Technology Inc. Please see the documentation for these tools to see how they can help you. Section 9. the listing file is generated by the linker. see the MPASM assembler documentation. Please see MPLAB IDE documentation concerning this control. Click Open to view the assembler cross-reference file for Example. You may choose from simulators. Please see the documentation for these tools to see how they can help you.7. Again. there are several programmers that work with MPLAB IDE to help you do this.7.map)”. For more information on using MPLAB IDE. Select “Example. Under “Files of type” select “All files (*. Select “Example. For more on this file. Using the output files previously discussed. 1.6 “Cross Reference File (. Section 9.foxitsoftware. you will want to program it into a device. When programming.asm in an MPLAB IDE editor window.lst)”. either manufactured by Microchip Technology or third-party developers. consult the on-line help that comes with this application or download printable documents from our website. use instead View>Program Memory or View>Disassembly Listing. used by various debug tools. you will need to set the Build Configuration to “Debug”.6 “Listing File (. MPLAB IDE Generated by Foxit PDF Creator © Foxit Software Output Files View the project output files by opening the files in MPLAB IDE. in-circuit emulators or in-circuit debuggers.com PIC1X MCU Language Tools andFor evaluation only. When debugging. 2. 4. see the MPLINK linker documentation.map”.xrf)”. see the MPLINK linker documentation. 3. Please see MPLAB IDE documentation concerning this control. Click Open to view the linker map file in an MPLAB IDE editor window. you will need to set the Build Configuration to “Release”.

.http://www.com Assembler/Linker/Librarian User’s Guide NOTES: Generated by Foxit PDF Creator © Foxit Software For evaluation only. DS33014K-page 20 2009 Microchip Technology Inc.foxitsoftware.

... Tips and Tricks ............................... DS33014K-page 21 ................................... ASSEMBLER/LINKER/LIBRARIAN USER’S GUIDE Part 1 – MPASM Assembler Chapter 1........ 43 Chapter 5.............................. Messages............. 23 Chapter 2.......... Relocatable Objects .... Errors...................... Assembler Examples.................. 37 Chapter 4. MPASM Assembler Overview ................ Assembler Interfaces ... Directives ............... 151 Chapter 8.... Warnings......................................................................................................... and Limitations ............................com For evaluation only........ 155 2009 Microchip Technology Inc........................... Expression Syntax and Operation ................. Macro Language ......... 141 Chapter 7....................... 121 Chapter 6.................................................................................... 33 Chapter 3..................................foxitsoftware...........................Generated by Foxit PDF Creator © Foxit Software http://www.

. DS33014K-page 22 2009 Microchip Technology Inc.com Assembler/Linker/Librarian User’s Guide NOTES: Generated by Foxit PDF Creator © Foxit Software For evaluation only.http://www.foxitsoftware.

1 INTRODUCTION An overview of the MPASM assembler and its capabilities is presented.40.) 1. Use this version with MPLAB IDE. DS33014K-page 23 . The executable version of the assembler is ³°¿­³©·²ò»¨». Notable features include: • • • • MPLAB IDE Compatibility Windows/Command Line Interfaces Rich Directive Language Flexible Macro Language 1. or on the command line. Topics covered in this chapter: • • • • • • MPASM Assembler Defined How MPASM Assembler Helps You Assembler Migration Path Assembler Compatibility Issues Assembler Operation Assembler Input/Output Files 1.2 MPASM ASSEMBLER DEFINED The MPASM assembler (the assembler) is a command-line or Windows-based PC application that provides a platform for developing assembly language code for Microchip's PIC1X microcontroller (MCU) families.Generated by Foxit PDF Creator © Foxit Software http://www. The rest of the directive and macro language will be the same. This version is available with MPLAB IDE or with the regular and demo version of the MPLAB C18 C compiler. MPASM Assembler Overview 1. application code developed for the PIC16F877A can be translated into a program for the PIC18F452.foxitsoftware. Also. This may require changing the instruction mnemonics that are not the same between the devices (assuming that register and peripheral usage were similar). configuration settings may be different.3 HOW MPASM ASSEMBLER HELPS YOU The MPASM assembler provides a universal solution for developing assembly code for all of Microchip's PIC1X MCUs. The __CONFIG syntax with one operand is not recognized by PIC18 and PIC16F19XX MCUs. ASSEMBLER/LINKER/LIBRARIAN USER’S GUIDE Chapter 1. (Some memory and KeeLoq devices were not supported in MPLAB IDE after v5. in a stand-alone Windows application.com For evaluation only.70. 2009 Microchip Technology Inc. The MPASM assembler supports all PIC1X MCU devices.4 ASSEMBLER MIGRATION PATH Since the MPASM assembler is a universal assembler for all PIC1X MCU devices. as well as memory and KeeLoq ® secure data products from Microchip Technology Inc.

If assembly proceeds without errors. code. 1.http://www. .6. even though certain older syntaxes may be supported for compatibility reasons. This process is shown below. The MPASM assembler supports a clean and consistent method of specifying radix (see Section 3.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. or in files that have been explicitly included by that source file. all variables and routines used in the source file must be defined within that source file.1 Generating Absolute Code Absolute code is the default output from the MPASM assembler. a hex file will be generated. 1. DS33014K-page 24 2009 Microchip Technology Inc. This file can then be used with a debugger to test code execution or with a device programmer to program the microcontroller.6 ASSEMBLER OPERATION The MPASM assembler can be used in two ways: • To generate absolute code that can be executed directly by a microcontroller. 1.5 ASSEMBLER COMPATIBILITY ISSUES The MPASM assembler is compatible with the MPLAB IDE integrated development environment and all Microchip PIC1X MCU development systems currently in production.foxitsoftware.4 “Numeric Constants and Radix”.asm MPASM™ assembler code. containing the executable machine code for the target device. • To generate relocatable code that can be linked with other separately assembled or compiled modules.hex MCU Programmer When a source file is assembled in this manner.) You are encouraged to develop using the radix and other directive methods described within this document.

2 Generating Relocatable Code The MPASM assembler also has the ability to generate a relocatable object module that can be linked with other modules using Microchip's MPLINK linker to form the final executable code. unit1.asm MPASM assembler MPLIB librarian units. DS33014K-page 25 . “Relocatable Objects” for more information on the differences between absolute and relocatable object assembly.http://www.asm MPASM™ assembler MPLIB™ librarian unit1. MPASM Assembler Overview Generated by Foxit PDF Creator © Foxit Software 1.o MPLIB librarian Refer to Chapter 6. 2009 Microchip Technology Inc.asm MPASM assembler unit3.6.o unit3.lib unit2.foxitsoftware. and only the routines that are needed will be included in the final executable.o unit2.com For evaluation only. Required libraries can be specified at link time. Related modules can be grouped and stored together in a library using Microchip's MPLIB librarian. This method is very useful for creating reusable modules.

DS33014K-page 26 2009 Microchip Technology Inc.foxitsoftware.asm) Assembly is a programming language you may use to develop the source code for your application. and white space must separate the mnemonic and the operand(s). Unless within character constants.hxl. and can start in any column.asm) TABLE 1-2: Listing File (.lst) Error File (. Note: Several example source code files are included free with MPLAB IDE.hxh) Cross Reference File (. White space should be used to make your code easier for people to read. mnemonics or labels. Multiple operands must be separated by commas.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. Your source code should conform to the following basic guidelines.7.http://www.inc) INPUT FILES Default source file extension input to assembler. . Operands follow the mnemonic. Output extension from assembler for hex files. Output extension from assembler for cross reference files. Comments may follow the operands. Hex File Formats (. it is recommended that labels start in column one and mnemonics start in column two or beyond. The maximum column width is 255 characters.o) 1. Include (header) file Source Code (. White space or a colon must separate the label and the mnemonic.1 Source Code (. Each line of the source file may contain up to four types of information: • • • • Labels Mnemonics.err) OUTPUT FILES Default output extension for listing files generated by assembler. Output extension from assembler for object files. Directives and Macros Operands Comments The order and position of these are important. 1.hex. any white space means the same as exactly one space. For ease of debugging. The source code file may be created using any ASCII text file editor. . White space is used to separate pieces of a source line. White space is one or more spaces or tabs. . TABLE 1-1: Include File (.7 ASSEMBLER INPUT/OUTPUT FILES These are the default file extensions used by the assembler and the associated utility functions.xrf) Object File (. Output extension from assembler for error files.

tab or the end of line. output. 2009 Microchip Technology Inc. addition (¿¼¼). DS33014K-page 27 . branches (¹±¬±) or moves (³±ª©º).3 “Reserved Words and Section Names”). Labels must not: • begin with two leading underscores. space. and data allocation. • be an assembler reserved word (see Section 3.g. Unlike labels that you create yourself. Directives are not case sensitive.1 LABELS A label is used to represent a line or group of code. Directives are assembler commands that appear in the source code but are not usually translated directly into opcodes. For example. ÁÁ½±²º·¹. They may be followed by a colon (:). 1.1. If a colon is used when defining a label. mnemonics are provided by the assembly language..7.1. but case sensitivity may be overridden by a command-line option (ñ½).7.foxitsoftware. • begin with a leading underscore and number. ÁîÒÜÔÑÑÐ. MPASM Assembler Overview EXAMPLE 1-1: ABSOLUTE MPASM ASSEMBLER SOURCE CODE (SHOWS MULTIPLE OPERANDS) Generated by Foxit PDF Creator © Foxit Software Mnemonics Directives Operands Comments Labels Macros | | ´·­¬ ý·²½´«¼» Ü»­¬ »¯« ±®¹ ¹±¬± ±®¹ ͬ¿®¬ ³±ª´© ³±ª©º ¾½º ¹±¬± »²¼ ð¨ðß Ü»­¬ Ü»­¬ô í å̸·­ ´·²» «­»­ î ±°»®¿²¼­ ͬ¿®¬ | °ãïèºìëî °ïèºìëîò·²½ ð¨ðÞ ð¨ðððð ͬ¿®¬ ð¨ððîð åÜ»º·²» ½±²­¬¿²¬ åλ­»¬ ª»½¬±® | åÞ»¹·² °®±¹®¿³ 1.) Labels should start in column 1. DIRECTIVES AND MACROS Mnemonics tell the assembler what machine instructions to assemble. Macros are user defined sets of instructions and directives that will be evaluated in-line with the assembler source code whenever the macro is invoked. They are used to control the assembler: its input. Labels must begin with an alpha character or an under bar (_) and may contain alphanumeric characters. Mnemonics are not case sensitive. the under bar and the question mark.com For evaluation only.g.2 MNEMONICS. it is treated as a label operator and not part of the label itself..http://www. By default they are case sensitive. e. Labels may be up to 32 characters long. or a constant value. e. It is needed for branching instructions (Example 1-1.

5. memory usage information. ½±²­¬¿²¬. 3.7. The fourth column lists the associated source file line number for this line.3 OPERANDS Operands give information to the instruction on the data that should be used and the storage location for the instruction. or header. selecting File>Open to launch the Open dialog selecting “List files (*.2 Include File (. use: ý·²½´«¼» °ïèºìëîò·²½ Standard header files are located in: ÝæÄЮ±¹®¿³ Ú·´»­ÄÓ·½®±½¸·°ÄÓÐßÍÓ Í«·¬» 1. and the number of errors. This is the code that will be executed by the PIC1X MCU. the file contains device-specific register and bit assignments. 2.lst) An MPASM assembler listing file provides a mapping of source code to object code. or ½¾´±½µ directives. ª¿®·¿¾´». 1. to add the standard header file for the PIC18F452 device to your assembly code. Assembler instruction mnemonics. The first column contains the base address in memory where the code will be placed.7.inc) An assembler include. If there is a label on the same line.1. The MPASM assembler treats anything after a semicolon as a comment. instructions must be separated from that label by a colon. file is any file containing valid assembly code. . and the page number appear at the top of every page. »¯«. or tabs.) Set the size of tabs in the list file using the ñ¬ option. use the ñ´ó option or use with MPLINK linker (The linker list file overwrites the assembler list file. All characters following the semicolon are ignored through the end of the line. the assembly date and time.lst)”. The third column is reserved for the machine instruction.lst)” from the “Files of type” drop-down list locating the desired list file clicking on the list file name clicking Open Both the MPASM assembler and the MPLINK linker can generate listing files. EXAMPLE 1-2: ABSOLUTE MPASM ASSEMBLER LISTING FILE The product name and version. see 9. Operands must be separated from mnemonics by one or more spaces. Usually.foxitsoftware.3 Listing File (. directives and macro calls should begin in column two or greater. String constants containing a semicolon are allowed and are not confused with comments. The second column displays the 32-bit value of any symbols created with the ­»¬.7. 1. 4. or by one or more spaces or tabs. For information on the MPLINK linker listing file. The remainder of the line is reserved for the source code line that generated the machine code. To prevent assembler list file generation.7. warnings and messages generated. 1. It also provides a list of symbol values.1.7. As an example.http://www.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. This file may be “included” in the code so that it may be reused by many programs. DS33014K-page 28 2009 Microchip Technology Inc. This file may be viewed in MPLAB IDE by: 1.6 “Listing File (.4 COMMENTS Comments are text explaining the operation of a line or lines of code. Multiple operands must be separated by commas.

'X' marks a used location and '-' marks memory that is not used by this object. °ïèºìëîò·²½. some symbol table listings have been removed. MPASM Assembler Overview Errors. DS33014K-page 29 . indicated by “:” See the standard header. indicated by “. some comments have been shortened. warnings. Also.foxitsoftware. The symbol table lists all symbols defined in the program.com For evaluation only. The memory usage map gives a graphical representation of memory usage.” Also. Note: Due to page width restrictions. The memory map is not printed if an object file is generated. ÍÑËÎÝÛòßÍÓ ìóëóîððì ïëæìðæðð Generated by Foxit PDF Creator © Foxit Software ÓÐßÍÓ ðíòéð λ´»¿­»¼ ÐßÙÛ ï ÔÑÝ ÑÞÖÛÝÌ ÝÑÜÛ ÊßÔËÛ Ô×ÒÛ ÍÑËÎÝÛ ÌÛÈÌ ðððððððÞ ðððððð ðððððð ððððîð ððððîð ððððîî ððððîì ððððîê ÛÚïð Úððð ðÛðß êÛðÞ çêðÞ ÛÚïð Úððð ððððï ´·­¬ °ãïèºìëî ððððî ý·²½´«¼» °ïèºìëîò·²½ ððððï Ô×ÍÌ ððððî å ÐïèÚìëîò×ÒÝ Í¬¿²¼¿®¼ Ø»¿¼»® Ú·´»ô Ê»®­·±² ïòìòò ððèìë Ô×ÍÌ ððððí Ü»­¬ »¯« ð¨ðÞ ððððì ððððë ±®¹ ð¨ðððð ððððê ¹±¬± ͬ¿®¬ ððððé ±®¹ ð¨ððîð ððððè ͬ¿®¬ ³±ª´© ð¨ðß ððððç ³±ª©º Ü»­¬ ðððïð ¾½º Ü»­¬ô í å̸·­ ´·²» «­»­ î ±°òò ðððïï ¹±¬± ͬ¿®¬ ðððïî »²¼ ÍÑËÎÝÛòßÍÓ ìóëóîððì ïëæìðæðð ÐßÙÛ î ÓÐßÍÓ ðíòéð λ´»¿­»¼ ÍÇÓÞÑÔ ÌßÞÔÛ ÔßÞÛÔ ß ßÝÝÛÍÍ æ ÁÈÌÁÑÍÝÁïØ ÁÁïèÚìëî ÓÐßÍÓ ðíòéð λ´»¿­»¼ ÊßÔËÛ ðððððððð ðððððððð æ ððððððÚç ðððððððï ÍÑËÎÝÛòßÍÓ ìóëóîððì ïëæìðæðð ÐßÙÛ ïî ÓÛÓÑÎÇ ËÍßÙÛ ÓßÐ øùÈù ã Ë­»¼ô ùóù ã ˲«­»¼÷ ðððð æ ÈÈÈÈóóóóóóóóóóóó óóóóóóóóóóóóóóóó ÈÈÈÈÈÈÈÈÈÈóóóóóó óóóóóóóóóóóóóóóó ß´´ ±¬¸»® ³»³±®§ ¾´±½µ­ «²«­»¼ò Ю±¹®¿³ Ó»³±®§ Þ§¬»­ Ë­»¼æ ïì Ю±¹®¿³ Ó»³±®§ Þ§¬»­ Ú®»»æ íîéëì 2009 Microchip Technology Inc. for a complete list of symbols. The map also displays program memory usage.http://www. there is a summary at the end of the listing.. and messages are embedded between the source lines and pertain to the following source line.

Each record has the following format: æÞÞßßßßÌÌØØØØòòòòØØØÝÝ where: ÞÞ ßßßß ÌÌ ØØ ÝÝ A two digit hexadecimal byte count representing the number of data bytes that will appear on the line. A four digit hexadecimal address representing the starting address of the data record. and Limitations”. use the ñ»ó option.err) The MPASM assembler. ò¸¨¸ ò¸»¨ Use 8-bit core device programmers odd/even programmers 16-bit core device programmers This file format is useful for transferring PIC1X MCU series code to Microchip programmers and third party PIC1X MCU programmers. 1. see Chapter 8. . . . Warnings.5 Hex File Formats (.4 Error File (. by default. This file can be useful when debugging your code. Format Name Intel Hex Format Intel Split Hex Format Intel Hex 32 Format Format Type INHX8M INHX8S INHX32 File Extension ò¸»¨ ò¸¨´. For more on these. 1. Messages. generates an error file. Each data record begins with a 9-character prefix and ends with a 2-character checksum. To prevent error file generation.hxl. presented in low byte/high byte combinations. all addresses are doubled. A two digit hexadecimal checksum that is the two's complement of the sum of all preceding bytes in the record. “Errors. The format of the messages in the error file is: ¬§°»Å²«³¾»®Ã º·´» ´·²» ¼»­½®·°¬·±² For example: Û®®±®Åïïíà ÝæÄÐÎÑÙòßÍÓ é æ ͧ³¾±´ ²±¬ °®»ª·±«­´§ ¼»º·²»¼ ø­¬¿®¬÷ The error file may contain any number of MPASM assembler errors.com Assembler/Linker/Librarian User’s Guide Û®®±®­ æ É¿®²·²¹­ æ Ó»­­¿¹»­ æ ð ð ®»°±®¬»¼ô ð ®»°±®¬»¼ô Generated by Foxit PDF Creator © Foxit Software For evaluation only.http://www.foxitsoftware.5.hxh) The MPASM assembler and MPLINK linker are capable of producing ASCII text hex files in different formats.1 INTEL HEX FORMAT This format produces one 8-bit hex file with a low byte. which will be '01'.7. high byte combination. ð ­«°°®»­­»¼ ð ­«°°®»­­»¼ 1. A two digit hexadecimal data byte. DS33014K-page 30 2009 Microchip Technology Inc. Since each address can only contain 8 bits in this format. A two digit record type that will always be '00' except for the end-of-file record.hex.7.7. warnings and messages. The MPLAB IDE will display the error information in the Output window.

A two digit record type: 00 . A two digit hexadecimal checksum that is the two's complement of the sum of all preceding bytes in the record. and the addresses are divided by two. except that the low bytes of the data word are stored in the ò¸¨´ file.3 INTEL HEX 32 FORMAT The extended 32-bit address hex format is similar to the hex 8 format.7. This is used to program 16-bit words into pairs of 8-bit EPROMs.Segment address record 04 .7.2 INTEL SPLIT HEX FORMAT The split 8-bit file format produces two output files: ò¸¨´ and ò¸¨¸.End of File record 02 . Each record has the following format: æÞÞßßßßÌÌØØØØòòòòØØØÝÝ where: ÞÞ ßßßß ÌÌ A two digit hexadecimal byte count representing the number of data bytes that will appear on the line.foxitsoftware.Data record 01 . except that the extended linear address record is output also to establish the upper 16 bits of the data address. Each data record begins with a 9-character prefix and ends with a 2-character checksum. and the high bytes of the data word are stored in the ò¸¨¸ file. A four digit hexadecimal address representing the starting address of the data record.5.Linear address record ØØ ÝÝ A two digit hexadecimal data byte.http://www. presented in low byte/high byte combinations. DS33014K-page 31 . one file for low byte. 2009 Microchip Technology Inc. This is mainly used for 16-bit core devices since their addressable program memory exceeds 64 kbytes.com For evaluation only. The format is the same as the normal 8-bit format. one file for high byte. MPASM Assembler Overview EXAMPLE 1-3: INHX8M Generated by Foxit PDF Creator © Foxit Software º·´»Á²¿³»ò¸»¨ æïðððððððððððððððððððððððððððððððððððððððÚð æðìððïðððððððððððÛÝ æïðððíîððððððîèððìðððêèððßèððÛèððÝèððîèðïêÜ æïðððìîððêèðïßçðïèçðïÛßðïîèðîðèðîêßðîÞÚðîÝë æïðððëîððÛððîÛèðîîèðíêèðíÞÚðíÛèðíÝèðíðèðìÞè æïðððêîðððèðìðèðìðíðììíðëðíðêÛèðéÛèðéÚÚðèíç æðêððéîððÚÚðèÚÚðèïçðßëé æðððððððïÚÚ 1.5. EXAMPLE 1-4: INHX8S º·´»Á²¿³»ò¸¨´ æðßððððððððððððððððððððððððððððÚê æïðððïçððððîèìðêèßèÛèÝèîèêèßçèçÛßîèðèêßÞÚßß æïðððîçððÛðÛèîèêèÞÚÛèÝèðèðèðèðíìíðíÛèÛèÚÚÜð æðíððíçððÚÚÚÚïçßÜ æðððððððïÚÚ º·´»Á²¿³»ò¸¨¸ æðßððððððððððððððððððððððððððððÚê æïðððïçðððððððððððððððððïðïðïðïðïðîðîðîðîÝß æïðððîçðððîðîðíðíðíðíðíðìðìðìðìðëðêðéðéðèèí æðíððíçðððèðèðßßß æðððððððïÚÚ 1.

use the ñ¨ó option. .7. To prevent object file generation.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. The file has the following format: • The symbols are listed in the “Label” column.http://www.7. 1. see 1.hxl. sorted by name. A list of “Label Types” is provided at the end of the file. • The “Type” column defines the type of symbol. To generate a file that will execute after being programmed into a device.5 “Hex File Formats (. An asterisk means a definition.7 Object File (.xrf) A cross reference file contains a listing of all symbols used in the assembly code.hxh)”.6 Cross Reference File (. . • The “Source File References” column lists the line number of the corresponding file in the “File Name” column where the symbol is defined/referenced.o) The assembler creates a relocatable object file from source code. This object file does not yet have addresses resolved and must be linked before it can be used as an executable. To prevent cross-reference file generation. DS33014K-page 32 2009 Microchip Technology Inc.foxitsoftware. 1. use the ñ±ó option.hex.7. . • The “File Name” column lists the names of the files that use the symbol.

enter one or browse to the location of this file. select “Microchip MPASM Toolsuite”. a path to the ³°¿­³©·²ò»¨» file should be displayed. 3. depending on the assembler version. the assembler may be obtained with the regular and demo version of the MPLAB C18 C compiler.2 MPLAB IDE INTERFACE The MPASM assembler is most commonly used with the MPLINK linker in an MPLAB IDE project to generate relocatable code. 6. To do this: 1. By default.foxitsoftware.Generated by Foxit PDF Creator © Foxit Software http://www. The assembler may also be used in MPLAB IDE to generate absolute code (without the use of the MPLINK linker or MPLAB IDE project) by using the QuickBuild feature. Select MPASM Assembler (³°¿­³©·²ò»¨»). Under Location. Select Executables. Click OK. under Registered Tools. In the dialog. 4. For more information on this use. When MPLAB IDE is installed. Click the “+” to expand. These interfaces are discussed here. In addition. select Project>Quickbuild to assemble the specified asm file using the MPASM assembler. DS33014K-page 33 . 2009 Microchip Technology Inc. If no path is displayed. From the MPLAB IDE menu bar. 2.1 INTRODUCTION There are several interfaces with which you may use the MPASM assembler. Assembler Interfaces 2. it is located at: ÝæÄЮ±¹®¿³ Ú·´»­ÄÓ·½®±½¸·°ÄÓÐßÍÓ Í«·¬»Ä³°¿­³©·²ò»¨» 5. see “PIC1X MCU Language Tools and MPLAB IDE”. the MPASM assembler (³°¿­³©·²ò»¨») is also installed. ASSEMBLER/LINKER/LIBRARIAN USER’S GUIDE Chapter 2. Topics covered in this chapter: • MPLAB IDE Interface • Windows Interface • Command Line Interface 2. Click the “+” to expand. select Project>Set Language Tool Locations to open a dialog to set/check language tool executable location. From the MPLAB IDE menu bar.com For evaluation only.

Reference: Section 1.Expand Macro Listing” Warning Level Hex Output Generated Files Case Sensitivity Tab Size Macro Expansion DS33014K-page 34 2009 Microchip Technology Inc.3 WINDOWS INTERFACE MPASM assembler for Windows provides a graphical interface for setting assembler options. (Default options are read from the source file.foxitsoftware.hxl.Specify Default Radix”. Reference: Section 4. Option Radix Description Override any source file radix settings. FIGURE 2-1: MPASM ASSEMBLER WINDOWS SHELL INTERFACE Select a source file by typing in the name or using the Browse button.7.hex. It is invoked by executing ³°¿­³©·²ò»¨» in Windows Explorer or from a command prompt. Set the various options as described below. If enabled. Reference: Section 4. Section 4.4 “Numeric Constants and Radix” Override any source file message level settings.32 “»¨°¿²¼ . the assembler will distinguish between upper.Create User Defined Message” Override any source file hex file format settings.56 “®¿¼·¨ . Section 3. Use the MPASM Assembler tab of the Build Options dialog in MPLAB IDE (Project>Build Options>Project) to set options. Reference: Section 1. . 2. . this options screen is not available.Listing Options”.7 “Assembler Input/Output Files” Enable/disable case sensitivity.5 “Hex File Formats (. Reference: Section 4. .48 “³»­­¹ . Set the list file tab size. Note: When MPASM assembler for Windows is invoked through MPLAB IDE.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only.7. Reference: Section 1.and lower-case letters.43 “´·­¬ .3 “Listing File (.hxh)” Enable/disable various output files.) Then click Assemble to assemble the source file.http://www.lst)” Override any source file macro expansion settings.

. Option ñá ñ¿¸»¨óº±®³¿¬ Default N/A INHX32* Description Display the assembler help screen. Assembler Interfaces Description Option Processor Extended Mode Extra Options Save Settings on Exit Override any source file processor settings. Enable PIC18F extended instruction support.4 COMMAND LINE INTERFACE MPASM assembler can be invoked through the command line interface (command prompt) as follows: ³°¿­³©·² Åñ±°¬·±²ïòòòñ±°¬·±²Òà º·´»²¿³» where ñ±°¬·±² . Define a text string substitution. it can be assembled with following command: ³°¿­³©·² ñ» ñ´ ¬»­¬ò¿­³ If the source filename is omitted. Enable/Disable/Set Path for list file ñ´ Enable ñ´õ Enable ñ´ó Disable ñ´ °¿¬¸ Enable/specify path See Section 1. Display the assembler help screen.e. Any additional command-line options. Enable/Disable/Set Path for error file.4 “Command Line Interface” Save these settings in ³°´¿¾ò·²·. They will be used the next time you run ³°¿­³©·²ò»¨».4 “Error File (.foxitsoftware.7. Reference: Section 2.Generated by Foxit PDF Creator © Foxit Software http://www. i.err)” for more information.e..7. i.refers to one of the command line options º·´»²¿³» .com For evaluation only.and lower-case letters. DS33014K-page 35 .7. if ¬»­¬ò¿­³ exists in the current directory. Enable/Disable case sensitivity. the appropriate shell interface is invoked. which includes a Help button. assign ª¿´«» to ´¿¾»´. Generate ò¸»¨ output directly from assembler. If enabled. ñ½ On ñ¼´¿¾»´Å㪿´«»Ã ñ»Åõ¤ó¤°¿¬¸Ã N/A On ñ¸ ñ´Åõ¤ó¤°¿¬¸Ã N/A On 2009 Microchip Technology Inc.5 “Hex File Formats (. 2.3 “Listing File (.. ñ» Enable ñ»õ Enable ñ»ó Disable ñ» °¿¬¸ Enable/specify path See Section 1. where ¸»¨óº±®³¿¬ is one of {×ÒØÈèÓ | ×ÒØÈèÍ | ×ÒØÈíî}.is the file being assembled For example. the assembler will distinguish between upper.hxh)” for more information. See 1.hxl. a Windows OS interface is displayed.lst)” for more information.hex. .

7 “Object File (.g. See Section 4. See Section 4.43 “´·­¬ Listing Options”.. .48 “³»­­¹ . Enable/Disable/Set Path for object file.7. Ð×ÝïèÚìëî.) Defines default radix. where ®¿¼·¨ is one of {ØÛÈ | ÜÛÝ | ÑÝÌ }. Option ñ³Åõ¤óà Default On Description Enable/Disable macro expansion. where ª¿´«» is one of {ð|ï|î}. Enable/Disable/Set Path for cross reference file.Specify Default Radix” for more information. where °®±½»­­±®Á¬§°» is a PIC1X MCU device. Enable/Disable quiet mode (suppress screen output. 0 all messages 1 errors and warnings 2 errors only See Section 4.7. e.7.xrf)” for more information.foxitsoftware.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. Set message level.lst)” for more information. Set the size of tabs in the list file. See Section 1. ñ± Enable ñ±õ Enable ñ±ó Disable ñ± °¿¬¸ Enable/specify path See Section 1.43 “´·­¬ .Create User Defined Message” for more information.o)” for more information. Set the processor type.6 “Cross Reference File (.32 “»¨°¿²¼ . Enable/Disable extended instruction set. ñ§ Enable ñ§õ Enable ñ§ó Disable Can only be enabled for processors which support the extended instruction set and for the generic processor PIC18CXXX. ñ¨ Enable ñ¨õ Enable ñ¨ó Disable ñ¨ °¿¬¸ Enable/specify path See Section 1.Listing Options” or Section 4.56 “®¿¼·¨ .http://www. ñ§ó overrides Ô×ÍÌ ÐÛ㬧°» directive (see Section 4.) ñ±Åõ¤ó¤°¿¬¸Ã Off ñ°°®±½»­­±®Á¬§°» ñ¯Åõ¤óà ñ®®¿¼·¨ None Off Hex ñ¬ 8 ñ©ª¿´«» 0 ñ¨Åõ¤ó¤°¿¬¸Ã Off ñ§Åõ¤óà Disabled * Default is dependent on processor selected. DS33014K-page 36 2009 Microchip Technology Inc.Expand Macro Listing” for more information.3 “Listing File (.

Expression Syntax and Operation 3. If a string has an odd number of characters (bytes). If none is found before the end of the line. It may contain double quotes or null characters.2 TEXT STRINGS A “string” is a sequence of any valid ASCII character (of the decimal range of 0 to 127) enclosed by double quotes. or an error will occur. The ¼© directive will store the entire string into successive words.Generated by Foxit PDF Creator © Foxit Software http://www. the ¼© and ¼¿¬¿ directives will pad the end of the string with one byte of zero (00). the string will end at the end of the line. ASSEMBLER/LINKER/LIBRARIAN USER’S GUIDE Chapter 3. The same escape sequences that apply to strings also apply to characters. and operations used by MPASM assembler are described here.1 INTRODUCTION Various expression formats. it is generally no problem to use a second ¼© directive for the next line. syntax. Topics covered in this chapter: • • • • Text Strings Reserved Words and Section Names Numeric Constants and Radix Arithmetic Operators and Precedence 3. If a matching quote mark is found. If a string is used as a literal operand. While there is no direct provision for continuation onto a second line. it must be exactly one character long. The way to get special characters into a string is to escape the characters. 2009 Microchip Technology Inc. the string ends. preceding them with a backslash ‘\’ character.foxitsoftware. Strings may be of any length that will fit within a 255 column source line.com For evaluation only. DS33014K-page 37 .

Octal digit) Hexadecimal number Hex Value ðé ðè ðÝ ðß ðÜ ðç ðÞ ëÝ íÚ îé îî 3.1 Escape Characters The assembler accepts the ANSI ‘C’ escape sequences to represent certain special control characters: TABLE 3-1: Escape Character Ä¿ ľ ĺ IJ Ä® Ĭ Ī ÄÄ Äá Äù ÄŒ ÄðÑÑ Ä¨ØØ ANSI ‘C’ ESCAPE SEQUENCES Description Bell (alert) character Backspace character Form feed character New line character Carriage return character Horizontal tab character Vertical tab character Backslash Question mark character Single quote (apostrophe) Double quote character Octal number (zero. . Octal digit.http://www. éìêë êéîð éëéì êçêÛ êëðß Þðêï éìêë êéîð éìîð éëéì êçêÛ éíéì êÚéë îðéí êéîð êçêÛ éìéð éìéî êÚêÛ ¼© ¬»­¬·²¹ ±«¬°«¬ ­¬®·²¹ ±²»Ä²Œ ý¼»º·²» éíéì êêêç êÚéë îðéí êéðð êçêÛ éîéí éìéð éìéî ­¬® ¬»­¬·²¹ ±«¬°«¬ ­¬®·²¹ ¬©±Œ ³±ª´© ¿Œ ¼¿¬¿ ¬»­¬·²¹ º·®­¬ ±«¬°«¬ ­¬®·²¹Œ DS33014K-page 38 2009 Microchip Technology Inc.2.foxitsoftware.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only.2.2 Code Examples See the examples below for the object code generated by different statements involving strings. 3.

2009 Microchip Technology Inc. binary.3 RESERVED WORDS AND SECTION NAMES You may not use the following words for label. If unsigned. «¼¿¬¿Á¿½­. respectively. • The word “main” (when using the assembler with MPLAB IDE). and ASCII.foxitsoftware. as with an interrupt.com For Operation Expression Syntax andevaluation only. decimal. respectively. Also. Default section names for «¼¿¬¿. Do not use a “main” label that cannot be reached by a simple reset and run. Whenever an attempt is made to place a constant in a field for which it is too large. the default radix determines what value will be assigned to constants in the object file when a radix is not explicitly specified by a base descriptor. “Directives”). DS33014K-page 39 . a data label named “main” or a routine named “main” that will only be accessed under certain conditions. decimal. Note: Intermediate values in constant expressions are treated as 32-bit unsigned integers. octal. and octal.http://www. Generated by Foxit PDF Creator © Foxit Software 3. a truncation warning will be issued. the assembler has the following reserved section names: TABLE 3-2: ò¿½½»­­Á±ª® ò½±¼» ò·¼¿¬¿ ò·¼¿¬¿Á¿½­ ò«¼¿¬¿ ò«¼¿¬¿Á¿½­ ò«¼¿¬¿Á±ª® ò«¼¿¬¿Á­¸® RESERVED SECTION NAMES Purpose Default section name for ¿½½»­­Á±ª® directive. «¼¿¬¿Á±ª® and «¼¿¬¿Á­¸® directives.4 NUMERIC CONSTANTS AND RADIX MPASM assembler supports the following radix forms for constants: hexadecimal. Default section name for ½±¼» directive. allowable default radices are limited to hexadecimal. for example. the value is assumed to be positive. Constants can be optionally preceded by a plus or minus sign. “Instruction Sets”). The default radix is hexadecimal. • Instructions (see Appendix A. Default section names for ·¼¿¬¿ and ·¼¿¬¿Á¿½­ directives. constant or variable names: • Directives (see Chapter 4. Section Name 3. Note: The radix for numeric constants can be made different from the default radix specified with the directives ®¿¼·¨ or ´·­¬ ®ã. In addition.

’ followed by one or more decimal digits ‘0123456789’. 3. Precedence refers to the order in which operators are executed in a code statement.2 “ASCII Character Set”) in single quotes.http://www. Or. a hexadecimal integer is ‘0x’ or ‘0X’ followed by one or more hexadecimal digits ‘0123456789abcdefABCDEF’. Note: These operators cannot be used with program variables. The following table presents the various radix specifications: TABLE 4: RADIX SPECIFICATIONS . a decimal integer is ‘. TABLE 3-1: ARITHMETIC OPERATORS IN ORDER OF PRECEDENCE Ñ°»®¿¬±® ü ø ÷ ÿ ó ¢ ´±©1 ¸·¹¸1 «°°»® ö ñ û õ ó ää 1 Example ¹±¬± ü õ í ï õ ø¼ ö ì÷ øÔ»²¹¬¸ õ ï÷ ö îëê ·º ÿ ø¿ ãã ¾÷ óï ö Ô»²¹¬¸ º´¿¹­ ã ¢º´¿¹­ ³±ª´© ´±© ÝÌÎÁÌ¿¾´» ³±ª´© ¸·¹¸ ÝÌÎÁÌ¿¾´» ³±ª´© «°°»® ÝÌÎÁÌ¿¾´» ¿ ã ¾ ö ½ ¿ ã ¾ ñ ½ »²¬®§Á´»² ã ¬±¬Á´»² û ïê ¬±¬Á´»² ã »²¬®§Á´»² ö è õ ï »²¬®§Á´»² ã ø¬±¬ ó ï÷ ñ è º´¿¹­ ã º´¿¹­ ää ï Current/Return program counter Left Parenthesis Right Parenthesis Item NOT (logical complement) Negation (2’s complement) Complement Return low byte of address Return high byte of address Return upper byte of address Multiply Divide Modulus Add Subtract Left shift DS33014K-page 40 2009 Microchip Technology Inc.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. 2. An ASCII character is ‘a’ or ‘A’ followed by one character (see Section B. They are for use with directives only. 5. Or. The operator order in the table also corresponds to its precedence. A hexadecimal integer is ‘h’ or ‘H’ followed by one or more hexadecimal digits ‘0123456789abcdefABCDEF’ in single quotes.foxitsoftware. 3. .5 ARITHMETIC OPERATORS AND PRECEDENCE Arithmetic operators may be used with directives and their variables as specified in the table below. an ASCII character is one character in single quotes. Or. A binary integer is ‘b’ or ‘B’ followed by one or more of the binary digits ‘01’ in single quotes. where the first operator has the highest precedence and the last operator has the lowest precedence. A decimal integer is ‘d’ or ‘D’ followed by one or more decimal digits ‘0123456789’ in single quotes. Binary Octal Decimal Hexadecimal ASCII Type Syntax ÞŽ¾·²¿®§Á¼·¹·¬­Ž ÑŽ±½¬¿´Á¼·¹·¬­Ž ÜŽ¼·¹·¬­Ž ò¼·¹·¬­ ØŽ¸»¨Á¼·¹·¬­Ž 𨸻¨Á¼·¹·¬­ ߎ½¸¿®¿½¬»®Ž Ž½¸¿®¿½¬»®Ž ÑŽéééŽ ÜŽïððŽ òïðð ؎纎 ð¨çº ߎݎ ŽÝŽ Example ÞŽððïïïððïŽ 4. An octal integer is ‘o’ or ‘O’ followed by one or more of the octal digits ‘01234567’ in single quotes.MPASM ASSEMBLER/MPLINK LINKER Note 1 2 3 4 5 1.

set equal Left shift.com For Operation Expression Syntax andevaluation only.http://www. set equal Modulus. high and upper operands which apply to sections. DS33014K-page 41 . set equal Right shift. TABLE 3-1: ARITHMETIC OPERATORS IN ORDER OF PRECEDENCE Ñ°»®¿¬±® ââ âã â ä äã ãã ÿã ú  ¤ úú ¤¤ ã õã óã öã ñã ûã ääã ââã úã ¤ã Âã õõ óó Note 1: Right shift Greater or equal Greater than Less than Less or equal Equal to Not equal to Bitwise AND Bitwise exclusive OR Bitwise inclusive OR Logical AND Logical OR Set equal to Add to. set equal Increment2 Decrement 2 Example º´¿¹­ ã º´¿¹­ ââ ï ·º »²¬®§Á·¼¨ âã ²«³Á»²¬®·»­ ·º »²¬®§Á·¼¨ â ²«³Á»²¬®·»­ ·º »²¬®§Á·¼¨ ä ²«³Á»²¬®·»­ ·º »²¬®§Á·¼¨ äã ²«³Á»²¬®·»­ ·º »²¬®§Á·¼¨ ãã ²«³Á»²¬®·»­ ·º »²¬®§Á·¼¨ ÿã ²«³Á»²¬®·»­ º´¿¹­ ã º´¿¹­ ú ÛÎÎÑÎÁÞ×Ì º´¿¹­ ã º´¿¹­  ÛÎÎÑÎÁÞ×Ì º´¿¹­ ã º´¿¹­ ¤ ÛÎÎÑÎÁÞ×Ì ·º ø´»² ãã ëïî÷ úú ø¾ ãã ½÷ ·º ø´»² ãã ëïî÷ ¤¤ ø¾ ãã ½÷ »²¬®§Á·²¼»¨ ã ð »²¬®§Á·²¼»¨ õã ï »²¬®§Á·²¼»¨ óã ï »²¬®§Á·²¼»¨ öã »²¬®§Á´»²¹¬¸ »²¬®§Á¬±¬¿´ ñã »²¬®§Á´»²¹¬¸ »²¬®§Á·²¼»¨ ûã è º´¿¹­ ääã í º´¿¹­ ââã í º´¿¹­ úã ÛÎÎÑÎÁÚÔßÙ º´¿¹­ ¤ã ÛÎÎÑÎÁÚÔßÙ º´¿¹­ Âã ÛÎÎÑÎÁÚÔßÙ · õõ · óó Generated by Foxit PDF Creator © Foxit Software 2: This precedence is the same for the low.foxitsoftware. set equal Divide. These operators can only be used on a line by themselves.4 “Low. they cannot be embedded within other expression evaluations. 2009 Microchip Technology Inc. set equal Multiply. set equal Inclusive OR. set equal Subtract. set equal AND. set equal Exclusive OR. High and Upper Operators” for more information. See Section 6.

com Assembler/Linker/Librarian User’s Guide NOTES: Generated by Foxit PDF Creator © Foxit Software For evaluation only.http://www. . DS33014K-page 42 2009 Microchip Technology Inc.foxitsoftware.

For instruction set information. simple examples may be assembled and run by adding an »²¼ statement. 5. expanded examples of use. cblock may be executed as CBLOCK. 3. These may exist to provide backward compatibility with previous assemblers from Microchip and to be compatible with individual programming practices. output. 2.Generated by Foxit PDF Creator © Foxit Software http://www. and data allocation.com For evaluation only. Cblock. 6. Information on individual directives includes syntax. e. Control Directives Conditional Assembly Directives Data Directives Listing Directives Macro Directives Object File Directives 2009 Microchip Technology Inc. etc 4. Individual directives may be found alphabetically (in the following sections) or by type (Section 4. Note: Directives are not case-sensitive. Directives 4. They are used to control the assembler: its input. In most cases. See MPLINK object linker documentation for more information on linker options to control listing and hex file output. description.). etc.2 “Directives by Type”). ASSEMBLER/LINKER/LIBRARIAN USER’S GUIDE Chapter 4. in some cases. 4.. 1. DS33014K-page 43 . cblock. btfss. usage. Note: Although MPASM assembler is often used with MPLINK object linker.1 INTRODUCTION Directives are assembler commands that appear in the source code but are not usually translated directly into opcodes. as well as simple and.2 DIRECTIVES BY TYPE There are six basic types of directives provided by the assembler.foxitsoftware.g. consult your device data sheet. MPASM assembler directives are not supported in MPLINK linker scripts. If portable code is desired. and related directives. it is recommended that programs be written using the specifications contained here. Expanded examples may be assembled and run as-is to give an demonstration of an application using the directive(s). Note: Directives are not instructions (movlw. Many of the assembler directives have alternate names and formats. goto.

.. 67 DS33014K-page 44 2009 Microchip Technology Inc.. p..................................................... 71 ±®¹ ............................ 62 ¼» ............. p..Declare Symbol Variable .......... 50 ½±²­¬¿²¬ . p......Set Processor Type ..................................Specify Default Radix .............Set Program Origin.................... p....Identify Unimplemented RAM .. p..........1 • • • • • • • • • • • • • • • Control Directives Control directives control how code is assembled.......End a ©¸·´» Loop ............................. 117 4...... p...................... 99 °¿¹»­»´ ................. p.... 71 ·º ..Include Additional Source File ................................ 89 ©¸·´» ..... 116 ¾¿²µ·­»´ .... p......................... 108 ª¿®·¿¾´» . These are not run-time instructions like their C language counterparts......................... 103 °®±½»­­±® ..........Begin Conditionally Assembled Code Block............... 48 ¾¿²µ­»´ ........................ p.. p............... 58 »²¼ ...Set Processor Configuration Bits (PIC18 MCUs)................. p............ by meaningful names....................foxitsoftware......Declare Symbol Constant ......... ý¼»º·²» ...............................................Generate Page Selecting Code (PIC10/12/16 MCUs)..... p.... 68 »²¼·º .... p.... 95 ÁÁ³¿¨®±³ ........Define Table (PIC12/16 MCUs) ..............................................................Declare Data of One Byte. p.............Execute If Symbol has not Been Defined ................. p.........Define a Text Substitution Label .....................Store Strings in Program Memory (PIC12/16 MCUs) .................... p.....................Create Numeric and Text Data .................... p....... 57 ÁÁ·¼´±½­ .2............................................ i................................. 65 ý·²½´«¼» ....................... 104 ®¿¼·¨ ...Generate Bank Selecting Code ..................................................... 86 ·º¼»º .. 105 ­»¬ ...... p........................ 85 ÁÁ³¿¨®¿³ .................... ....................Define a Block of Constants............ p..................................................Set Processor Configuration Bits....End Conditional Assembly Block . 4.............Define Maximum ROM Location...... 96 ½¾´±½µ ............................................. p..................Delete a Substitution Label..................................................Execute If Symbol has Been Defined............................. p....................Define an Assembler Variable ...................... p.......2................. p................................................... p...............2 Conditional Assembly Directives Conditional assembly directives permit sections of conditionally assembled code............ They define which code is assembled... 90 ý«²¼»º·²» ......Define Maximum RAM Location .. p....... 88 ·º²¼»º .........3 Data Directives Data directives control the allocation of memory and provide a way to refer to data items symbolically.................. p...com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only....http://www..................................Begin Alternative Assembly Block to ·º Conditional .... p.............................. • • • • • • • »´­» ...........Identify Unimplemented ROM.. • • • • • • • • • • • • • ÁÁ¾¿¼®¿³ ... 47 ÁÁ½±²º·¹ .................... p....... 69 »¯« .......Generate Page Selecting Code Using WREG Commands (PIC10/12/16 MCUs)....Set Processor ID Locations ........ p............ p...Declare EEPROM Data Byte ......... p....End Program Block..... 118 4........... 55 ½±²º·¹ ...................Define an Assembler Constant................................. 46 ÁÁ¾¿¼®±³ ...... p................. p............ 59 ¼¿¬¿ ..... 60 ¼¾ ....2... 102 °¿¹»­»´© . not how the code executes.... p..e............ p............ 52 ¼¿ ................................ 70 »²¼© ........Generate Indirect Bank Selecting Code (PIC12/16 MCUs) ........ 64 ¼¬ ..........Perform Loop While Condition is True ..............

.....................................Declare Local Macro Variable... and other listing control.. 69 º·´´ ........................................ p................................ p...... • • • • • • • • • »®®±® ................................................ 109 ­«¾¬·¬´» ......Generated by Foxit PDF Creator © Foxit Software http://www.........Create User Defined Message ............................ 113 • «¼¿¬¿Á­¸® ..................................Begin an Object File Code Section ........................... p........................................Exit from a Macro.....................Expand Macro Listing .................................................p............ 82 • ·¼¿¬¿Á¿½­ ......... 98 4.Specify Program Title........... p...........com For evaluation only........Export a Label ................................. 110 4................Declare Data of One Word .... 68 »²¼½ ........... p.............................6 Object File Directives Object file directives are used only when creating an object file.....Set Message Level ............... p.................................... p...................................... pagination........................................ 75 »¨°¿²¼ .........................Begin an Object File Initialized Data Section in Access RAM (PIC18 MCUs)..........................................................Issue an Error Message............................... 98 °¿¹» .... 84 • «¼¿¬¿ ............. p...................Begin an Object File Access Uninitialized Data Section (PIC18 MCUs).............Define Table (Extended PIC16 MCUs Only) ................Insert Blank Listing Lines............Specify Program Subtitle ..... p...................................Turn off Listing Output ..4 Listing Directives Listing directives control the MPASM assembler listing file format..................... p............................. These directives allow the specification of titles.................End a Macro Definition.....................End an Automatic Constant Block .......... p..5 Macro Directives Macro directives control the execution and data allocation within macro body definitions...............................Begin an Object File Shared Uninitialized Data Section (PIC12/16 MCUs).............Declare Macro Definition ........... 55 • »¨¬»®² ..................... 101 ­°¿½» .Listing Options ..........................................................p..Reserve Memory... • ¿½½»­­Á±ª® .................. DS33014K-page 45 .........Insert Listing Page Eject ..........Begin an Object File Initialized Data Section .............................. Some listing directives also control how code is assembled..................Begin an Object File Packed Code Section (PIC18 MCUs)..........Specify Program Memory Fill Value .............................................. p................................................ p...2......................... 72 »®®±®´»ª»´ ............. 94 ²±»¨°¿²¼ . p... p........................ p.... 111 • «¼¿¬¿Á±ª® .. p.............. 54 • ½±¼»Á°¿½µ ................ 106 4... p.......................................... p.............................. 82 • ·¼¿¬¿ ...foxitsoftware.. 67 ¼© ........................ 115 2009 Microchip Technology Inc.................Declare an Externally Defined Label .......... p....... 70 »¨·¬³ .Begin an Object File Overlaid Uninitialized Data Section ...................Turn off Macro Expansion ................ 78 • ¹´±¾¿´ .... 110 • «¼¿¬¿Á¿½­ .... p...... p...................................... p.............Begin an Object File Overlay Section in Access RAM (PIC18 MCUs).. 91 ³»­­¹ ........... 46 • ½±¼» ... p.............................................. 80 ®»­ ...... 77 ´±½¿´ ......................... 92 ³¿½®± ........................... 109 ¬·¬´» ............... p......... p...............Begin an Object File Uninitialized Data Section .......2............... p.. p...............................2............................. p......... 73 ´·­¬ ... • • • • • • »²¼³ .......... Directives • • • • • ¼¬³ ........... 96 ²±´·­¬ ..................

foxitsoftware. 4.http://www.3 ¿½½»­­Á±ª® . .5 Simple Example å̸» î ·¼»²¬·½¿´´§ó²¿³»¼ ­»½¬·±²­ ¿®» ±ª»®´¿·¼ ·² Ð×Ýïè ß½½»­­ ÎßÓò åײ ¬¸·­ »¨¿³°´»ô «ïê¿ ·­ ±ª»®´¿·¼ ©·¬¸ ³»³±®§ ´±½¿¬·±²­ «­»¼ 徧 «¿è ¿²¼ «è¾ò «ïê¾ ·­ ±ª»®´¿·¼ ©·¬¸ ³»³±®§ ´±½¿¬·±²­ «­»¼ 徧 «è½ ¿²¼ «è¼ò ³§¿±­½² «è¿æ «è¾æ «è½æ «è¼æ ³§¿±­½² «ïê¿æ «ïê¾æ ¿½½»­­Á±ª® ®»­ ï ®»­ ï ®»­ ï ®»­ ï ¿½½»­­Á±ª® ®»­ î ®»­ î 4. For information on types of code.6 “Assembler Operation”.4.2 Description This directive declares the beginning of a section of overlay data in Access RAM. 4.3. ¿½½»­­Á±ª® is similar to «¼¿¬¿Á¿½­ and «¼¿¬¿Á±ª®.IDENTIFY UNIMPLEMENTED RAM Note: ¾¿¼®¿³ is preceded by two underline characters.3 Usage This directive is used in the following types of code: relocatable.3. 4.4 See Also »¨¬»®² ¹´±¾¿´ «¼¿¬¿ «¼¿¬¿Á±ª® «¼¿¬¿Á¿½­ 4.4 ÁÁ¾¿¼®¿³ . see Section 1.3.3.1 Syntax Å´¿¾»´Ã ¿½½»­­Á±ª® ÅÎßÓÁ¿¼¼®»­­Ã 4. 4. The space declared by this section is overlaid by all other ¿½½»­­Á±ª® sections of the same name. No code can be placed by the user in this segment.3. uninitialized-data section that can be overlaid with other overlay access sections of the same name. Overlaying access sections allows you to reuse access-bank data space.BEGIN AN OBJECT FILE OVERLAY SECTION IN ACCESS RAM (PIC18 MCUs) 4. The starting address is initialized to the specified address or will be assigned at link time if no address is specified.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. the section is named ò¿½½»­­Á±ª®. except that it declares a PIC18 Access-RAM. If ´¿¾»´ is not specified.1 Syntax ÁÁ¾¿¼®¿³ »¨°®Å󻨰®ÃÅô »¨°®Å󻨰®Ãà DS33014K-page 46 2009 Microchip Technology Inc.

foxitsoftware.5. For information on types of code. 4.6 “Assembler Operation”.1 Syntax ÁÁ¾¿¼®±³ »¨°®Å󻨰®ÃÅô »¨°®Å󻨰®Ãà 4. use the syntax ³·²´±½ . 4.³¿¨´±½. 4. strict ROM address checking is enabled.4. and falls in a bad ROM region • the target of an ÔÙÑÌÑ or ÔÝßÔÔ pseudo-op is evaluated by the assembler to a constant. Each »¨°® must be less than or equal to the value specified by ÁÁ³¿¨®±³. A ÁÁ³¿¨®¿³ directive must precede any ÁÁ¾¿¼®¿³ directive.4.Generated by Foxit PDF Creator © Foxit Software http://www. Directives 4. To specify a range of invalid locations.4.4. A ÁÁ³¿¨®±³ directive must precede any ÁÁ¾¿¼®±³ directive. ÁÁ¾¿¼®¿³ defines the locations of invalid RAM addresses. Once the ÁÁ³¿¨®¿³ directive is used.com For evaluation only. and part of an instruction falls in a bad ROM region 2009 Microchip Technology Inc. ÁÁ¾¿¼®¿³ is not commonly used. see Section 1. DS33014K-page 47 .IDENTIFY UNIMPLEMENTED ROM Note: ¾¿¼®±³ is preceded by two underline characters.4 ÁÁ³¿¨®¿³ See Also 4. To specify a range of invalid locations.³¿¨´±½. Each »¨°® must be less than or equal to the value specified by ÁÁ³¿¨®¿³. a warning will be raised in the following circumstances: • the target of a ÙÑÌÑ or ÝßÔÔ instruction is evaluated by the assembler to a constant. ÁÁ¾¿¼®±³ defines the locations of invalid ROM addresses. using the ROM map specified by ÁÁ¾¿¼®±³. This directive is designed for use with the ÁÁ³¿¨®¿³ directive. strict RAM address checking is enabled.5.5 Simple Example ý·²½´«¼» °ïê½êîîò·²½ ÁÁ³¿¨®¿³ ð¨ðÞÚ ÁÁ¾¿¼®¿³ ð¨ðéóð¨ðçô ð¨ðÜóð¨Û ÁÁ¾¿¼®¿³ ð¨èéóð¨èçô ð¨èÜô ð¨èÚóð¨çÛ ³±ª©º ð¨ðé å Ù»²»®¿¬»­ ·²ª¿´·¼ ÎßÓ ©¿®²·²¹ ³±ª©º ð¨èé å Ù»²»®¿¬»­ ·²ª¿´·¼ ÎßÓ ©¿®²·²¹ å ¿²¼ ¬®«²½¿¬·±² ³»­­¿¹» 4.5 ÁÁ¾¿¼®±³ . This directive is designed for use with the ÁÁ³¿¨®±³ directive.3 Usage This directive is used in the following types of code: absolute or relocatable. and falls in a bad ROM region • a ò¸»¨ file is being generated. using the RAM map specified by ÁÁ¾¿¼®¿³. as RAM and ROM details are handled by the include files (öò·²½) or linker script files (öò´µ®). use the syntax ³·²´±½ . Once the ÁÁ³¿¨®±³ directive is used. Specifically.2 Description The ÁÁ³¿¨®±³ and ÁÁ¾¿¼®±³ directives together flag accesses to unimplemented registers.2 Description The ÁÁ³¿¨®¿³ and ÁÁ¾¿¼®¿³ directives together flag accesses to unimplemented registers.

see Section 1. No operations can be performed on ´¿¾»´. For information on types of code. .1 Syntax ¾¿²µ·­»´ ´¿¾»´ 4. ÁÁ¾¿¼®±³ is not commonly used.5. But for PIC16 extended instructions.6. The linker will generate the appropriate bank selecting code.5.6 “Assembler Operation”. as RAM and ROM details are handled by the include files (öò·²½) or linker script files (öò´µ®). This label must have been previously defined.6.4 See Also ¾¿²µ­»´ °¿¹»­»´ 4. This directive may be used with 14-bit instruction width PIC1X devices. For information on types of code.5. see Section 1.6.3 Usage This directive is used in the following types of code: absolute or relocatable.4 ÁÁ³¿¨®±³ See Also 4.6. the appropriate bit set/clear instruction on the IRP bit in the STATUS register will be generated. 4.6 ¾¿²µ·­»´ .foxitsoftware. Only one ´¿¾»´ should be specified.6 “Assembler Operation”. This excludes 12-bit instruction width devices and PIC18 devices.3 Usage This directive is used in the following types of code: absolute or relocatable. no code will be generated.2 Description This directive is an instruction to the assembler or linker to generate the appropriate bank selecting code for an indirect access of the register address specified by ´¿¾»´.GENERATE INDIRECT BANK SELECTING CODE (PIC12/16 MCUs) 4. FSR0H is modified instead of IRP bit (as there is no IRP bit).5 Simple Example åÔ±¿¼ ¬¸» ¿¼¼®»­­ ±º Ê¿®ï ·²º± ÚÍÎ åÍ»´»½¬ ¬¸» ½±®®»½¬ ¾¿²µ º±® Ê¿®ï åײ¼·®»½¬´§ ©®·¬» ¬± Ê¿®ï ³±ª´© Ê¿®ï ³±ª©º ÚÍÎ ¾¿²µ·­»´ Ê¿®ï æ ³±ª©º ×ÒÜÚ DS33014K-page 48 2009 Microchip Technology Inc. For 14-bit instruction width (most PIC12/PIC16) devices. 4. If the indirect address can be specified without these instructions.http://www. 4.5 Simple Example ý·²½´«¼» °ïî½ëðèò·²½ ÁÁ³¿¨®±³ ð¨ïÚÚ ÁÁ¾¿¼®±³ ð¨î ó ð¨ìô ð¨ß ±®¹ ð¨ë ¹±¬± ð¨î å ¹»²»®¿¬»­ ¿ ©¿®²·²¹ ½¿´´ ð¨í å ¹»²»®¿¬»­ ¿ ©¿®²·²¹ ±®¹ ð¨ß ³±ª´© ë å ¹»²»®¿¬»­ ¿ ©¿®²·²¹ 4.6. 4.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only.

DS33014K-page 49 .6 Application Example .foxitsoftware.Generated by Foxit PDF Creator © Foxit Software http://www.6. ý·²½´«¼» °ïêºèéé¿ò·²½ åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò å¹®±«°ï ¼¿¬¿ å­¬¿®¬·²¹ ¿¬ å¹®±«°ïÁª¿®ï å¹®±«°ïÁª¿®î å¹®±«°î ¼¿¬¿ å­¬¿®¬·²¹ ¿¬ å¹®±«°îÁª¿®ï å¹®±«°îÁª¿®î ­¬±®»¼ ¿¬ ´±½¿¬·±²­ ð¨îð ø×ÎÐ ¾·¬ ð÷ò ´±½¿¬»¼ ¿¬ ð¨îðò ´±½¿¬»¼ ¿¬ ð¨îïò ­¬±®»¼ ¿¬ ´±½¿¬·±²­ ð¨ïîð ø×ÎÐ ¾·¬ ï÷ò ´±½¿¬»¼ ¿¬ ð¨ïîðò ´±½¿¬»¼ ¿¬ ð¨ïîïò ¹®±«°ï «¼¿¬¿ ð¨îð ®»­ ®»­ ð¨ïîð ®»­ ®»­ ð¨ð ï ï ï ï ¹®±«°ïÁª¿®ï ¹®±«°ïÁª¿®î ¹®±«°î «¼¿¬¿ ¹®±«°îÁª¿®ï ¹®±«°îÁª¿®î ÎÍÌ ÝÑÜÛ °¿¹»­»´ ¹±¬± ÐÙÓ ÝÑÜÛ ­¬¿®¬ ­¬¿®¬ å̸» ½±¼» ­»½¬·±² ²¿³»¼ ÎÍÌ å·­ °´¿½»¼ ¿¬ °®±¹®¿³ ³»³±®§ å´±½¿¬·±² ð¨ðò ̸» ²»¨¬ ¬©± å·²­¬®«½¬·±²­ ¿®» °´¿½»¼ ·² å½±¼» ­»½¬·±² ÎÍÌò åÖ«³°­ ¬± ¬¸» ´±½¿¬·±² ´¿¾»´´»¼ 厭¬¿®¬Žò å̸·­ ·­ ¬¸» ¾»¹·²²·²¹ ±º ¬¸» å½±¼» ­»½¬·±² ²¿³»¼ ÐÙÓò ׬ ·­ å¿ ®»´±½¿¬¿¾´» ½±¼» ­»½¬·±² å­·²½» ²± ¿¾­±´«¬» ¿¼¼®»­­ ·­ å¹·ª»² ¿´±²¹ ©·¬¸ ¼·®»½¬·ª» ÝÑÜÛò ­¬¿®¬ ³±ª´© ð¨îð ³±ª©º ÚÍÎ ¾¿²µ·­»´ ¹®±«°ïÁª¿®ï ½´®º ×ÒÜÚ ·²½º ÚÍÎôÚ ½´®º ×ÒÜÚ ³±ª©º ÚÍÎ ¾¿²µ·­»´ ¹®±«°îÁª¿®ï ½´®º ×ÒÜÚ ·²½º ÚÍÎôÚ ½´®º ×ÒÜÚ ¹±¬± »²¼ ü å̸·­ °¿®¬ ±º ¬¸» ½±¼» ¿¼¼®»­­»­ 媿®·¿¾´»­ ¹®±«°ïÁª¿®ï ú å¹®±«°ïÁª¿®î ·²¼·®»½¬´§ò åÙ± ¬± ½«®®»²¬ ´·²» ø´±±° ¸»®»÷ 2009 Microchip Technology Inc. Directives 4.¾¿²µ·­»´ This program demonstrates the ¾¿²µ·­»´ directive.com For evaluation only. This directive generates the appropriate code to set/clear the IRP bit of the STATUS register for an indirect access.

the appropriate bit set/clear instructions on the FSR will be generated.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only.http://www. This directive may be used with all PIC1X devices.7 ¾¿²µ­»´ .7. For 14-bit instruction width (most PIC12/PIC16) devices. 4. bit set/clear instructions on the STATUS register will be generated.7.4 See Also ¾¿²µ·­»´ °¿¹»­»´ 4.5 Simple Example åÍ»´»½¬ ¬¸» ½±®®»½¬ ¾¿²µ º±® Ê¿®ï åÉ®·¬» ¬± Ê¿®ï ¾¿²µ­»´ Ê¿®ï ³±ª©º Ê¿®ï DS33014K-page 50 2009 Microchip Technology Inc.7.1 Syntax ¾¿²µ­»´ ´¿¾»´ 4.2 Description This directive is an instruction to the assembler and linker to generate bank selecting code to set the bank to the bank containing the designated ´¿¾»´.7 Application Example 2 . Only one ´¿¾»´ should be specified. This label must have been previously defined.7. No operations can be performed on ´¿¾»´. see Section 1.) 4. a ³±ª´¾ will be generated.foxitsoftware. The linker will generate the appropriate bank selecting code: For 12-bit instruction width (PIC10F. For information on types of code. If the device contains only one bank of RAM.¾¿²µ·­»´ åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò å̸·­ ®»¹·­¬»® ·­ ¿¬ ´±½¿¬·±² ïðð¸ å·² ¾¿²µ­ î ±® í ­± ¬¸» ×ÎÐ ¾·¬ 峫­¬ ¾» ­»¬ò ¾¿²µ·­»´ ©·´´ ­»¬ ·¬ 徫¬ ±²´§ ©¸»®» ·¬ ·­ «­»¼ò åЫ¬ ¬¸» ¿¼¼®»­­ ±º ¬¸» ®»¹·­¬»® ¬± å¾» ¿½½»­­»¼ ·²¼·®»½¬´§ ·²¬± Éò åݱ°§ ¿¼¼®»­­ º®±³ É ¬± ÚÍÎ ¬± ­»¬ å«° °±·²¬»® ¬± ÛÛßÜÎò åÝ´»¿® ÛÛßÜÎ ¬¸®±«¹¸ ·²¼·®»½¬ 忽½»­­·²¹ ±º ÛÛßÜÎ ¬¸®±«¹¸ ÚÍÎñ×ÒÜÚò å׬ ©±«´¼ ¸¿ª» ½´»¿®»¼ Ð×Îî øððܸ÷ å·º ¾¿½µ·­»´ ¸¿¼ ²±¬ ¾»»² «­»¼ ¬± å­»¬ ¬¸» ×ÎÐ ¾·¬ò åЮ»ª»²¬­ º¿´´ ±ºº »²¼ ±º ½±¼»ò åß´´ ½±¼» ³«­¬ ¸¿ª» ¿² »²¼ ­¬¿¬»³»²¬ò ý·²½´«¼» °ïêºèéé¿ò·²½ ¾¿²µ·­»´ ÛÛßÜÎ ³±ª´© ³±ª©º ½´®º ÛÛßÜÎôÉ ÚÍÎ ×ÒÜÚ ¹±¬± »²¼ ü 4. no instructions will be generated.6. This directive is not needed for variables in access RAM (PIC18 devices. For PIC16 extended and PIC18 devices.3 Usage This directive is used in the following types of code: absolute or relocatable.6 “Assembler Operation”. 4. . some PIC12/PIC16) devices.7.GENERATE BANK SELECTING CODE 4.

7.6 Application Example .foxitsoftware.com For evaluation only. DS33014K-page 51 . ý·²½´«¼» °ïêºèéé¿ò·²½ åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò å¹®±«°ï ¼¿¬¿ å­¬¿®¬·²¹ ¿¬ å¹®±«°ïÁª¿®ï å¹®±«°ïÁª¿®î ­¬±®»¼ ¿¬ ´±½¿¬·±²­ ð¨îð ø¾¿²µ ð÷ò ´±½¿¬»¼ ¿¬ ð¨îðò ´±½¿¬»¼ ¿¬ ð¨îïò ¹®±«°ï «¼¿¬¿ ð¨îð ®»­ ®»­ ð¨ßð ®»­ ®»­ ð¨ð ï ï ï ï ¹®±«°ïÁª¿®ï ¹®±«°ïÁª¿®î ¹®±«°î «¼¿¬¿ å¹®±«°î ¼¿¬¿ ­¬±®»¼ ¿¬ ´±½¿¬·±²­ å­¬¿®¬·²¹ ¿¬ ð¨ßð ø¾¿²µ ï÷ ¹®±«°îÁª¿®ï ¹®±«°îÁª¿®î ÎÍÌ ÝÑÜÛ °¿¹»­»´ ¹±¬± ÐÙÓ ÝÑÜÛ ­¬¿®¬ ­¬¿®¬ å̸» ½±¼» ­»½¬·±² ²¿³»¼ ÎÍÌ å·­ °´¿½»¼ ¿¬ °®±¹®¿³ ³»³±®§ å´±½¿¬·±² ð¨ðò ̸» ²»¨¬ ¬©± å·²­¬®«½¬·±²­ ¿®» °´¿½»¼ ·² å½±¼» ­»½¬·±² ÎÍÌò åÖ«³°­ ¬± ¬¸» ´±½¿¬·±² ´¿¾»´´»¼ 厭¬¿®¬Žò å̸·­ ·­ ¬¸» ¾»¹·²²·²¹ ±º ¬¸» å½±¼» ­»½¬·±² ²¿³»¼ ÐÙÓò ׬ ·­ å¿ ®»´±½¿¬¿¾´» ½±¼» ­»½¬·±² å­·²½» ²± ¿¾­±´«¬» ¿¼¼®»­­ ·­ å¹·ª»² ¿´±²¹ ©·¬¸ ¼·®»½¬·ª» ÝÑÜÛò ­¬¿®¬ ¾¿²µ­»´ ¹®±«°ïÁª¿®ï å̸·­ ¼·®»½¬·ª» ¹»²»®¿¬»­ ½±¼» 嬱 ­»¬ñ½´»¿® ¾¿²µ ­»´»½¬ ¾·¬­ åÎÐð ú ÎÐï ±º ÍÌßÌËÍ ®»¹·­¬»® å¼»°»²¼·²¹ «°±² ¬¸» ¿¼¼®»­­ ±º å¹®±«°ïÁª¿®ïò ½´®º ½´®º ¹®±«°ïÁª¿®ï ¹®±«°ïÁª¿®î ¹®±«°îÁª¿®ï å̸·­ ¼·®»½¬·ª» ¹»²»®¿¬»­ ½±¼» 嬱 ­»¬ñ½´»¿® ¾¿²µ ­»´»½¬ ¾·¬­ åÎÐð ú ÎÐï ±º ÍÌßÌËÍ ®»¹·­¬»® å¼»°»²¼·²¹ «°±² ¬¸» ¿¼¼®»­­ ±º å¹®±«°îÁª¿®ïò ¾¿²µ­»´ ½´®º ½´®º ¹±¬± »²¼ ¹®±«°îÁª¿®ï ¹®±«°îÁª¿®î ü åÙ± ¬± ½«®®»²¬ ´·²» ø´±±° ¸»®»÷ 2009 Microchip Technology Inc.Generated by Foxit PDF Creator © Foxit Software http://www.¾¿²µ­»´ This program demonstrates the ¾¿²µ­»´ directive. Directives 4. This directive generates the appropriate code to set/clear the RP0 and RP1 bits of the STATUS register.

If no expression is found.1 Syntax ½¾´±½µ Å»¨°®Ã ´¿¾»´Åæ·²½®»³»²¬ÃÅô´¿¾»´Åæ·²½®»³»²¬Ãà »²¼½ 4.3 Usage This directive is used in the following types of code: absolute.http://www. Use this directive in place of or in addition to the »¯« directive.8 ½¾´±½µ . The purpose of this directive is to assign address offsets to many labels.8.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. The list of names end when an »²¼½ directive is encountered. the first name will receive a value one higher than the final name in the previous ½¾´±½µ.8. For information on types of code.8.6 “Assembler Operation”.4 »²¼½ »¯« See Also DS33014K-page 52 2009 Microchip Technology Inc.8. When creating non-relocatable (absolute) code. ½¾´±½µ is useful for defining constants in program and data memory for absolute code generation. 4. separated by commas. Do not use ½¾´±½µ or »¯« to define variable location names for relocatable code.7.2 Description Defines a list of named sequential symbols. Multiple names may be given on a line. see Section 1. then the next ´¿¾»´ is assigned the value of ·²½®»³»²¬ higher than the previous ´¿¾»´. 4. 4.¾¿²µ­»´ åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò åÍ·²½» ¬¸·­ ®»¹·­¬»® ·­ ·² ¾¿²µ ïô å²±¬ ¼»º¿«´¬ ¾¿²µ ðô ¾¿²µ­»´ ·­ å«­»¼ ¬± »²­«®» ¾¿²µ ¾·¬­ ¿®» ½±®®»½¬ò åÝ´»¿® ÌÎ×ÍÞò Í»¬­ ÐÑÎÌÞ ¬± ±«¬°«¬­ò 徿²µ­»´ «­»¼ ¬± ®»¬«®² ¬± ¾¿²µ ðô 婸»®» ÐÑÎÌÞ ·­ ´±½¿¬»¼ò åÍ»¬ ÐÑÎÌÞ ª¿´«»ò ý·²½´«¼» °ïêºèéé¿ò·²½ ¾¿²µ­»´ ÌÎ×ÍÞ ½´®º ÌÎ×ÍÞ ¾¿²µ­»´ ÐÑÎÌÞ ³±ª´© ³±ª©º ¹±¬± »²¼ ð¨ëë ÐÑÎÌÞ ü åß´´ °®±¹®¿³­ ³«­¬ ¸¿ª» ¿² »²¼ò 4.foxitsoftware.DEFINE A BLOCK OF CONSTANTS 4. If ·²½®»³»²¬ is specified.7 Application Example 2 . If the first cblock in the source file has no »¨°®. . assigned values start with zero. ½¾´±½µ is often used to define variable address location names. »¨°® indicates the starting value for the first name in the block.

20H and 21H). The same directives can be used for program memory space also.8.Generated by Foxit PDF Creator © Foxit Software http://www. DS33014K-page 53 . Directives 4. Length and width of the rectangle will be stored in buffers addressed by ´»²¹¬¸ (22H) and ©·¼¬¸ (23H). The calculated perimeter will be stored in the double-precision buffer addressed by °»®·³»¬»® (i. The program calculates the perimeter of a rectangle.½¾´±½µ/»²¼½ This example shows the usage of ÝÞÔÑÝÕ and ÛÒÜÝ directives for defining constants or variables in data memory space.5 Simple Example å ²¿³»Áï ©·´´ ¾» ¿­­·¹²»¼ îð å ²¿³»Áîô îï ¿²¼ ­± ±² å ²¿³»Áì ·­ ¿­­·¹²»¼ îíò ½¾´±½µ ð¨î𠲿³»Áïô ²¿³»Áî ²¿³»Áíô ²¿³»Áì »²¼½ ½¾´±½µ ð¨íð Ì©±Þ§¬»Ê¿®æ ðô Ì©±Þ§¬»Ø·¹¸ô Ì©±Þ§¬»Ô±© åÌ©±Þ§¬»Ê¿® ãð¨íð åÌ©±Þ§¬»Ø·¹¸ãð¨íð åÌ©±Þ§¬»Ô±© ãð¨íï Ï«»«»æ ÏËÛËÛÁÍ×ÆÛ Ï«»«»Ø»¿¼ô Ï«»«»Ì¿·´ ܱ«¾´»ïæîô ܱ«¾´»îæî »²¼½ 4.8. ý·²½´«¼» °ïêºèéé¿ò·²½ ÝÞÔÑÝÕ ð¨îð åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò åÜ»º·²» ¿ ¾´±½µ ±º ª¿®·¿¾´»­ å­¬¿®¬·²¹ ¿¬ îðØ ·² ¼¿¬¿ ³»³±®§ò å̸» ´¿¾»´ °»®·³»¬»® ·­ î ¾§¬»­ å©·¼»ò ß¼¼®»­­ îðØ ¿²¼ îïØ ·­ å¿­­·¹²»¼ ¬± ¬¸» ´¿¾»´ °»®·³»¬»®ò åß¼¼®»­­ îîØ ·­ ¿­­·¹²»¼ ¬± ¬¸» å´¿¾»´ ´»²¹¬¸ò åß¼¼®»­­ îíØ ·­ ¿­­·¹²»¼ ¬± ¬¸» å´¿¾»´ ©·¼¬¸ò å̸·­ ¼·®»½¬·ª» ³«­¬ ¾» ­«°°´·»¼ 嬱 ¬»®³·²¿¬» ¬¸» ÝÞÔÑÝÕ ´·­¬ò åÝ´»¿® °»®·³»¬»® ¸·¹¸ ¾§¬» 忬 ¿¼¼®»­­ îïØò åÓ±ª» ¬¸» ¼¿¬¿ °®»­»²¬ ·² ¬¸» å®»¹·­¬»® ¿¼¼®»­­»¼ ¾§ ù´»²¹¬¸ù 嬱 ù©ù åß¼¼ ¼¿¬¿ ·² ù©ù ©·¬¸ ¼¿¬¿ ·² ¬¸» å®»¹·­¬»® ¿¼¼®»­­»¼ ¾§ ù©·¼¬¸ùò åÍÌßÌËÍ ®»¹·­¬»® ½¿®®§ ¾·¬ Ý å³¿§ ¾» ¿ºº»½¬»¼ò åÓ±ª» ù©ù ¬± ¬¸» °»®·³»¬»® ´±© 徧¬» ¿¬ ¿¼¼®»­­ îðØò Ý¿®®§ ¾·¬ å·­ «²¿ºº»½¬»¼ò åײ½®»³»²¬ ®»¹·­¬»® îïØ ·º ½¿®®§ å©¿­ ¹»²»®¿¬»¼ò ß´­± ½´»¿® ½¿®®§ å·º ¾·¬ ©¿­ ­»¬ò åÓ«´¬·°´§ ®»¹·­¬»® îðØ ¾§ îò åÝ¿®®§ ¾·¬ ³¿§ ¾» ¿ºº»½¬»¼ò åß¹¿·²ô ·²½®»³»²¬ ®»¹·­¬»® îïØ å·º ½¿®®§ ©¿­ ¹»²»®¿¬»¼ò åÙ± ¬± ½«®®»²¬ ´·²» ø´±±° ¸»®»÷ °»®·³»¬»®æî ´»²¹¬¸ ©·¼¬¸ ÛÒÜÝ ½´®º ³±ªº °»®·³»¬»®õï ´»²¹¬¸ô© ¿¼¼©º ©·¼¬¸ô© ³±ª©º °»®·³»¬»® ®´º °»®·³»¬»®õï ®´º ®´º ¹±¬± »²¼ ü °»®·³»¬»® °»®·³»¬»®õï 2009 Microchip Technology Inc.e.6 Application Example .com For evaluation only.foxitsoftware..

Note: Two sections in a source file may not have the same name. If ´¿¾»´ is not specified.6 “Assembler Operation”. 4.http://www.9.1 Syntax Å´¿¾»´Ã ½±¼» ÅÎÑÓÁ¿¼¼®»­­Ã 4. .9.9.3 Usage This directive is used in the following types of code: relocatable.4 See Also »¨¬»®² ½±¼»Á°¿½µ ¹´±¾¿´ ·¼¿¬¿ «¼¿¬¿ «¼¿¬¿Á¿½­ «¼¿¬¿Á±ª® «¼¿¬¿Á­¸® 4. the section is named ò½±¼». which declares the beginning of a section of program code. For information on types of code.9.BEGIN AN OBJECT FILE CODE SECTION 4.½±¼» This program demonstrates the ½±¼» directive. 4.foxitsoftware. The code of a section ends automatically when another code or data section is defined or when the end of the file is reached. The starting address is initialized to the specified address or will be assigned at link time if no address is specified.9. There is no “end code” directive.9 ½±¼» . see Section 1.2 Description This directive declares the beginning of a section of program code.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. ý·²½´«¼» °ïêºèéé¿ò·²½ åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò å̸» ½±¼» ­»½¬·±² ²¿³»¼ ÎÍÌ å·­ °´¿½»¼ ¿¬ °®±¹®¿³ ³»³±®§ å´±½¿¬·±² ð¨ðò ̸» ²»¨¬ ¬©± å·²­¬®«½¬·±²­ ¿®» °´¿½»¼ ·² å½±¼» ­»½¬·±² ÎÍÌò åÖ«³°­ ¬± ¬¸» ´±½¿¬·±² ´¿¾»´´»¼ 厭¬¿®¬Žò å̸·­ ·­ ¬¸» ¾»¹·²²·²¹ ±º ¬¸» å½±¼» ­»½¬·±² ²¿³»¼ ÐÙÓò ׬ ·­ å¿ ®»´±½¿¬¿¾´» ½±¼» ­»½¬·±² å­·²½» ²± ¿¾­±´«¬» ¿¼¼®»­­ ·­ å¹·ª»² ¿´±²¹ ©·¬¸ ¼·®»½¬·ª» ÝÑÜÛò ÎÍÌ ÝÑÜÛ ð¨ð °¿¹»­»´ ¹±¬± ÐÙÓ ÝÑÜÛ ­¬¿®¬ ­¬¿®¬ ­¬¿®¬ ½´®© ¹±¬± ü ÝÑÜÛ åÙ± ¬± ½«®®»²¬ ´·²» ø´±±° ¸»®»÷ å̸·­ ·­ ¿ ®»´±½¿¬¿¾´» ½±¼» å­»½¬·±² ­·²½» ²± ¿¼¼®»­­ ·­ å­°»½·º·»¼ò ̸» ­»½¬·±² ²¿³» ©·´´ å¾»ô ¾§ ¼»º¿«´¬ô ò½±¼»ò ²±° »²¼ DS33014K-page 54 2009 Microchip Technology Inc.5 Simple Example ÎÛÍÛÌ ½±¼» ð¨ðïÚÚ ¹±¬± ÍÌßÎÌ 4.9.6 Application Example . 4.

4 See Also »¨¬»®² ½±¼» ¹´±¾¿´ ·¼¿¬¿ «¼¿¬¿ «¼¿¬¿Á¿½­ «¼¿¬¿Á±ª® «¼¿¬¿Á­¸® 4. Directives 4.10.SET PROCESSOR CONFIGURATION BITS Note: ½±²º·¹ is preceded by two underline characters. If ´¿¾»´ is not specified.6 “Assembler Operation”.Generated by Foxit PDF Creator © Foxit Software http://www.5 Simple Example ððððï Ô×ÍÌ Ðãïèݨ¨ ððððî ððððí °¿½µ»¼ ½±¼»Á°¿½µ ð¨ïÚð ððððì ÜÞ ïô îô í ððððë ÜÞ ìô ë ððððê ððððé °¿¼¼»¼ ½±¼» ððððè ÜÞ ïô îô í ððððç ÜÞ ìô ë ðððïð ðððïï ÛÒÜ ðððïÚð ðï ðî ðí ðððïÚí ðì ðë ðððððð ðîðï ðððí ðððððì ðëðì 4.BEGIN AN OBJECT FILE PACKED CODE SECTION (PIC18 MCUs) 4. the section is named ò½±¼». If ÎÑÓÁ¿¼¼®»­­ is specified. Note: Two sections in a source file may not have the same name 4.com For evaluation only. see Section 1.) Supported: ÁÁº«­»­ »¨°® 2009 Microchip Technology Inc. For information on types of code. it must be word-aligned.11 ÁÁ½±²º·¹ . This directive is commonly used when storing data into program memory (use with ¼¾) or the EEPROM data memory (use with ¼») of a PIC18 device. 4.1 Syntax Preferred: ÁÁ½±²º·¹ »¨°® ÁÁ½±²º·¹ ¿¼¼®ô »¨°® Note: PIC18FXXJ devices do not support this directive. If padded data is desired.10.10.10. use ¼¾.11.foxitsoftware. The starting address is initialized to ÎÑÓÁ¿¼¼®»­­ or will be assigned at link time if no address is specified.2 Description This directive declares the beginning of a section of program code or ROM data where a padding byte of zero is not appended to an odd number of bytes.1 Syntax Å´¿¾»´Ã ½±¼»Á°¿½µ ÅÎÑÓÁ¿¼¼®»­­Ã 4. DS33014K-page 55 . 4.10 ½±¼»Á°¿½µ .10. Use ½±²º·¹ directive (no underline characters.3 Usage This directive is used in the following types of code: relocatable.

For information on types of code. MCUs with a single configuration register Sets the processor's configuration bits to the value described by »¨°®.11. it is recommended that you use the ½±²º·¹ directive (no underline characters.6 “Assembler Operation”. This is useful when giving your files to a third-party programming house.2 Description Sets the processor's configuration bits. Although this directive may be used to set configuration bits for PIC18 MCU devices. the processor must be declared through the command line. 4. Note: Configuration bits must be listed in ascending order.11. MCUs with multiple configuration registers For the address of a valid configuration byte specified by ¿¼¼®. This directive is placed in source code so that. the configuration values are preset to desired values in your application. Use the configuration options (names) in the standard include (öò·²½) file. Refer to individual PIC1X microcontroller data sheets for a description of the configuration bits. Note: Do not mix ÁÁ½±²º·¹ and ½±²º·¹ directives in the same code. 4. as this helps insure the device is configured correctly when programmed. 4. .4 See Also ½±²º·¹ ÁÁ·¼´±½­ ´·­¬ °®±½»­­±® 4.foxitsoftware.11.) For PIC18FXXJ devices. Before this directive is used.http://www. the processor directive or Configure>Select Device if using MPLAB IDE.3 Usage This directive is used in the following types of code: absolute or relocatable. Place configuration bit assignments at the beginning of your code.5 Simple Examples Example 1: PIC16 Devices ý·²½´«¼» °ïêºèéé¿ò·²½ å·²½´«¼» º·´» ©·¬¸ ½±²º·¹ ¾·¬ ¼»º·²·¬·±²­ ÁÁ½±²º·¹ ÁØÍÁÑÍÝ ú ÁÉÜÌÁÑÚÚ ú ÁÔÊÐÁÑÚÚ åÍ»¬ ±­½·´´¿¬±® ¬± ØÍô å©¿¬½¸¼±¹ ¬·³» ±ººô å´±©óª±´¬¿¹» °®±¹ò ±ºº Example 2: PIC17X Devices ý·²½´«¼» °ïé½ìîò·²½ ÁÁ½±²º·¹ ð¨ÚÚÚÚ å·²½´«¼» º·´» ©·¬¸ ½±²º·¹ ¾·¬ ¼»º·²·¬·±²­ å¼»º¿«´¬ ½±²º·¹«®¿¬·±² ¾·¬­ DS33014K-page 56 2009 Microchip Technology Inc. These names can be bitwise ANDed together using & to declare multiple configuration bits. see Section 1.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. you must use the ½±²º·¹ directive. when the code is assembled into a hex file. the list directive. sets the configuration bits to the value described by »¨°®.11.

3 Usage This directive is used in the following types of code: absolute or relocatable. Multiple settings may be defined on a single line.com For evaluation only.12.SET PROCESSOR CONFIGURATION BITS (PIC18 MCUs) 4.6 “Assembler Operation”. see Section 1. Settings for a single configuration byte may also be defined on separate lines. For information on types of code.2 Description Defines a list of configuration bit setting definitions. 2009 Microchip Technology Inc. Directives Example 3: PIC18 Devices ý·²½´«¼» °ïè½ìëîò·²½ åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò å½±¼» °®±¬»½¬ ¼·­¿¾´»¼ò ÁÁÝÑÒÚ×Ù ÁÝÑÒÚ×Ùðô ÁÝÐÁÑÚÚÁð åÑ­½·´´¿¬±® ­©·¬½¸ ¼·­¿¾´»¼ô ÎÝ ±­½·´´¿¬±® ©·¬¸ ÑÍÝî å¿­ ×ñÑ °·²ò ÁÁÝÑÒÚ×Ù ÁÝÑÒÚ×Ùïô ÁÑÍÝÍÁÑÚÚÁï ú ÁÎÝ×ÑÁÑÍÝÁï åÞ®±©²óÑ«¬Î»­»¬ »²¿¾´»¼ô ÞÑΠʱ´¬¿¹» ·­ îòëª ÁÁÝÑÒÚ×Ù ÁÝÑÒÚ×Ùîô ÁÞÑÎÁÑÒÁî ú ÁÞÑÎÊÁîëÁî åÉ¿¬½¸ ܱ¹ Ì·³»® »²¿¾´»ô É¿¬½¸ ܱ¹ Ì·³»® б­¬Í½¿´»® å½±«²¬ ó ïæïîè ÁÁÝÑÒÚ×Ù ÁÝÑÒÚ×Ùíô ÁÉÜÌÁÑÒÁí ú ÁÉÜÌÐÍÁïîèÁí åÝÝÐî °·² Ó«¨ »²¿¾´»¼ ÁÁÝÑÒÚ×Ù ÁÝÑÒÚ×Ùëô ÁÝÝÐîÓÈÁÑÒÁë åͬ¿½µ ±ª»®ñ«²¼»®º´±© λ­»¬ »²¿¾´»¼ ÁÁÝÑÒÚ×Ù ÁÝÑÒÚ×Ùêô ÁÍÌÊÎÁÑÒÁê 4. Note: Do not mix ÁÁ½±²º·¹ and ½±²º·¹ directives in the same code. the list directive.12 ½±²º·¹ .12. DS33014K-page 57 . Available settings and values maybe found in both the standard processor include (öò·²½) files and the PIC18 Configuration Settings Addendum (DS51537). Another directive that may be used to set configuration bits for PIC18 MCU devices is the ÁÁ½±²º·¹ directive.foxitsoftware. This is useful when giving your files to a third-party programming house. This directive is placed in source code so that. Refer to individual PIC18 microcontroller data sheets for a description of the configuration bits. the configuration values are preset to desired values in your application. the processor directive or Configure>Select Device in MPLAB IDE. Before this directive is used. separated by commas.1 ½±²º·¹ Syntax ­»¬¬·²¹ãª¿´«» Åô ­»¬¬·²¹ãª¿´«»Ã 4. 4. as this helps insure the device is configured correctly when programmed. but this is not recommended for new code. This list sets the PIC18 processor's configuration bits represented by ­»¬¬·²¹ to a value described by ª¿´«».12. a PIC18 MCU must be declared through the command line.Generated by Foxit PDF Creator © Foxit Software http://www. when the code is compiled/assembled into a hex file.

Otherwise.12. Place configuration bit assignments at the beginning of your code.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only.foxitsoftware. Use the configuration options (­»¬¬·²¹=ª¿´«» pairs) listed in the standard include (öò·²½) file or the addendum. and the expression must be fully resolvable at the time of the assignment.13.2 Description Creates symbols for use in MPASM assembler expressions.3 Usage This directive is used in the following types of code: absolute or relocatable. or created by the ­»¬ directive.1 Syntax ½±²­¬¿²¬ ´¿¾»´ã»¨°® Åòòòô´¿¾»´ã»¨°®Ã 4. For information on types of code.DECLARE SYMBOL CONSTANT 4. The ½±²º·¹ directive can be used multiple times in the source code. see Section 1.4 See Also ­»¬ ª¿®·¿¾´» »¯« ½¾´±½µ DS33014K-page 58 2009 Microchip Technology Inc.13.13. 4.. .5 Simple Example åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò ý·²½´«¼» °ïèºìëîò·²½ å½±¼» °®±¬»½¬ ¼·­¿¾´»¼ ÝÑÒÚ×Ù ÝÐðãÑÚÚ åÑ­½·´´¿¬±® ­©·¬½¸ »²¿¾´»¼ô ÎÝ ±­½·´´¿¬±® ©·¬¸ ÑÍÝî ¿­ ×ñÑ °·²ò ÝÑÒÚ×Ù ÑÍÝÍãÑÒô ÑÍÝãÔÐ åÞ®±©²óÑ«¬Î»­»¬ »²¿¾´»¼ô ÞÑΠʱ´¬¿¹» ·­ îòëª ÝÑÒÚ×Ù ÞÑÎãÑÒô ÞÑÎÊãîë åÉ¿¬½¸ ܱ¹ Ì·³»® »²¿¾´»ô É¿¬½¸ ܱ¹ Ì·³»® б­¬Í½¿´»® ½±«²¬ ó ïæïîè ÝÑÒÚ×Ù ÉÜÌãÑÒô ÉÜÌÐÍãïîè åÝÝÐî °·² Ó«¨ »²¿¾´»¼ ÝÑÒÚ×Ù ÝÝÐîÓËÈãÑÒ åͬ¿½µ ±ª»®ñ«²¼»®º´±© λ­»¬ »²¿¾´»¼ ÝÑÒÚ×Ù ÍÌÊÎãÑÒ 4.4 See Also ÁÁ½±²º·¹ ÁÁ·¼´±½­ ´·­¬ °®±½»­­±® 4.http://www.13.13 ½±²­¬¿²¬ . Constants may not be reset after having once been initialized.e. the ½±²­¬¿²¬ directive also works. i.12.6 “Assembler Operation”. but an error will be generated if the same bit is assigned a value more than once. Although »¯« or ½¾´±½µ is more generally used to create constants. ÝÑÒÚ×Ù ÝÐðãÑÚÚô ÉÜÌãÑÒ ÝÑÒÚ×Ù ÝÐðãÑÒ åøß² »®®±® ©·´´ ¾» ·­­«»¼ ­·²½» ÝÐð ·­ ¿­­·¹²»¼ ¬©·½»÷ 4. This is the principal difference between symbols declared as constant and those declared as variable. constants and variables may be used interchangeably in absolute code expressions. 4.

4.STORE STRINGS IN PROGRAM MEMORY (PIC12/16 MCUs) 4.2 Description ¼¿ . 4.14.4 Simple Examples • ¼¿ þ¿¾½¼»ºþ will put íðÛî íïÛì íîÛê into program memory • ¼¿ þïîíìëêéèþ ôð will put ïèÞî ïçÞì ïßÞê ïÞÞè ðððð into program memory • ¼¿ ð¨ÚÚÚÚ will put ð¨íÚÚÚ into program memory 4.14.13. This directive is useful for storing strings in memory for PIC16 MCU devices. For information on types of code.3 Usage This directive is used in the following types of code: absolute or relocatable.14.¼¿ This example shows the usefulness of directive ¼¿ in storing a character string in the program memory of 14-bit architecture devices.6 “Assembler Operation”.Data ASCII. ý·²½´«¼» °ïêºèéé¿ò·²½ åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò å̸» º±´´±©·²¹ ½±¼» ©·´´ ¾» å°®±¹®¿³³»¼ ·² ®»­»¬ ¿¼¼®»­­ ðò åÖ«³° ¬± ¿² ¿¼¼®»­­ ´¿¾»´´»¼ åù­¬¿®¬ùò åÉ®·¬» §±«® ³¿·² °®±¹®¿³ ¸»®»ò ü ð¨ïððð åÙ± ¬± ½«®®»²¬ ´·²» ø´±±° ¸»®»÷ åͬ±®» ¬¸» ­¬®·²¹ ­¬¿®¬·²¹ º®±³ åïðððØò ÑÎÙ ¹±¬± ð¨ðððð ­¬¿®¬ ­¬¿®¬ ¹±¬± ÑÎ٠ݸÁ­¬²¹ ¼¿ þÐ×ݳ·½®±þ 2009 Microchip Technology Inc. see Section 1.14 ¼¿ .com For evaluation only.foxitsoftware.5 Examples See the examples under ª¿®·¿¾´». DS33014K-page 59 . Generates a packed 14-bit number representing two 7-bit ASCII characters. 4.5 Application Example . Directives 4.Generated by Foxit PDF Creator © Foxit Software http://www.14. This directive generates a packed 14-bit number representing two 7-bit ASCII characters.1 Syntax Å´¿¾»´Ã ¼¿ »¨°® Åô »¨°®îô òòòô »¨°®²Ã 4.14.

See below for more information. The data may also consist of ASCII character strings.15 ¼¿¬¿ .2 Description Initialize one or more words of program memory with data. On the PIC18 device family. Each is presented in 7-bit as (0)1010000 and (0)1001001 respectively. To see how the 14-bit numbers are determined. Single character items are placed into the low byte of the word.15. the final byte is zero. For information on types of code. The data may be in the form of constants.15. 21ED. Cm. 34E3. Cm. ic. When generating a linkable object file. which is stored as (00)101000 01001001 or 2849. enclosed in single quotes for one character or double quotes for strings. and 396F representing the ASCII equivalent of PI. 21ED. the first character is in the most significant byte of the word.3 Usage This directive is used in the following types of code: absolute or relocatable. 4. see Section 1. relocatable or external labels. ic and ro. 4.5 ¼¿¬¿ ¼¿¬¿ ¼¿¬¿ ¼¿¬¿ ¼¿¬¿ Simple Example å å å å å ½±²­¬¿²¬­ ½±²­¬¿²¬­ô »¨¬»®²¿´­ ¬»¨¬ ­¬®·²¹ ­·²¹´» ½¸¿®¿½¬»® ®»´±½¿¬¿¾´» ´¿¾»´ ®»´±½Á´¿¾»´õïð ïôîô»¨¬Á´¿¾»´ þ¬»­¬·²¹ ïôîôíþ ùÒù ­¬¿®¬Á±ºÁ°®±¹®¿³ DS33014K-page 60 2009 Microchip Technology Inc. 4.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. On all families except the PIC18 device family. look at the ASCII values of P and I. or expressions of any of the above. .15. The packed 14-bit number is 101000 01001001. 34E3 and 396F representing the ASCII equivalent of PI.CREATE NUMERIC AND TEXT DATA 4. ¬»¨¬Á­¬®·²¹.15. Directive ¼¿ produces four 14-bit numbers: 2849.1 Syntax Å´¿¾»´Ã ¼¿¬¿ »¨°®ôÅô»¨°®ôòòòô»¨°®Ã Å´¿¾»´Ã ¼¿¬¿ þ¬»¨¬Á­¬®·²¹þÅôþ¬»¨¬Á­¬®·²¹þôòòòà 4.http://www. Ͳ¹´Á½¸ ¼¿ þßþ åéó¾·¬ ßÍÝ×× »¯«·ª¿´»²¬­ ±º ùßù 忲¼ ¿ ÒËÔÔ ½¸¿®¿½¬»® ©·´´ ¾» °¿½µ»¼ å·² ¿ ïìó¾·¬ ²«³¾»®ò åд¿½»­ íºëë ·² °®±¹®¿³ ³»³±®§ò åÒ± °¿½µ·²¹ò ¼¿ 𨺺ëë »²¼ Determining 14-Bit Numbers For the following statement: ݸÁ­¬²¹ ¼¿ þÐ×ݳ·½®±þ directive ¼¿ produces four 14-bit numbers: 2849.6 “Assembler Operation”. the first character is in the least significant byte of the word. and ro. Refer to the ·¼¿¬¿ directive for more information. If an odd number of characters are given in a string.15.4 See Also ¼¾ ¼» ¼¬ ¼¬³ ¼© ·¼¿¬¿ 4. ¼¾ and other data directives are more commonly used than ¼¿¬¿. this directive can also be used to declare initialized data values. while strings are packed two to a word. which are 50h(01010000) and 49h(01001001) respectively.foxitsoftware.

ý·²½´«¼» °ïèºìëîò·²½ åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò å̸» º±´´±©·²¹ ½±¼» ©·´´ ¾» å°®±¹®¿³³»¼ ·² ®»­»¬ ¿¼¼®»­­ ðò åÖ«³° ¬± ¿² ¿¼¼®»­­ ´¿¾»´´»¼ 厭¬¿®¬Žò åÉ®·¬» §±«® ³¿·² °®±¹®¿³ ¸»®»ò ü ð¨ïððð åÙ± ¬± ½«®®»²¬ ´·²» ø´±±° ¸»®»÷ åͬ±®» ¬¸» ­¬®·²¹ ­¬¿®¬·²¹ º®±³ åïðððØò ײ Ð×Ýïè ¼»ª·½»­ô ¬¸» 康®­¬ ½¸¿®¿½¬»® ·­ ·² ´»¿­¬ å­·¹²·º·½¿²¬ ¾§¬»ò ÑÎÙ ¹±¬± ð¨ðððð ­¬¿®¬ ­¬¿®¬ ¹±¬± ÑÎÙ 2009 Microchip Technology Inc.6 PIC16 Application Example .7 PIC18 Application Example .foxitsoftware.¼¿¬¿ This example shows the usefulness of directive ¼¿¬¿ in storing one or more words in program memory. ¬¾ïÁ¼¬¿ ¼¿¬¿ 𨺺ººô𨿿ëë åд¿½»­ íººº¸ ¿²¼ î¿ëë¸ ·² 嬩± ½±²­»½«¬·ª» °®±¹®¿³ å³»³±®§ ´±½¿¬·±²­ò ß­ °®±¹®¿³ å³»³±®§ ·­ ïìó¾·¬ ©·¼»ô 嬸» ´¿­¬ ²·¾¾´» ½¿² ­¬±®» å¿ ³¿¨·³«³ ª¿´«» íò »²¼ 4.Generated by Foxit PDF Creator © Foxit Software http://www. respectively. Directives 4.com For evaluation only. 4Dh. and 0055h. ý·²½´«¼» °ïêºèéé¿ò·²½ åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò å̸» º±´´±©·²¹ ½±¼» ©·´´ ¾» å°®±¹®¿³³»¼ ·² ®»­»¬ ¿¼¼®»­­ ðò åÖ«³° ¬± ¿² ¿¼¼®»­­ ´¿¾»´´»¼ 厭¬¿®¬Žò åÉ®·¬» §±«® ³¿·² °®±¹®¿³ ¸»®»ò ü ð¨ïððð åÙ± ¬± ½«®®»²¬ ´·²» ø´±±° ¸»®»÷ åͬ±®» ¬¸» ­¬®·²¹ ­¬¿®¬·²¹ º®±³ åïðððØò ŽÓŽôŽÝŽôŽËŽ åí °®±¹®¿³ ³»³±®§ ´±½¿¬·±²­ å©·´´ ¾» º·´´»¼ ©·¬¸ ßÍÝ×× å»¯«·ª¿´»²¬ ±º ŽÓŽôŽÝŽ ¿²¼ åŽËŽò ÑÎÙ ¹±¬± ð¨ðððð ­¬¿®¬ ­¬¿®¬ ¹±¬± ÑÎ٠ݸÁ­¬²¹ ¼¿¬¿ Directive ¼¿¬¿ produces three 14-bit numbers: 004Dh.15. DS33014K-page 61 . 43h and 55h are ASCII equivalents of ’M’.15. ’C’ and ’U’. 0043h.¼¿¬¿ This example shows the usefulness of directive ¼¿¬¿ in storing one or more words in program memory.

1 Syntax Å´¿¾»´Ã ¼¾ »¨°®Åô»¨°®ôòòòô»¨°®Ã 4.DECLARE DATA OF ONE BYTE 4. Reserve program memory words with 8-bit values. See Section 4. since it is desired to not have bytes padded with zeroes. 4.Data Byte.3 Usage This directive is used in the following types of code: absolute or relocatable. 4Dh. this directive can also be used to declare initialized data values. 43h and 55h are ASCII equivalents of ’M’.foxitsoftware.6 “Assembler Operation”. 434Dh represents ’C’ and ’M’. åí °®±¹®¿³ ³»³±®§ ´±½¿¬·±²­ å©·´´ ¾» º·´´»¼ ©·¬¸ ßÍÝ×× å»¯«·ª¿´»²¬ ±º ŽÓŽôŽÝŽ ¿²¼ åŽËŽò Directive ¼¿¬¿ produces three 16-bit numbers: 004Dh.http://www.16.16. ݸÁ­¬¹ï ¼¿¬¿ þÓÝËþ åî °®±¹®¿³ ³»³±®§ ´±½¿¬·±²­ å©·´´ ¾» º·´´»¼ ©·¬¸ ¬©± 婱®¼­ øïêó¾·¬ ²«³¾»®­÷ô 廿½¸ ®»°®»­»²¬·²¹ ßÍÝ× å»¯«·ª¿´»²¬ ±º ¬©± 彸¿®¿½¬»®­ò ̸» ´¿­¬ 彸¿®¿½¬»® ©·´´ ¾» ¬¿µ»² ¿­ åÒËÔÔ ·² ½¿­» ±¼¼ ²«³¾»® ±º 彸¿®¿½¬»®­ ¿®» ­°»½·º·»¼ò Directive ¼¿¬¿ produces two words: 434Dh and 0055h. the last byte will be zero unless in a PIC18 ½±¼»Á°¿½µ section.4 See Also ¼¿¬¿ ¼» ¼¬ ¼¬³ ¼© ·¼¿¬¿ ½±¼»Á°¿½µ DS33014K-page 62 2009 Microchip Technology Inc. 4. and 0055h. Refer to the ·¼¿¬¿ directive for more information. respectively. When generating a linkable object file.16. ’C’ and ’U’. Multiple expressions continue to fill bytes consecutively until the end of expressions. 0043h.16 ¼¾ .10 “½±¼»Á°¿½µ . see Section 1.com Assembler/Linker/Librarian User’s Guide ݸÁ­¬²¹ ¼¿¬¿ ŽÓŽôŽÝŽôŽËŽ Generated by Foxit PDF Creator © Foxit Software For evaluation only. For PIC18 devices. .2 Description ¼¾ . use ½±¼»Á°¿½µ with ¼¾.Begin an Object File Packed Code Section (PIC18 MCUs)” for better use of memory. For information on types of code. Should there be an odd number of expressions. ¬¾ïÁ¼¬¿ ¼¿¬¿ 𨺺ººô𨿿ëë åд¿½»­ ºººº ¿²¼ ¿¿ëë ·² 嬩± ½±²­»½«¬·ª» °®±¹®¿³ å³»³±®§ ´±½¿¬·±²­ò »²¼ 4. See the description of ½±¼»Á°¿½µ for more information.16.

DS33014K-page 63 .16. ý·²½´«¼» °ïêºèéé¿ò·²½ åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò å̸» º±´´±©·²¹ ½±¼» ©·´´ ¾» å°®±¹®¿³³»¼ ·² ®»­»¬ ¿¼¼®»­­ ðò åÖ«³° ¬± ¿² ¿¼¼®»­­ ´¿¾»´´»¼ 厭¬¿®¬Žò åÉ®·¬» §±«® ³¿·² °®±¹®¿³ ¸»®»ò ü ð¨ïððð åÙ± ¬± ½«®®»²¬ ´·²» ø´±±° ¸»®»÷ åͬ±®» ¬¸» ­¬®·²¹ ­¬¿®¬·²¹ º®±³ åïðððØò ðôŽÓŽôðôŽÝŽôðôŽËŽ ÑÎÙ ¹±¬± ð¨ðððð ­¬¿®¬ ­¬¿®¬ ¹±¬± ÑÎ٠ݸÁ­¬²¹ ¼¾ ݸÁ­¬®²¹ contains three 14-bit numbers: 004Dh.¼¾ This example shows the usefulness of directive ¼¾ in storing one or more bytes or characters in program memory.5 Simple Examples Example1: PIC16 Devices ¼¾ ð¨ðºô ù¬ùô ð¨ðºô ù»ùô ð¨ðºô ù­ùô ð¨ðºô ù¬ùô ùIJù ASCII: 0x0F74 0x0F65 0x0F73 0x0F74 0x0a00 Example 2: PIC18 Devices ¼¾ ù¬ùô ù»ùô ù­ùô ù¬ùô ùIJù ASCII: 0x6574 0x7473 0x000a 4.foxitsoftware.6 PIC16 Application Example .16. Directives 4.com For evaluation only.16. respectively. 0043h. ý·²½´«¼» °ïèºìëîò·²½ åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò å̸» º±´´±©·²¹ ½±¼» ©·´´ ¾» å°®±¹®¿³³»¼ ·² ®»­»¬ ¿¼¼®»­­ ðò åÖ«³° ¬± ¿² ¿¼¼®»­­ ´¿¾»´´»¼ 厭¬¿®¬Žò åÉ®·¬» §±«® ³¿·² °®±¹®¿³ ¸»®»ò ü åÙ± ¬± ½«®®»²¬ ´·²» ø´±±° ¸»®»÷ ÑÎÙ ¹±¬± ð¨ðððð ­¬¿®¬ ­¬¿®¬ ¹±¬± 2009 Microchip Technology Inc.¼¾ This example shows the usefulness of directive ¼¾ in storing one or more byte or character in program memory. These are ASCII equivalents of ’M’.Generated by Foxit PDF Creator © Foxit Software http://www. ¬¾ïÁ¼¬¿ ¼¾ ðô𨺺 åд¿½»­ ð𺺠·² °®±¹®¿³ ³»³±®§ å´±½¿¬·±²ò »²¼ 4. and 0055h.7 PIC18 Application Example . ’C’ and ’U’.

17 ¼» . ’C’ and ’U’.DECLARE EEPROM DATA BYTE 4. For information on types of code.17. a 0 will be added unless in a ½±¼»Á°¿½µ section.17.Begin an Object File Packed Code Section (PIC18 MCUs)” ¬¾ïÁ¼¬¿ ¼¾ ðô𨺺 åд¿½»­ ººðð ·² °®±¹®¿³ ³»³±®§ å´±½¿¬·±²ò »²¼ 4. make sure to specify the start of data memory at 0xF00000.3 Usage This directive is used in the following types of code: absolute or relocatable. reserve memory word bytes are packed. 4. make sure to specify the start of data memory at 0x2100.foxitsoftware. For PIC18 devices. For PIC18 MCU devices. reserve memory words with 8-bit data. This directive is designed mainly for initializing data in the EE data memory region of PIC1X MCU devices with EE data FLASH. For other PIC1X MCU devices.5 Simple Example Initialize EEPROM data on a PIC16 device: ±®¹ ð¨îïðð ¼» þÓ§ Ю±¹®¿³ô ªïòðþô ð DS33014K-page 64 2009 Microchip Technology Inc. If an odd number of bytes is specified.17.com Assembler/Linker/Librarian User’s Guide ÑÎÙ ð¨ïððð Generated by Foxit PDF Creator © Foxit Software For evaluation only. The upper bits of the program word are zeroes.http://www. Information on storing data in both bytes of a program word on the PIC18 architecture can be found in Section 4. Always check your device programming specification for the correct address.6 “Assembler Operation”. 0043h. This directive can be used at any location for any processor. Each »¨°® must evaluate to an 8-bit value. Each character in a string is stored in a separate word. See the description for ½±¼»Á°¿½µ for more information. These are ASCII equivalents of ’M’. respectively.17. åͬ±®» ¬¸» ­¬®·²¹ ­¬¿®¬·²¹ º®±³ åïðððØò ײ Ð×Ýïè ¼»ª·½»­ô ¬¸» 康®­¬ ½¸¿®¿½¬»® ·­ ·² ´»¿­¬ å­·¹²·º·½¿²¬ ¾§¬»ò ŽÓŽôŽÝŽôŽËŽ ݸÁ­¬²¹ ¼¾ ݸÁ­¬®²¹ contains three 16-bit numbers: 004Dh.4 See Also ¼¿¬¿ ¼¾ ¼¬ ¼¬³ ¼© ½±¼»Á°¿½µ 4. .Data EEPROM.10 “½±¼»Á°¿½µ .1 Syntax Å´¿¾»´Ã ¼» »¨°® Åô »¨°®ô òòòô »¨°®Ã 4.17. 4.2 Description ¼» . For all other PIC1X MCU devices. see Section 1. and 0055h.

This directive emulates the ANSI 'C' standard for ý¼»º·²».17.com For evaluation only.DEFINE A TEXT SUBSTITUTION LABEL 4. Using the directive with no ­¬®·²¹ causes a definition of ²¿³» to be noted internally and may be tested for using the ·º¼»º directive.7 PIC18 Application Example .18.2 Description This directive defines a text substitution string. For information on types of code.¼» åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò ý·²½´«¼» °ïèºìëîò·²½ ±®¹ ð¨Úððððð å̸» ¿¾­±´«¬» ¿¼¼®»­­ Úðððð𸠷­ 峿°°»¼ ¬± ¬¸» ðððð ´±½¿¬·±² ±º åÛÛ ¼¿¬¿ ³»³±®§ º±® Ð×Ýïè ¼»ª·½»­ò åDZ« ½¿² ½®»¿¬» ¿ ¼¿¬¿ ±® ½¸¿®¿½¬»® ¬¿¾´» ­¬¿®¬·²¹ º®±³ ¿²§ 忼¼®»­­ ·² ÛÛ ¼¿¬¿ ³»³±®§ò ½¸Á¬¾´î ¼» þÐ×ݳ·½®±þ åè ÛÛ ¼¿¬¿ ³»³±®§ ´±½¿¬·±²­ åø­¬¿®¬·²¹ º®±³ ð÷ ©·´´ ¾» º·´´»¼ å©·¬¸ è ßÍÝ×× ½¸¿®¿½¬»®­ò »²¼ 4.18.17.6 PIC16 Application Example .1 Syntax ý¼»º·²» ²¿³» Å­¬®·²¹Ã 4. see Section 1. 2009 Microchip Technology Inc.6 “Assembler Operation”.Generated by Foxit PDF Creator © Foxit Software http://www. DS33014K-page 65 . 4. Symbols defined with this method are not available for viewing using MPLAB IDE.foxitsoftware. ­¬®·²¹ will be substituted.18. Directives 4.18 ý¼»º·²» .¼» åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò ý·²½´«¼» °ïêºèéé¿ò·²½ ±®¹ ð¨îïðð å̸» ¿¾­±´«¬» ¿¼¼®»­­ îïð𸠷­ 峿°°»¼ ¬± ¬¸» ðððð ´±½¿¬·±² ±º åÛÛ ¼¿¬¿ ³»³±®§ò åDZ« ½¿² ½®»¿¬» ¿ ¼¿¬¿ ±® ½¸¿®¿½¬»® ¬¿¾´» ­¬¿®¬·²¹ º®±³ ¿²§ 忼¼®»­­ ·² ÛÛ ¼¿¬¿ ³»³±®§ò ½¸Á¬¾´î ¼» þÐ×ݳ·½®±þ åè ÛÛ ¼¿¬¿ ³»³±®§ ´±½¿¬·±²­ åø­¬¿®¬·²¹ º®±³ ð÷ ©·´´ ¾» º·´´»¼ å©·¬¸ è ßÍÝ×× ½¸¿®¿½¬»®­ò »²¼ 4. Wherever ²¿³» is encountered in the assembly code.3 Usage This directive is used in the following types of code: absolute or relocatable.

18. See ý·²½´«¼» for how to include a file in your program. This directive is also useful with the ·º¼»º and ·º²¼»º directives. The label ´²¹¬¸ must be undefined before it can be defined as '0'.4 See Also ý«²¼»º·²» ý·²½´«¼» ·º¼»º ·º²¼»º 4.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only.http://www. It is recommended that you use this file instead of defining the variables yourself. is removed from the symbol table if ý«²¼»º·²» directive is used.foxitsoftware. which look for the presence of an item in the symbol table. ý·²½´«¼» °ïêºèéé¿ò·²½ åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò å̸» ´¿¾»´ ù¿®»¿ù ·­ ¿­­·¹²»¼ 嬸» ª¿´«» ðò åÔ¿¾»´ ù´²¹¬¸ù ·­ ¿­­·¹²»¼ 嬸» ª¿´«» ëðØò åÔ¿¾»´ ù©¼¬¸ù ·­ ¿­­·¹²»¼ 嬸» ª¿´«» îëØ åλ¿­­·¹²³»²¬ ±º ´¿¾»´ ù¿®»¿ùò åͱ ù¿®»¿ù ©·´´ ¾» ®»¿­­·¹²»¼ ¿ 媿´«» »¯«¿´ ¬± ëðØöîëØò å˲¼»º·²» ´¿¾»´ ù´²¹¬¸ùò å˲¼»º·²» ´¿¾»´ ù©¼¬¸ù åÜ»º·²» ´¿¾»´ ù´²¹¬¸ù ¬± ùðùò ¿®»¿ ­»¬ ð ëðØ îëØ ý¼»º·²» ´²¹¬¸ ý¼»º·²» ©¼¬¸ ¿®»¿ ­»¬ ´²¹¬¸ö©¼¬¸ ý«²¼»º·²» ý«²¼»º·²» ý¼»º·²» »²¼ ´²¹¬¸ ©¼¬¸ ´²¹¬¸ ð By using the above directives.18. . A symbol name previously defined with the ý¼»º·²» directive.ý¼»º·²»/ý«²¼»º·²» This example shows the usage of ý¼»º·²» and ý«²¼»º·²» directives. ´²¹¬¸ will be reassigned a value '0' and ©¼¬¸ will be removed from the symbol list in the list (ò´­¬) file.6 Application Example .5 Simple Example ý¼»º·²» ´»²¹¬¸ îð ý¼»º·²» ½±²¬®±´ ð¨ïçôé ý¼»º·²» °±­·¬·±²øÈôÇôÆ÷ øÇóøî ö Æ õÈ÷÷ æ æ ¬»­¬Á´¿¾»´ ¼© °±­·¬·±²øïô ´»²¹¬¸ô ëïî÷ ¾­º ½±²¬®±´ å ­»¬ ¾·¬ é ·² ºïç 4. DS33014K-page 66 2009 Microchip Technology Inc.18. 4. The same symbol may be redefined again. ý¼»º·²» is useful for defining values for constants in your program. Note: A processor-specific include file exists with predefined SFR names.

4.19. If you are using a PIC18 device. See the device data sheet for more information. see Section 1.4 See Also ¼¿¬¿ ¼¾ ¼» ¼¬ ¼© 4. DS33014K-page 67 . it is recommended that you use the table read/write (ÌÞÔÎÜ/ÌÞÔÉÌ) features. For information on types of code.3 Usage This directive is used in the following types of code: absolute or relocatable.1 Syntax Å´¿¾»´Ã ¼¬ »¨°® Åô »¨°®ô òòòô »¨°®Ã 4.1 Syntax Å´¿¾»´Ã ¼¬³ »¨°® Åô »¨°®ô òòòô »¨°®Ã 4.6 “Assembler Operation”.3 Usage This directive is used in the following types of code: absolute or relocatable. Directives 4.2 Description ¼¬ . Each »¨°® must be an 8-bit value.6 “Assembler Operation”. Each character in a string is stored in its own ÎÛÌÔÉ instruction.20. 4. Each character in a string is stored in its own ÓÑÊÔÉ instruction.DEFINE TABLE (EXTENDED PIC16 MCUS ONLY) 4. Generates a series of ÎÛÌÔÉ instructions.5 Simple Example ¼¬ þß Ó»­­¿¹»þô 𠼬 Ú·®­¬Ê¿´«»ô Í»½±²¼Ê¿´«»ô Û²¼ÑºÊ¿´«»­ 4. Generates a series of ÓÑÊÔÉ instructions.19.20.19 ¼¬ .2 Description ¼¬³ . one instruction for each »¨°®. This directive is used when generating a table of data for the PIC12/16 device family.20 ¼¬³ .20.Generated by Foxit PDF Creator © Foxit Software http://www. Each »¨°® must be an 8-bit value.5 Simple Example ¼¬³ þß Ó»­­¿¹»þô 𠼬³ Ú·®­¬Ê¿´«»ô Í»½±²¼Ê¿´«»ô Û²¼ÑºÊ¿´«»­ 2009 Microchip Technology Inc.foxitsoftware.20.4 See Also ¼¿¬¿ ¼¾ ¼» ¼¬³ ¼© 4.Define data Table. one instruction for each »¨°®. 4.20.19.com For evaluation only.DEFINE TABLE (PIC12/16 MCUs) 4.Define data Table using ÓÑÊÔÉ.19. For information on types of code.19. 4. This directive is used when generating a table of data for the PIC16 extended device family. see Section 1.

Refer to the ·¼¿¬¿ directive for more information. .21. 4. This directive is not an instruction.22.21 ¼© .22. this directive can also be used to declare initialized data values.6 “Assembler Operation”. It is used to perform conditional assembly of code. Values are stored into successive memory locations and the location counter is incremented by one.6 “Assembler Operation”.1 »´­» Syntax Preferred: Supported: ý»´­» ò»´­» 4.2 Description ¼© .3 Usage This directive is used in the following types of code: absolute or relocatable.Data Word. When generating a linkable object file.2 Description Used in conjunction with an ·º directive to provide an alternative path of assembly code should the ·º evaluate to false. For information on types of code. See the PIC16F877A data sheet for examples and more information.4 »²¼·º ·º See Also DS33014K-page 68 2009 Microchip Technology Inc. you may use ¼© to store data in Flash PIC16FXXX devices. ¼© functions like ¼¾. as many of these devices can read all 14 bits of a program memory word at run-time.21. 4.22.22 »´­» . Reserve program memory words for data.1 Syntax Å´¿¾»´Ã ¼© »¨°®Åô»¨°®ôòòòô»¨°®Ã 4.5 Simple Example ¼© íçô þ¼·¿¹²±­¬·½ íçþô ð¨ïîí ¼© ¼·¿¹¾¿­»óï 4. Expressions may be literal strings and are stored as described in the ¼¾ data directive.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. While ¼¾ is more common to use.4 See Also ¼¿¬¿ ¼¾ ·¼¿¬¿ 4. For information on types of code. see Section 1.22.DECLARE DATA OF ONE WORD 4.3 Usage This directive is used in the following types of code: absolute or relocatable.21. see Section 1.foxitsoftware. 4. 4. initializing that space to specific values.http://www.BEGIN ALTERNATIVE ASSEMBLY BLOCK TO ·º CONDITIONAL 4.21. For PIC18 devices. »´­» may be used inside a regular program block or macro. 4.21.

6 “Assembler Operation”.23.23.23 »²¼ .3 Usage This directive is used in the following types of code: absolute. one and only one »²¼ must be used. 4.foxitsoftware.23. see Section 1.END AN AUTOMATIC CONSTANT BLOCK 4. It must be supplied to terminate the list.1 »²¼ Syntax 4.4 ½¾´±½µ See Also 2009 Microchip Technology Inc.1 »²¼½ Syntax 4. 4. DS33014K-page 69 .24.2 Description »²¼½ terminates the end of a ½¾´±½µ list.24.END PROGRAM BLOCK 4.com For evaluation only.5 Simple Example ý·²½´«¼» °ïèºìëîò·²½ æ å »¨»½«¬¿¾´» ½±¼» æ å »²¼ å »²¼ ±º ·²­¬®«½¬·±²­ 4.6 Application Example . there must be a corresponding »²¼½. For information on types of code. Directives 4. 4.3 Usage This directive is used in the following types of code: absolute or relocatable.24.24 »²¼½ .Generated by Foxit PDF Creator © Foxit Software http://www. For every ½¾´±½µ directive used.22.22.2 Description Indicates the end of the program.24. For information on types of code.23. see Section 1. 4. In a single assembly file program. Be careful not to include files which contain »²¼ as assembly will be prematurely stopped.·º/»´­»/»²¼·º See this example under ·º.6 “Assembler Operation”.5 Simple Example ·º ®¿¬» ä ëð ·²½º ­°»»¼ô Ú »´­» ¼»½º ­°»»¼ô Ú »²¼·º 4.4 ±®¹ See Also 4.23. 4. You will need at least one »²¼ directive in any assembly program to indicate the end of a build.

1 »²¼³ Syntax 4. 4. For every ³¿½®± directive used.26. For information on types of code.1 »²¼·º Syntax Preferred: Supported: ý»²¼·º ò»²¼·º òº· 4. 4.2 Description Terminates a macro definition begun with ³¿½®±.26.6 “Assembler Operation”.4 »´­» ·º See Also 4. .http://www. there must be a corresponding »²¼³.25.26.4 See Also ³¿½®± »¨·¬³ 4. see Section 1. 4.foxitsoftware. 4.5 Examples See the examples under ½¾´±½µ. 4.6 “Assembler Operation”.2 Description This directive marks the end of a conditional assembly block. »²¼·º may be used inside a regular program block or macro.END CONDITIONAL ASSEMBLY BLOCK 4.3 Usage This directive is used in the following types of code: absolute or relocatable. 4.25.5 Examples See the examples under ·º. but used for code assembly only. ·º and »²¼·º are not instructions.25.3 Usage This directive is used in the following types of code: absolute or relocatable.26 »²¼³ .END A MACRO DEFINITION 4.25.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. there must be a corresponding »²¼·º.25. see Section 1. 4.26.26.24. For every ·º directive used. For information on types of code.5 Simple Example ³¿µ»Á¬¿¾´» ³¿½®± ¿®¹ïô ¿®¹î ¼© ¿®¹ïô ð å ²«´´ ¬»®³·²¿¬» ¬¿¾´» ²¿³» ®»­ ¿®¹î å ®»­»®ª» ­¬±®¿¹» »²¼³ DS33014K-page 70 2009 Microchip Technology Inc.25 »²¼·º .

Do not use this method for assigning variables when building a linked project. As long as the condition specified by the ©¸·´» directive remains true.28.4 See Also ­»¬ ½¾´±½µ ®»­ ·¼¿¬¿ «¼¿¬¿ «¼¿¬¿Á¿½­ «¼¿¬¿Á±ª® «¼¿¬¿Á­¸® 2009 Microchip Technology Inc.2 Description »²¼© terminates a ©¸·´» loop. DS33014K-page 71 .³¿½®±/»²¼³ See this example under ³¿½®±. ©¸·´» and »²¼© are not instructions.1 »²¼© Syntax Preferred: Supported: ò»²¼© 4. This directive may be used inside a regular program block or macro.26.27. 4. 4.28.DEFINE AN ASSEMBLER CONSTANT 4.END A ©¸·´» LOOP 4.6 “Assembler Operation”. but used for code assembly only. In a single assembly file program. 4.com For evaluation only.27.28.3 Usage This directive is used in the following types of code: absolute or relocatable.28 »¯« . 4.foxitsoftware. »¯« is commonly used to assign a variable name to an address location in RAM.4 ©¸·´» See Also 4. For every ©¸·´» directive used.27.6 “Assembler Operation”.1 Syntax ´¿¾»´ »¯« »¨°® 4.5 Examples See the example under ©¸·´». the source code between the ©¸·´» directive and the »²¼© directive will be repeatedly expanded in the assembly source code stream. see Section 1. use a ®»­ directive inside a data section directive (·¼¿¬¿. «¼¿¬¿). For information on types of code. 4. see Section 1.6 Application Example .27. For information on types of code.27. Directives 4.Generated by Foxit PDF Creator © Foxit Software http://www.2 Description The value of »¨°® is assigned to ´¿¾»´.27 »²¼© .28. 4. there must be a corresponding »²¼©.3 Usage This directive is used in the following types of code: absolute or relocatable.

6 “Assembler Operation”. You can use this directive to generate errors for yourself or others who build your code. .6 Application Example . 4800.5 Simple Example º±«® »¯« ì å ¿­­·¹²»¼ ¬¸» ²«³»®·½ ª¿´«» ±º ì ¬± ´¿¾»´ º±«® 4.5 Simple Example »®®±®Á½¸»½µ·²¹ ³¿½®± ¿®¹ï ·º ¿®¹ï âã ëë å ·º ¿®¹ ·­ ±«¬ ±º ®¿²¹» »®®±® þ»®®±®Á½¸»½µ·²¹óðï ¿®¹ ±«¬ ±º ®¿²¹»þ »²¼·º »²¼³ 4. You can create any error message you wish.4 ³»­­¹ ·º See Also 4.29.2 Description ¬»¨¬Á­¬®·²¹ is printed in a format identical to any MPASM assembler error message. 4. 4. see Section 1. 4.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. DS33014K-page 72 2009 Microchip Technology Inc. as long as it is no longer than 80 characters. ý·²½´«¼» °ïêºèéé¿ò·²½ åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò 媿®·¿¾´» «­»¼ ¬± ¼»º·²» å®»¯«·®»¼ ¾¿«¼ ®¿¬» åÛ²¬»® ¬¸» ®»¯«·®»¼ ª¿´«» ±º 徿«¼ ®¿¬» ¸»®»ò ª¿®·¿¾´» ¾¿«¼®¿¬» ¾¿«¼®¿¬» ­»¬ Üùëêððù ·º ø¾¿«¼®¿¬»ÿãÜùïîððù÷úúø¾¿«¼®¿¬»ÿãÜùîìððù÷úú ø¾¿«¼®¿¬»ÿãÜùìèððù÷úúø¾¿«¼®¿¬»ÿãÜùçêððù÷úú ø¾¿«¼®¿¬»ÿãÜùïçîððù÷ »®®±® þÍ»´»½¬»¼ ¾¿«¼ ®¿¬» ·­ ²±¬ ­«°°±®¬»¼þ »²¼·º The ·º-»²¼·º code above outputs »®®±® if the baud rate selected is other than 1200.29.»®®±® This program demonstrates the »®®±® assembler directive.3 Usage This directive is used in the following types of code: absolute or relocatable.29. 2400.foxitsoftware.29.29.http://www.1 Syntax »®®±® þ¬»¨¬Á­¬®·²¹þ 4.29 »®®±® .29. For information on types of code.28.­»¬/»¯« See this example under ­»¬.ISSUE AN ERROR MESSAGE 4. ¬»¨¬Á­¬®·²¹ may be from 1 to 80 characters.28.6 Application Example . 9600 or 19200 Hz. which sets an error message to be printed in the listing file and error file. 4.

1 Syntax »®®±®´»ª»´ ¥ð¤ï¤î¤õ³­¹²«³¤ó³­¹²«³£ Åô òòòà 4. Messages may be disabled using settings 1 or 2. check to ensure bank bits are correct”. warnings. Warnings may be disabled using setting 2. as this can make debugging of your code more difficult. 4. See the Simple Example for how to do this.30 »®®±®´»ª»´ . Directives ÎÍÌ ÝÑÜÛ ð¨ð °¿¹»­»´ ¹±¬± ÐÙÓ ÝÑÜÛ ­¬¿®¬ ­¬¿®¬ å̸» ½±¼» ­»½¬·±² ²¿³»¼ ÎÍÌ å·­ °´¿½»¼ ¿¬ °®±¹®¿³ ³»³±®§ å´±½¿¬·±² ð¨ðò ̸» ²»¨¬ ¬©± å·²­¬®«½¬·±²­ ¿®» °´¿½»¼ ·² å½±¼» ­»½¬·±² ÎÍÌò åÖ«³°­ ¬± ¬¸» ´±½¿¬·±² ´¿¾»´´»¼ 厭¬¿®¬Žò å̸·­ ·­ ¬¸» ¾»¹·²²·²¹ ±º ¬¸» å½±¼» ­»½¬·±² ²¿³»¼ ÐÙÓò ׬ ·­ å¿ ®»´±½¿¬¿¾´» ½±¼» ­»½¬·±² å­·²½» ²± ¿¾­±´«¬» ¿¼¼®»­­ ·­ å¹·ª»² ¿´±²¹ ©·¬¸ ¼·®»½¬·ª» ÝÑÜÛò åÙ± ¬± ½«®®»²¬ ´·²» ø´±±° ¸»®»÷ ­¬¿®¬ ¹±¬± ü »²¼ 4.com For evaluation only. 1.2 Description Sets the types of messages that are printed in the listing file and error file.30.3 Usage This directive is used in the following types of code: absolute or relocatable. Also.30. DS33014K-page 73 .30. the setting of 0. Be careful about disabling warnings and messages. or 2 overrides individual message disabling or enabling.SET MESSAGE LEVEL 4. and errors printed Warnings and errors printed Errors printed Inhibits printing of message ³­¹²«³ Enables printing of message ³­¹²«³ 4. For information on types of code.Operand Not in bank 0. Setting ð ï î ó³­¹²«³ õ³­¹²«³ Affect Messages.6 “Assembler Operation”.4 See Also ´·­¬ »®®±® 2009 Microchip Technology Inc. messages may be disabled individually. Errors cannot be disabled. The most common usage for this directive is to suppress “MESSAGE 302 .30. see Section 1.Generated by Foxit PDF Creator © Foxit Software http://www.foxitsoftware. However.

4.http://www. »®®±®´»ª»´ ï åÜ·­°´¿§ñ°®·²¬ ±²´§ ©¿®²·²¹­ 忲¼ »®®±®­ò ³»­­¹ þÝßËÌ×ÑÒæ ̸·­ °®±¹®¿³ ¸¿­ »®®±®­þ å¼·­°´¿§ ³»­­¿¹» This message will NOT display/print for error level 1 or 2. ¹®±«°ï «¼¿¬¿ ¹®±«°ïÁª¿®ï ð¨îð ®»­ ï åÔ¿¾»´ ±º ¬¸·­ ¼·®»½¬·ª» ·­ ²±¬ 忬 ½±´«³² ïò ̸·­ ©·´´ ¹»²»®¿¬» å¿ ©¿®²·²¹ ²«³¾»® îðéò Warning #207 will display/print for error level 0 or 1. which sets the type of messages that are printed in the listing file and error file.30.6 Application Example .com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only.5 Simple Example Ì«®² ±ºº ¾¿²µ·²¹ ³»­­¿¹» µ²±©² ¬»­¬»¼ ø¹±±¼÷ ½±¼» Û²¿¾´» ¾¿²µ·²¹ ³»­­¿¹» «²¬»­¬»¼ ½±¼» »®®±®´»ª»´ óíðî å å æ »®®±®´»ª»´ õíðî å å æ »²¼ 4. ý·²½´«¼» °ïêºèéé¿ò·²½ åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò »®®±®´»ª»´ ð åÜ·­°´¿§ñ°®·²¬ ³»­­¿¹»­ô å©¿®²·²¹­ ¿²¼ »®®±®­ò ³»­­¹ þÝßËÌ×ÑÒæ ̸·­ °®±¹®¿³ ¸¿­ »®®±®­þ å¼·­°´¿§ ±² ¾«·´¼ This message will display/print for error level 0.»®®±®´»ª»´ This program demonstrates the »®®±®´»ª»´ assembler directive. »®®±®´»ª»´ óîðé å̸·­ ¼·­¿¾´»­ ©¿®²·²¹ ©¸±­» 岫³¾»® ·­ îðéò å´¿¾»´ ±º ¬¸·­ ¼·®»½¬·ª» ·­ ¿´­± å²±¬ ¿¬ ½±´«³² ïô ¾«¬ ²± ©¿®²·²¹ å·­ ¼·­°´¿§»¼ñ°®·²¬»¼ò å̸·­ »²¿¾´»­ ©¿®²·²¹ ©¸±­» 岫³¾»® ·­ îðé ¹®±«°ïÁª¿®î ®»­ ï »®®±®´»ª»´ õîðé ¹®±«°î «¼¿¬¿ åÜ·­°´¿§ñ°®·²¬ ±²´§ »®®±®­ ï å´¿¾»´ ±º ¬¸·­ ¼·®»½¬·ª» ·­ ²±¬ 忬 ½±´«³² ïò ̸·­ ©·´´ ¹»²»®¿¬» å¿ ©¿®²·²¹ ²«³¾»® îðéò »®®±®´»ª»´ î ¹®±«°îÁª¿®ï ®»­ DS33014K-page 74 2009 Microchip Technology Inc.foxitsoftware. .30.

com For evaluation only. regardless of error level.Generated by Foxit PDF Creator © Foxit Software http://www. DS33014K-page 75 . 4.1 »¨·¬³ Syntax 4. Use this directive to prematurely end a macro.31. This is similar to the C language command ¾®»¿µ.31 »¨·¬³ . see Section 1. »®®±®´»ª»´ ï åÜ·­°´¿§ñ°®·²¬ ©¿®²·²¹­ 忲¼ »®®±®­ò ï å´¿¾»´ ±º ¬¸·­ ¼·®»½¬·ª» ·­ ²±¬ 忬 ½±´«³² ïò ̸·­ ©·´´ ¹»²»®¿¬» å¿ ©¿®²·²¹ ²«³¾»® îðéò å̸» ½±¼» ­»½¬·±² ²¿³»¼ ÎÍÌ å·­ °´¿½»¼ ¿¬ °®±¹®¿³ ³»³±®§ å´±½¿¬·±² ð¨ðò ̸» ²»¨¬ ¬©± å·²­¬®«½¬·±²­ ¿®» °´¿½»¼ ·² å½±¼» ­»½¬·±² ÎÍÌò åÖ«³°­ ¬± ¬¸» ´±½¿¬·±² ´¿¾»´´»¼ 厭¬¿®¬Žò å̸» ½±¼» ­»½¬·±² ²¿³»¼ ×ÒÌÎÌ ·­ å°´¿½»¼ ¿¬ ð¨ìò ̸» ²»¨¬ ¬©± å·²­¬®«½¬·±²­ ¿®» °´¿½»¼ ·² å½±¼» ­»½¬·±² ×ÒÌÎÌ åÔ¿¾»´ ù­»®ª·½»Á·²¬ù ·­ ²±¬ å¼»º·²»¼ò Ø»²½» ¬¸·­ ¹»²»®¿¬»­ å»®®±®ÅïïíÃò ¹®±«°îÁª¿®î ®»­ ÎÍÌ ÝÑÜÛ ð¨ð °¿¹»­»´ ¹±¬± ×ÒÌÎÌ ÝÑÜÛ ­¬¿®¬ ­¬¿®¬ ð¨ì °¿¹»­»´ ¹±¬± ­»®ª·½»Á·²¬ ­»®ª·½»Á·²¬ Error 113 will always display/print.foxitsoftware. For information on types of code.31. usually for a specific condition.2 Description Force immediate return from macro expansion during assembly. ÐÙÓ ÝÑÜÛ å̸·­ ·­ ¬¸» ¾»¹·²²·²¹ ±º ¬¸» ½±¼» å­»½¬·±² ²¿³»¼ ùÐÙÓùò ׬ ·­ ¿ å®»´±½¿¬¿¾´» ½±¼» ­»½¬·±² ­·²½» å²± ¿¾­±´«¬» ¿¼¼®»­­ ·­ ¹·ª»² ¿´±²¹ å©·¬¸ ¼·®»½¬·ª» ÝÑÜÛò ­¬¿®¬ ³±ª©º ¹®±«°ïÁª¿®ï ¹±¬± ü »²¼ åÙ± ¬± ½«®®»²¬ ´·²» ø´±±° ¸»®»÷ 4.4 See Also »²¼³ ³¿½®± 2009 Microchip Technology Inc. The effect is the same as if an »²¼³ directive had been encountered.6 “Assembler Operation”.EXIT FROM A MACRO 4.31. 4.3 Usage This directive is used in the following types of code: absolute or relocatable.31. Directives Warning #207 will NOT display/print for error level 2.

»¨·¬³ This program demonstrates the »¨·¬³ assembler directive.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. 4.http://www. which causes an immediate exit from a macro.6 Application Example .31. ý·²½´«¼» °ïêºèéé¿ò·²½ åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò åß­­·¹² ª¿´«» îðØ ¬± ´¿¾»´ å®»­«´¬ò å̸» ½±¼» ­»½¬·±² ²¿³»¼ ÎÍÌ å·­ °´¿½»¼ ¿¬ °®±¹®¿³ ³»³±®§ å´±½¿¬·±² ð¨ðò ̸» ²»¨¬ ¬©± å·²­¬®«½¬·±²­ ¿®» °´¿½»¼ ·² å½±¼» ­»½¬·±² ÎÍÌò åÖ«³°­ ¬± ¬¸» ´±½¿¬·±² ´¿¾»´´»¼ 厭¬¿®¬Žò åù¿¼¼ù ·­ ¿ ³¿½®±ò ̸» ª¿´«»­ ±º åù²«³ïù ¿²¼ ù²«³îù ³«­¬ ¾» °¿­­»¼ 嬱 ¬¸·­ ³¿½®±ò å׺ ²«³ïâîëë ¼»½·³¿´ô 庱®½» ·³³»¼·¿¬» ®»¬«®² º®±³ 峿½®± ¼«®·²¹ ¿­­»³¾´§ò å׺ ²«³îâîëë ¼»½·³¿´ô 庱®½» ·³³»¼·¿¬» ®»¬«®² º®±³ 峿½®± ¼«®·²¹ ¿­­»³¾´§ò ®»­«´¬ »¯« ð¨îð ÎÍÌ ÝÑÜÛ ð¨ð °¿¹»­»´ ¹±¬± ¿¼¼ ÓßÝÎÑ ­¬¿®¬ ­¬¿®¬ ²«³ïô²«³î ·º ²«³ïâ𨺺 »¨·¬³ »´­» ·º ²«³îâ𨺺 »¨·¬³ »´­» ³±ª´© ²«³ï åÔ±¿¼ É ®»¹·­¬»® ©·¬¸ ¿ ´·¬»®¿´ 媿´«» ¿­­·¹²»¼ ¬± ¬¸» ´¿¾»´ åù²«³ïùò åÔ±¿¼ É ®»¹·­¬»® ¬± ¿² ¿¼¼®»­­ å´±½¿¬·±² ¿­­·¹²»¼ ¬± ¬¸» ´¿¾»´ åù®»­«´¬ùò åÔ±¿¼ É ®»¹·­¬»® ©·¬¸ ¿ ´·¬»®¿´ 媿´«» ¿­­·¹²»¼ ¬± ¬¸» ´¿¾»´ åù²«³îùò åß¼¼ É ®»¹·­¬»® ©·¬¸ ¬¸» ³»³±®§ å´±½¿¬·±² ¿¼¼®»­­»¼ ¾§ ù®»­«´¬ù 忲¼ ´±¿¼ ¬¸» ®»­«´¬ ¾¿½µ ¬± åù®»­«´¬ùò ³±ª©º ®»­«´¬ ³±ª´© ²«³î ¿¼¼©º ®»­«´¬ »²¼·º »²¼·º DS33014K-page 76 2009 Microchip Technology Inc.foxitsoftware.31.5 Simple Example ¬»­¬ ³¿½®± º·´»®»¹ ·º º·´»®»¹ ãã ï å ½¸»½µ º±® ª¿´·¼ º·´» »¨·¬³ »´­» »®®±® þ¾¿¼ º·´» ¿­­·¹²³»²¬þ »²¼·º »²¼³ 4. . It is used in the example to exit from the macro when certain conditions are met.

see Section 1. 4.2 Description Expand all macros in the listing file. This directive may be useful when exploring a small range of code with many macros in it.3 Usage This directive is used in the following types of code: absolute.32.5 Simple Example Code example: æ åÜ»º·²» ¿ ³¿½®± ¬± ¿¼¼ ¬©± ²«³¾»®­ ¿¼¼ ³¿½®± ²«³ïô²«³î ³±ª´© ²«³ï ³±ª©º ®»­«´¬ ³±ª´© ²«³î ¿¼¼©º ®»­«´¬ »²¼³ æ »¨°¿²¼ åË­» ³¿½®± ¿¼¼ ¿¼¼ òïððôòçð 2009 Microchip Technology Inc.4 See Also ³¿½®± ²±»¨°¿²¼ 4. Directives »²¼³ ±®¹ ­¬¿®¬ ððïð åÛ²¼ ±º ù¿¼¼ù ÓßÝÎÑ åÓ§ ³¿·² °®±¹®¿³ ­¬¿®¬­ ¿¬ ïðØò å̸» ´¿¾»´ ù­¬¿®¬ù ·­ ¿­­·¹²»¼ ¿² 忼¼®»­­ ïðØò òïððôòîëê åÝ¿´´ ù¿¼¼ù ÓßÝÎÑ ©·¬¸ ¼»½·³¿´ 岫³¾»®­ ïðð ¿²¼ îëê ¿­­·¹²»¼ ¬± åù²«³ïù ¿²¼ ù²«³îù ´¿¾»´­ô å®»­°»½¬·ª»´§ò ÛÈÌ×Ó ¼·®»½¬·ª» ·² 峿½®± ©·´´ º±®½» ®»¬«®²ò åλ³»³¾»® ùòù ³»¿²­ ¼»½·³¿´ô ²±¬ 庴±¿¬·²¹ °±·²¬ò ¿¼¼ »²¼ 4.32.) This directive is roughly equivalent to the ñ³ MPASM assembler command line option.Generated by Foxit PDF Creator © Foxit Software http://www. For information on types of code.32. DS33014K-page 77 .32.6 “Assembler Operation”. but may be disabled by the occurrence of a subsequent ²±»¨°¿²¼.32.1 »¨°¿²¼ Syntax 4.foxitsoftware.com For evaluation only.32 »¨°¿²¼ .EXPAND MACRO LISTING 4. 4. (This is the default behavior.

This allows a project to be split up into multiple files (two in this example) for code reuse. »¨¬»®² will be used in a file when a label (usually a variable) is used by that file.33.6 Application Example . ððïð ððïï ððïî ððïí íðêì ððßð íðëß ðéßð 4.33.http://www. You must use both directives as specified or the label will not be visible to other files.1 Syntax »¨¬»®² ´¿¾»´ Åô ´¿¾»´òòòà 4. demonstrate the ¹´±¾¿´ and »¨¬»®² directives. At least one label must be specified on the line.6 “Assembler Operation”. which make it possible to use symbols in modules other than where they are defined.com Assembler/Linker/Librarian User’s Guide Resulting listing file: ðððîç ðððíð Ó Ó Ó Ó ðððíï »¨°¿²¼ ¿¼¼ òïððôòçð ³±ª´© òïðð ³±ª©º ®»­«´¬ ³±ª´© òçð ¿¼¼©º ®»­«´¬ Generated by Foxit PDF Creator © Foxit Software For evaluation only.»¨¬»®²/¹´±¾¿´ The program ³¿·²ò¿­³.2 Description This directive declares symbol names that may be used in the current module but are defined as global in a different module.33.foxitsoftware. As soon as you have more than one file in your project. MPASM assembler will generate a duplicate label error.33 »¨¬»®² .DECLARE AN EXTERNALLY DEFINED LABEL 4.33. The »¨¬»®² statement must be included before the ´¿¾»´ is used.5 Simple Example »¨¬»®² Ú«²½¬·±² æ ½¿´´ Ú«²½¬·±² 4. 4.33. ¹´±¾¿´ will be used in another file so that the label may be seen by other files.4 See Also ¹´±¾¿´ ·¼¿¬¿ «¼¿¬¿ «¼¿¬¿Á¿½­ «¼¿¬¿Á±ª® «¼¿¬¿Á­¸® 4. along with ­«¾ò¿­³. .3 Usage This directive is used in the following types of code: relocatable. 4. If ´¿¾»´ is defined in the current module. see Section 1. you may use this directive. åööööööööööööööööööööööööööööööööööööööööööööööööööööööö 峿·²ò¿­³ åööööööööööööööööööööööööööööööööööööööööööööööööööööööö ý·²½´«¼» °ïêºèéé¿ò·²½ åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò ËÜßÌß ¼»´¿§Áª¿´«» ÙÔÑÞßÔ ®»­ ï å̸» ª¿®·¿¾´» ù¼»´¿§Áª¿´«»ùô å¼»½´¿®»¼ ÙÔÑÞßÔ ·² ¬¸·­ ¼»´¿§Áª¿´«» DS33014K-page 78 2009 Microchip Technology Inc.33. For information on types of code.

DS33014K-page 79 .Generated by Foxit PDF Creator © Foxit Software http://www. Directives å³±¼«´»ô ·­ ·²½´«¼»¼ ·² ¿² åÛÈÌÛÎÒ ¼·®»½¬·ª» ·² ¬¸» ³±¼«´» å­«¾ò¿­³ò ÛÈÌÛÎÒ ¼»´¿§ å̸» ª¿®·¿¾´» ù¼»´¿§ùô ¼»½´¿®»¼ åÛÈÌÛÎÒ ·² ¬¸·­ ³±¼«´»ô ·­ å¼»½´¿®»¼ ÙÔÑÞßÔ ·² ¬¸» ³±¼«´» å­«¾ò¿­³ò ð¨ð å̸» ½±¼» ­»½¬·±² ²¿³»¼ ÎÍÌ å·­ °´¿½»¼ ¿¬ °®±¹®¿³ ³»³±®§ å´±½¿¬·±² ð¨ðò ̸» ²»¨¬ ¬©± å·²­¬®«½¬·±²­ ¿®» °´¿½»¼ ·² å½±¼» ­»½¬·±² ÎÍÌò åÖ«³°­ ¬± ¬¸» ´±½¿¬·±² ´¿¾»´´»¼ 厭¬¿®¬Žò å̸·­ ·­ ¬¸» ¾»¹·²²·²¹ ±º ¬¸» å½±¼» ­»½¬·±² ²¿³»¼ ÐÙÓò ׬ ·­ å¿ ®»´±½¿¬¿¾´» ½±¼» ­»½¬·±² å­·²½» ²± ¿¾­±´«¬» ¿¼¼®»­­ ·­ å¹·ª»² ¿´±²¹ ©·¬¸ ¼·®»½¬·ª» ÝÑÜÛò ÎÍÌ ÝÑÜÛ °¿¹»­»´ ¹±¬± ÐÙÓ ÝÑÜÛ ­¬¿®¬ ­¬¿®¬ ­¬¿®¬ ³±ª´© ³±ª©º ¨±®´© ½¿´´ ¹±¬± »²¼ Üùïðù ¼»´¿§Áª¿´«» ð¨èð ¼»´¿§ ­¬¿®¬ åööööööööööööööööööööööööööööööööööööööööööööööööööööööö å­«¾ò¿­³ åööööööööööööööööööööööööööööööööööööööööööööööööööööööö ý·²½´«¼» °ïêºèéé¿ò·²½ åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò ÙÔÑÞßÔ ¼»´¿§ å̸» ª¿®·¿¾´» ù¼»´¿§ù ¼»½´¿®»¼ åÙÔÑÞßÔ ·² ¬¸·­ ³±¼«´» ·­ å·²½´«¼»¼ ·² ¿² ÛÈÌÛÎÒ ¼·®»½¬·ª» å·² ¬¸» ³±¼«´» ³¿·²ò¿­³ò å̸» ª¿®·¿¾´» ù¼»´¿§Áª¿´«»ù å¼»½´¿®»¼ ÛÈÌÛÎÒ ·² ¬¸·­ ³±¼«´» å·­ ¼»½´¿®»¼ ÙÔÑÞßÔ ·² ¬¸» å³±¼«´» ³¿·²ò¿­³ò ÛÈÌÛÎÒ ¼»´¿§Áª¿´«» ÐÙÓ ÝÑÜÛ ¼»´¿§ ¼»½º­¦ ¼»´¿§Áª¿´«»ôï ¹±¬± ¼»´¿§ ®»¬«®² »²¼ 2009 Microchip Technology Inc.com For evaluation only.foxitsoftware.

34.34.1 Syntax Å´¿¾»´Ã º·´´ »¨°®ô½±«²¬ 4.4 See Also ¼¿¬¿ ¼© ±®¹ 4. which would cause the device to reset.foxitsoftware. If bounded by parentheses.34.34. it is not uncommon to see this used with the watchdog timer (WDT) on a PIC16 device.6 PIC16 Application Example . ý·²½´«¼» °ïêºèéé¿ò·²½ åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò å̸» ½±¼» ­»½¬·±² ²¿³»¼ ÎÍÌ å·­ °´¿½»¼ ¿¬ °®±¹®¿³ ³»³±®§ å´±½¿¬·±² ð¨ðò ̸» ²»¨¬ ¬©± å·²­¬®«½¬·±²­ ¿®» °´¿½»¼ ·² å½±¼» ­»½¬·±² ÎÍÌò ÎÍÌ ÝÑÜÛ ð¨ðððð DS33014K-page 80 2009 Microchip Technology Inc.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. For example.SPECIFY PROGRAM MEMORY FILL VALUE 4. 4.2 Description Generates ½±«²¬ occurrences of the program word or byte (PIC18 devices). 4.34 º·´´ . Unused program memory would be filled with goto or branch instructions to prevent execution of the ½´®©¼¬ instruction in code. see Section 1. 4. This directive is often used to force known data into unused program memory. Note: For relocatable code.http://www.3 Usage This directive is used in the following types of code: absolute or relocatable.º·´´ The º·´´ directive is used to specify successive program memory locations with a constant or an assembly instruction. For information on types of code. This helps ensure that if code ever branches to an unused area at run-time.34. do not use a symbol in another section in the expression »¨°®. .34.5 Simple Examples Example 1: PIC10/12/16 MCU’s º·´´ ð¨ïððçô ë å º·´´ ©·¬¸ ¿ ½±²­¬¿²¬ º·´´ øÙÑÌÑ ÎÛÍÛÌÁÊÛÝÌÑÎ÷ô ÒÛÈÌÁÞÔÑÝÕóü Example 2: PIC18 Devices ý·²½´«¼» °ïèºîëîò·²½ ±®¹ ð¨ïî º¿·´­¿º» ¹±¬± ü ±®¹ ð¨ïðð º·´´ ø¹±¬± º¿·´­¿º»÷ô øð¨èðððóü÷ñî åÜ·ª·¼» ¾§ î º±® åîó©±®¼ ·²­¬®«½¬·±²­ »²¼ 4. a fail-safe condition occurs. »¨°® can be an assembler instruction.6 “Assembler Operation”. »¨°®. See the device data sheet for more information on the WDT.

7 PIC18 Application Example . only an even number is allowed to be specified as a count of locations to be filled. Directives °¿¹»­»´ ¹±¬± º·´´ ­¬¿®¬ ­¬¿®¬ åÖ«³°­ ¬± ¬¸» ´±½¿¬·±² ´¿¾»´´»¼ 厭¬¿®¬Žò åÚ·´´ ©·¬¸ ð «° ¬± ¿¼¼®»­­ í ó å×ÒÌÎÐÌ ¿¼¼®ò ³·²«­ ½«®®»²¬ ¿¼¼®ò å̸» ½±¼» ­»½¬·±² ²¿³»¼ ×ÒÌÎÐÌ å·­ °´¿½»¼ ¿¬ °®±¹®¿³ ³»³±®§ å´±½¿¬·±² ð¨ìò ̸» ²»¨¬ ¬©± å·²­¬®«½¬·±²­ ¿®» °´¿½»¼ ·² å½±¼» ­»½¬·±² ×ÒÌÎÐÌò åÖ«³°­ ¬± ¬¸» ´±½¿¬·±² ´¿¾»´´»¼ å×ÍÎò ðô ×ÒÌÎÐÌóü ×ÒÌÎÐÌ ÝÑÜÛ ð¨ðððì °¿¹»­»´ ¹±¬± º·´´ ×ÍÎ ×ÍÎ ­¬¿®¬ º·´´ ¹±¬± ×ÍÎ ®»¬º·» »²¼ ø¹±¬± ­¬¿®¬÷ô ­¬¿®¬óü åÚ·´´ «°¬± ¿¼¼®»­­ ðÚ¸ ©·¬¸ å·²­¬®«½¬·±² ä¹±¬± ­¬¿®¬âò ÝÑÜÛ ð¨ððïð åÉ®·¬» §±«® ³¿·² °®±¹®¿³ ¸»®»ò ø²±°÷ô ü ë åÚ·´´ ë ´±½¿¬·±²­ ©·¬¸ ÒÑЭò åÙ± ¬± ½«®®»²¬ ´·²» ø´±±° ¸»®»÷ åÉ®·¬» §±«® ·²¬»®®«°¬ ­»®ª·½» å®±«¬·²» ¸»®»ò 4. DS33014K-page 81 .foxitsoftware.34.Generated by Foxit PDF Creator © Foxit Software http://www.com For evaluation only. ý·²½´«¼» °ïèºìëîò·²½ åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò å̸» ½±¼» ­»½¬·±² ²¿³»¼ ÎÍÌ å·­ °´¿½»¼ ¿¬ °®±¹®¿³ ³»³±®§ å´±½¿¬·±² ð¨ðò ̸» ·²­¬®«½¬·±² åù¹±¬± ­¬¿®¬ù ·­ °´¿½»¼ ·² å½±¼» ­»½¬·±² ÎÍÌò åÖ«³°­ ¬± ¬¸» ´±½¿¬·±² ´¿¾»´´»¼ åù­¬¿®¬ùò åÚ·´´­ ð ·² î °®±¹®¿³ ³»³±®§ å´±½¿¬·±²­æ ðððì ¿²¼ ðððê ó åØ×Á×ÒÌ ¿¼¼®ò ³·²«­ ½«®®»²¬ ¿¼¼®ò ÎÍÌ ÝÑÜÛ ð¨ðððð ¹±¬± ­¬¿®¬ º·´´ ðô Ø×Á×ÒÌóü Ø×Á×ÒÌ ¹±¬± º·´´ ÝÑÜÛ ð¨ðððè ×ÒÌÎÁØ ø¹±¬± ­¬¿®¬÷ôê åÚ·´´­ ê ´±½¿¬·±²­ ø»¿½¸ ´±½¿¬·±² å·­ î ¾§¬»­ ©·¼»÷ ©·¬¸ í ²«³¾»®­ 屺 î ©±®¼ ©·¼» ·²­¬®«½¬·±²­ åä¹±¬± ­¬¿®¬â ÔÑÁ×ÒÌ ¹±¬± º·´´ ÝÑÜÛ ð¨ððïè ×ÒÌÎÁÔ ïð¿çô ­¬¿®¬óü ÝÑÜÛ ð¨ððîð åÚ·´´­ ¿¼¼®»­­ ïݸ ¿²¼ ïÛ¸ ©·¬¸ åïð¿ç¸ åÉ®·¬» §±«® ³¿·² °®±¹®¿³ ¸»®» ­¬¿®¬ 2009 Microchip Technology Inc.º·´´ The º·´´ directive is used to specify successive program memory locations with a constant or an assembly instruction. For PIC18 devices.

35. 4.foxitsoftware.1 Syntax Å´¿¾»´Ã ·¼¿¬¿ ÅÎßÓÁ¿¼¼®»­­Ã DS33014K-page 82 2009 Microchip Technology Inc. åÚ·´´­ î ´±½¿¬·±²­ øì ¾§¬»­÷ ©·¬¸ åÒÑÐ åÙ± ¬± ½«®®»²¬ ´·²» ø´±±° ¸»®»÷ åÉ®·¬» §±«® ¸·¹¸ ·²¬»®®«°¬ ×ÍÎ ¸»®» åÉ®·¬» §±«® ´±© ·²¬»®®«°¬ ×ÍÎ ¸»®» 4.6 “Assembler Operation”.4 See Also »¨¬»®² ·¼¿¬¿ «¼¿¬¿ «¼¿¬¿Á¿½­ «¼¿¬¿Á±ª® «¼¿¬¿Á­¸® 4.35 ¹´±¾¿´ . 4.35.»¨¬»®²/¹´±¾¿´ See this example under »¨¬»®². ¹´±¾¿´ is used to make a label visible to other files.5 Simple Example ¹´±¾¿´ Ê¿®ïô Ê¿®î ¹´±¾¿´ ß¼¼Ì¸®»» «¼¿¬¿ ®»­ ï ®»­ ï ½±¼» ¿¼¼´© í ®»¬«®² Ê¿®ï Ê¿®î ß¼¼Ì¸®»» 4.36 ·¼¿¬¿ . . 4.35. »¨¬»®² must be used in the file that uses the label to make it visible in that file.com Assembler/Linker/Librarian User’s Guide º·´´ ¹±¬± ×ÒÌÎÁØ ®»¬º·» ×ÒÌÎÁÔ ®»¬º·» »²¼ ø²±°÷ô ü ì Generated by Foxit PDF Creator © Foxit Software For evaluation only.35.BEGIN AN OBJECT FILE INITIALIZED DATA SECTION 4. At least one label must be specified on the line.6 Application Example . see Section 1.3 Usage This directive is used in the following types of code: relocatable. When this happens. For information on types of code.http://www.1 Syntax ¹´±¾¿´ ´¿¾»´ Åô ´¿¾»´òòòà 4.35. you will be generating linkable object code.2 Description This directive declares symbol names that are defined in the current module and should be available to other modules.36. When your project uses more than one file.35. you may use the ¹´±¾¿´ and »¨¬»®² directives.EXPORT A LABEL 4.

DS33014K-page 83 . The linker will generate a look-up table entry for each byte specified in an idata section.com For evaluation only.36. If ´¿¾»´ is not specified. The ®»­.36. 4.foxitsoftware. For information on types of code. in low-byte/high-byte order. Directives 4. Note: This directive is not available for 12-bit instruction width (PIC10. the variables will be initialized with 0. Use this directive to initialize your variables.·¼¿¬¿ This directive reserves RAM locations for variables and directs the linker to generate a lookup table that may be used to initialize the variables specified in this section. 4.36.6 Application Example . No code can be placed by the user in this segment. some PIC12/PIC16) devices.36. ý·²½´«¼» °ïêºèéé¿ò·²½ åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò åײ·¬·¿´·¦»¼ åîð¸ò å¹®±«°ïÁª¿®ï å·²·¬·¿´·¦»¼ å¹®±«°ïÁª¿®î å·²·¬·¿´·¦»¼ ¼¿¬¿ ¿¬ ´±½¿¬·±² ´±½¿¬»¼ ¿¬ ð¨îðô ©·¬¸ ðò ´±½¿¬»¼ ¿¬ ð¨îïô ©·¬¸ ðò ¹®±«°ï ×ÜßÌß ð¨îð ®»­ ®»­ ï ï ¹®±«°ïÁª¿®ï ¹®±«°ïÁª¿®î 2009 Microchip Technology Inc. as behavioral differences between the emulator and the actual part may occur. ®»­ will generate an initial value of zero. Relying on RAM initialization can cause problems. You must then link or include the appropriate initialization code.4 See Also »¨¬»®² ¹´±¾¿´ «¼¿¬¿ «¼¿¬¿Á¿½­ «¼¿¬¿Á±ª® «¼¿¬¿Á­¸® 4. especially when using an emulator.5 Ô·³·¬Ô Ô·³·¬Ø Ù¿·² Ú´¿¹­ ͬ®·²¹ Simple Example ·¼¿¬¿ ¼© 𠼩 Üùíððù ¼© Üùëù ¼¾ ð ¼¾ ùØ· ¬¸»®»ÿù 4. ¼¾ and ¼© directives may be used to reserve space for variables. or use a «¼¿¬¿ directive and then initialize your variables with values in code. one word at a time.2 Description This directive declares the beginning of a section of initialized data. If you don’t specify a value in the idata section.Generated by Foxit PDF Creator © Foxit Software http://www. see Section 1. ¼¾ will initialize successive bytes of RAM.6 “Assembler Operation”. Examples of initialization code that may be used and modified as needed may be found with MPLINK linker sample application examples. The starting address is initialized to the specified address or will be assigned at link time if no address is specified.36. It is recommended that you always initialize your variables. The Starting Address of the lookup table can be obtained from the Map (ò³¿°) file.3 Usage This directive is used in the following types of code: relocatable. ¼© will initialize successive bytes of RAM. the section is named ò·¼¿¬¿.

com Assembler/Linker/Librarian User’s Guide ¹®±«°î ×ÜßÌß Generated by Foxit PDF Creator © Foxit Software For evaluation only.37 ·¼¿¬¿Á¿½­ . especially when using an emulator.6 “Assembler Operation”. Relying on RAM initialization can cause problems. ®»­ will generate an initial value of zero. For information on types of code.37. or use a «¼¿¬¿ directive and then initialize your variables with values in code. åÜ»½´¿®¿¬·±² ±º ¹®±«°î ¼¿¬¿ò ̸» 忼¼®»­­»­ º±® ª¿®·¿¾´»­ «²¼»® 嬸·­ ¼¿¬¿ ­»½¬·±² ¿®» ¿´´±½¿¬»¼ å¿«¬±³¿¬·½¿´´§ ¾§ ¬¸» ´·²µ»®ò ¼¾ ¼© ïôîôíôì ð¨ïîíì ð¨ð åì ¾§¬»­ ·² ÎßÓ ¿®» ®»­»®ª»¼ò åï ©±®¼ ·² ÎßÓ ·­ ®»­»®ª»¼ò ¹®±«°îÁª¿®ï ¹®±«°îÁª¿®î ÎÍÌ ÝÑÜÛ °¿¹»­»´ ¹±¬± ÐÙÓ ÝÑÜÛ ­¬¿®¬ ­¬¿®¬ å̸» ½±¼» ­»½¬·±² ²¿³»¼ ÎÍÌ å·­ °´¿½»¼ ¿¬ °®±¹®¿³ ³»³±®§ å´±½¿¬·±² ð¨ðò ̸» ²»¨¬ ¬©± å·²­¬®«½¬·±²­ ¿®» °´¿½»¼ ·² å½±¼» ­»½¬·±² ÎÍÌò åÖ«³°­ ¬± ¬¸» ´±½¿¬·±² ´¿¾»´´»¼ 厭¬¿®¬Žò å̸·­ ·­ ¬¸» ¾»¹·²²·²¹ ±º ¬¸» å½±¼» ­»½¬·±² ²¿³»¼ ÐÙÓò ׬ ·­ å¿ ®»´±½¿¬¿¾´» ½±¼» ­»½¬·±² å­·²½» ²± ¿¾­±´«¬» ¿¼¼®»­­ ·­ å¹·ª»² ¿´±²¹ ©·¬¸ ¼·®»½¬·ª» ÝÑÜÛò åÙ± ¬± ½«®®»²¬ ´·²» ø´±±° ¸»®»÷ ­¬¿®¬ ¹±¬± ü »²¼ 4.1 Syntax Å´¿¾»´Ã ·¼¿¬¿Á¿½­ ÅÎßÓÁ¿¼¼®»­­Ã 4. You must then link or include the appropriate initialization code. 4. as behavioral differences between the emulator and the actual part may occur. The ®»­. the section is named ò·¼¿¬¿Á¿½­. No code can be placed by the user in this segment.foxitsoftware. Use this directive to initialize your variables.37. .37. ¼© will initialize successive bytes of RAM.3 Usage This directive is used in the following types of code: relocatable. ¼¾ will initialize successive bytes of RAM.4 See Also »¨¬»®² ¹´±¾¿´ «¼¿¬¿ «¼¿¬¿Á¿½­ «¼¿¬¿Á±ª® «¼¿¬¿Á­¸® DS33014K-page 84 2009 Microchip Technology Inc.2 Description This directive declares the beginning of a section of initialized data in Access RAM.37. If ´¿¾»´ is not specified. one word at a time. It is recommended that you always initialize your variables. The linker will generate a look-up table entry for each byte specified in an idata section. 4. see Section 1.BEGIN AN OBJECT FILE INITIALIZED DATA SECTION IN ACCESS RAM (PIC18 MCUs) 4. in low-byte/high-byte order. The starting address is initialized to the specified address or will be assigned at link time if no address is specified.http://www. ¼¾ and ¼© directives may be used to reserve space for variables. Examples of initialization code that may be used and modified as needed may be found with MPLINK linker sample application examples.

For PIC18 devices. the ´·­¬ directive. but PIC12/16 devices cannot. Before this directive is used.3 Usage This directive is used in the following types of code: absolute or relocatable. according to the programming specification. if »¨°® evaluates to 1AF. For example.foxitsoftware. the processor must be declared through the command line. the first (lowest address) ID location is zero. or the °®±½»­­±® directive. 4.4 See Also ÁÁ½±²º·¹ ½±²º·¹ ´·­¬ °®±½»­­±® 4. PIC18 devices can read this value at run-time.5 Simple Example Example 1: PIC16 Devices ý·²½´«¼» °ïêºèéé¿ò·²½ ÁÁ·¼´±½­ ð¨ïîíì åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò åÍ»¬­ ¼»ª·½» ×Ü ¬± ïîíìò Example 2: PIC18 Devices Note: The most significant nibble of ÁÁ·¼´±½­ is always 0x0. 4. __·¼´±½­ can be read by a programmer.38. ÁÁ·¼´±½­ sets the two-byte device ID at location ¿¼¼® to the hexadecimal value of »¨°®. the third is ten.5 Ô·³·¬Ô Ô·³·¬Ø Ù¿·² Ú´¿¹­ ͬ®·²¹ Simple Example ·¼¿¬¿Á¿½­ ¼© 𠼩 Üùíððù ¼© Üùëù ¼¾ ð ¼¾ ùØ· ¬¸»®»ÿù 4.38. see Section 1. åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò ý·²½´«¼» °ïèºìëîò·²½ 2009 Microchip Technology Inc. DS33014K-page 85 . This directive is not commonly used. Directives 4. ÁÁ·¼´±½­ sets the four ID locations to the hexadecimal value of »¨°®.com For evaluation only. but does provide an easy method of serializing devices.38 ÁÁ·¼´±½­ .37.2 Description For PIC12 and PIC16 devices.6 “Assembler Operation”. the second is one. 4.38.Generated by Foxit PDF Creator © Foxit Software http://www.38. For information on types of code.SET PROCESSOR ID LOCATIONS Note: ·¼´±½­ is preceded by two underline characters.1 Syntax ÁÁ·¼´±½­ »¨°® ÁÁ·¼´±½­ ¿¼¼®ô »¨°® (PIC18 Only) 4. and the fourth is fifteen.38.

4 See Also »´­» »²¼·º DS33014K-page 86 2009 Microchip Technology Inc. FALSE a value of zero. The ·º and ©¸·´» directives operate on the logical value of an expression. the code immediately following the if will assemble.39. This directive is not an instruction. not how it behaves at run-time. Use this directive for conditional assembly or to check for a condition. An expression that evaluates to any other value is considered logically TRUE. A relational TRUE expression is guaranteed to return a nonzero value. Otherwise. ·º's may be nested up to 16 deep. 4.com Assembler/Linker/Librarian User’s Guide ÁÁ·¼´±½­ ÁÁ·¼´±½­ ÁÁ·¼´±½­ ÁÁ·¼´±½­ ÁÁ·¼´±½­ ÁÁ·¼´±½­ ÁÁ·¼´±½­ ÁÁ·¼´±½­ Á×ÜÔÑÝðô ð¨ï Á×ÜÔÑÝïô ð¨î Á×ÜÔÑÝîô ð¨í Á×ÜÔÑÝíô ð¨ì Á×ÜÔÑÝìô ð¨ë Á×ÜÔÑÝëô ð¨ê Á×ÜÔÑÝêô ð¨é Á×ÜÔÑÝéô ð¨è å×ÜÔÑÝ ®»¹·­¬»® ð å°®±¹®¿³³»¼ ¬± ïò å×ÜÔÑÝ ®»¹·­¬»® ï å°®±¹®¿³³»¼ ¬± îò å×ÜÔÑÝ ®»¹·­¬»® î å°®±¹®¿³³»¼ ¬± íò å×ÜÔÑÝ ®»¹·­¬»® í å°®±¹®¿³³»¼ ¬± ìò å×ÜÔÑÝ ®»¹·­¬»® ì å°®±¹®¿³³»¼ ¬± ëò å×ÜÔÑÝ ®»¹·­¬»® ë å°®±¹®¿³³»¼ ¬± êò å×ÜÔÑÝ ®»¹·­¬»® ê å°®±¹®¿³³»¼ ¬± éò å×ÜÔÑÝ ®»¹·­¬»® é å°®±¹®¿³³»¼ ¬± èò Generated by Foxit PDF Creator © Foxit Software For evaluation only. but used to control how code is assembled.39.6 “Assembler Operation”. such as to generate an error message. subsequent code is skipped until an else directive or an endif directive is encountered. For information on types of code.39. .BEGIN CONDITIONALLY ASSEMBLED CODE BLOCK 4. If »¨°® evaluates to true.1 ·º »¨°® Syntax Preferred: Supported: ý·º »¨°® ò·º »¨°® 4.39 ·º .http://www. 4.foxitsoftware. An expression that evaluates to zero is considered logically FALSE.2 Description Begin execution of a conditional assembly block. ©·´´ ¾» ©·´´ ¾» ©·´´ ¾» ©·´´ ¾» ©·´´ ¾» ©·´´ ¾» ©·´´ ¾» ©·´´ ¾» 4.3 Usage This directive is used in the following types of code: absolute or relocatable.39. see Section 1.

39. »´­» and »²¼·º assembly directives.·º/»´­»/»²¼·º åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò 媿®·¿¾´» «­»¼ ¬± ¼»º·²» å®»¯«·®»¼ ½±²º·¹«®¿¬·±² ±º åÐÑÎÌß ú ÐÑÎÌÞ åÍ»¬ ½±²º·¹ ¬± ¼»½·³¿´ òï ð¨ð å̸» ½±¼» ­»½¬·±² ²¿³»¼ ÎÍÌ å·­ °´¿½»¼ ¿¬ °®±¹®¿³ ³»³±®§ å´±½¿¬·±² ð¨ðò ̸» ²»¨¬ ¬©± å·²­¬®«½¬·±²­ ¿®» °´¿½»¼ ·² å½±¼» ­»½¬·±² ÎÍÌò åÖ«³°­ ¬± ¬¸» ´±½¿¬·±² ´¿¾»´´»¼ 厭¬¿®¬Žò å̸·­ ·­ ¬¸» ¾»¹·²²·²¹ ±º ¬¸» å½±¼» ­»½¬·±² ²¿³»¼ ÐÙÓò ׬ ·­ å¿ ®»´±½¿¬¿¾´» ½±¼» ­»½¬·±² å­·²½» ²± ¿¾­±´«¬» ¿¼¼®»­­ ·­ å¹·ª»² ¿´±²¹ ©·¬¸ ¼·®»½¬·ª» ÝÑÜÛò This program demonstrates the utility of ·º.6 Application Example .Generated by Foxit PDF Creator © Foxit Software http://www.com For evaluation only. DS33014K-page 87 . Directives 4.foxitsoftware.39.5 Simple Example ·º ª»®­·±² ãã ïððå ½¸»½µ ½«®®»²¬ ª»®­·±² ³±ª´© ð¨ð¿ ³±ª©º ·±Áï »´­» ³±ª´© ð¨ðï¿ ³±ª©º ·±Áî »²¼·º 4. ý·²½´«¼» °ïêºèéé¿ò·²½ ª¿®·¿¾´» ½º¿¾ ½º¿¾ ­»¬ ÎÍÌ ÝÑÜÛ òï °¿¹»­»´ ¹±¬± ÐÙÓ ÝÑÜÛ ­¬¿®¬ ­¬¿®¬ ­¬¿®¬ ¾¿²µ­»´ ÌÎ×Íß ·º ½º¿¾ããð¨ð ½´®© ³±ª©º ÌÎ×Íß ³±ª´© 𨺺 ³±ª©º ÌÎ×ÍÞ »´­» ½´®© ³±ª©º ÌÎ×ÍÞ ³±ª´© 𨺺 ³±ª©º ÌÎ×Íß »²¼·º ¹±¬± »²¼ ü å׺ ½±²º·¹ããð¨ð ·­ ¬®«»ô å¿­­»³¾´» ¬¸» ³²»³±²·½­ «° ¬± 嬸» ¼·®»½¬·ª» ù»´­»ùò Í»¬ «° ÐÑÎÌß å¿­ ±«¬°«¬ò å׺ ½±²º·¹ããð¨ð ·­ º¿´­»ô å¿­­»³¾´» ¬¸» ³²»³±²·½­ «° ¬± 嬸» ¼·®»½¬·ª» ù»²¼·ºùò Í»¬ «° ÐÑÎÌÞ å¿­ ±«¬°«¬ò åÙ± ¬± ½«®®»²¬ ´·²» ø´±±° ¸»®»÷ 2009 Microchip Technology Inc.

see Section 1. the conditional path is taken.http://www.1 Syntax Preferred: ·º¼»º ´¿¾»´ Supported: ý·º¼»º ´¿¾»´ 4. This directive is not an instruction. 4. 4. without the need to comment out large blocks of code.·º¼»º ý·²½´«¼» °ïêºèéé¿ò·²½ ý¼»º·²» ß´¬»®²¿¬»ßÍÓ åݱ³³»²¬ ±«¬ ©·¬¸ å ·º »¨¬®¿ 庻¿¬«®»­ ²±¬ ¼»­·®»¼ò ý·º¼»º ß´¬»®²¿¬»ßÍÓ Ó§Ð±®¬ »¯« ÐÑÎÌÝ åË­» ᮬ Ý ·º ß´¬»®²¿¬»ßÍÓ ¼»º·²»¼ò ӧ̮·­ »¯« ÌÎ×ÍÝ åÌÎ×ÍÝ ³«­¬ ¾» «­»¼ ¬± ­»¬ ¼¿¬¿ å¼·®»½¬·±² º±® ÐÑÎÌÝò ý»´­» ӧᮬ »¯« ÐÑÎÌÞ Ó§Ì®·­ »¯« ÌÎ×ÍÞ åË­» ᮬ Þ ·º ß´¬»®²¿¬»ßÍÓ ²±¬ ¼»º·²»¼ò åÌÎ×ÍÞ ³«­¬ ¾» «­»¼ ¬± ­»¬ ¼¿¬¿ å¼·®»½¬·±² º±® ÐÑÎÌÞò ý»²¼·º ¾¿²µ­»´ ½´®º ¾¿²µ­»´ ³±ª´© ³±ª©º »²¼ ӧ̮·­ ӧ̮·­ ӧᮬ ëë¸ Ó§Ð±®¬ åÍ»¬ °±®¬ ¬± ¿´´ ±«¬°«¬­ò å묫®² ¬± ¾¿²µ «­»¼ º±® °±®¬ò åÓ±ª» ¿®¾·¬®¿®§ ª¿´«» ¬± É ®»¹ò åÔ±¿¼ °±®¬ ­»´»½¬»¼ ©·¬¸ ëë¸ò DS33014K-page 88 2009 Microchip Technology Inc. For information on types of code.foxitsoftware. not how it behaves at run-time. usually by issuing a ý¼»º·²» directive or by setting the value on the MPASM assembler command line. .40 ·º¼»º .40. but used to control how code is assembled. Assembly will continue until a matching »´­» or »²¼·º directive is encountered.40.40.6 Application Example .40. Use this directive for removing or adding code during debugging.40.4 See Also ý¼»º·²» ý«²¼»º·²» »´­» »²¼·º ·º²¼»º 4.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only.6 “Assembler Operation”.EXECUTE IF SYMBOL HAS BEEN DEFINED 4.5 Simple Example ý¼»º·²» ¬»­¬·²¹ ï å ­»¬ ¬»­¬·²¹ þ±²þ æ ·º¼»º ¬»­¬·²¹ 仨»½«¬» ¬»­¬ ½±¼»â å ¬¸·­ °¿¬¸ ©±«´¼ ¾» »¨»½«¬»¼ò »²¼·º 4.3 Usage This directive is used in the following types of code: absolute or relocatable. 4.40.2 Description If ´¿¾»´ has been previously defined.

41.41. or has been undefined by issuing an ý«²¼»º·²» directive.2 Description If ´¿¾»´ has not been previously defined.6 “Assembler Operation”. The control directive ý¼»º·²» is used to create a “flag” to indicate how to assemble the code . Use this directive for removing or adding code during debugging.3 Usage This directive is used in the following types of code: absolute or relocatable. but used to control how code is assembled.·º¼»º This program uses the control directive ý¼»º·²». This directive is not an instruction. without the need to comment out large blocks of code. Directives 4.1 Syntax Preferred: ·º²¼»º ´¿¾»´ Supported: ý·º²¼»º ´¿¾»´ 4.Generated by Foxit PDF Creator © Foxit Software http://www. along with the ·º¼»º.7 Application Example 2 .for the emulator or for the actual device.5 ý¼»º·²» Simple Example å ­»¬ ¬»­¬·²¹ ±² å ­»¬ ¬»­¬·²¹ ±ºº å ·º ²±¬ ·² ¬»­¬·²¹ ³±¼» å »¨»½«¬» ¬¸·­ °¿¬¸ å »²¼ ±º ­±«®½» ¬»­¬·²¹ï æ ý«²¼»º·²» ¬»­¬·²¹ï ·º²¼»º ¬»­¬·²¹ æ »²¼·º »²¼ 2009 Microchip Technology Inc.41. then the code following the directive will be assembled.41.40.41 ·º²¼»º .EXECUTE IF SYMBOL HAS NOT BEEN DEFINED 4. 4.41. not how it behaves at run-time.4 See Also ý¼»º·²» ý«²¼»º·²» »´­» »²¼·º ·º¼»º 4. ý·²½´«¼» °ïèºìëîò·²½ ý¼»º·²» ÛÓËÔßÌÛÜ ò ò ×Ò×Ì ý·º¼»º ÛÓËÔßÌÛÜ ³±ª´© ð¨¾ð ³±ª©º ð¨ºç½ ý»²¼·º ò ò åݱ³³»²¬ ±«¬ ©·¬¸ å ·º ¿½¬«¿´ °¿®¬ å׺ »³«´¿¬±® «­»¼ô ¿¼¼ ´·²»­ ±º å·²·¬·¿´·¦¿¬·±² ½±¼» ¬± ©±®µ ¿®±«²¼ 嬿¾´» ®»¿¼ ´·³·¬¿¬·±²ò 4. »´­» and »²¼·º directives to selectively assemble code for use with either an emulator or an actual part. Assembly will be enabled or disabled until the next matching »´­» or »²¼·º directive is encountered.com For evaluation only. see Section 1.foxitsoftware. 4. For information on types of code. DS33014K-page 89 .

http://www.foxitsoftware.com Assembler/Linker/Librarian User’s Guide

Generated by Foxit PDF Creator © Foxit Software For evaluation only.

4.41.6

Application Example - ·º²¼»º

ý·²½´«¼» °ïêºèéé¿ò·²½ ý¼»º·²» Ë­»ÐÑÎÌÞ åݱ³³»²¬ ±«¬ ©·¬¸ å ¬± «­» ÐÑÎÌÝ ý·º²¼»º Ë­»ÐÑÎÌÞ Ó§Ð±®¬ »¯« ÐÑÎÌÝ Ó§Ì®·­ »¯« ÌÎ×ÍÝ

åË­» ᮬ Ý ·º Ë­»ÐÑÎÌÞ ²±¬ ¼»º·²»¼ò åÌÎ×ÍÝ ³«­¬ ¾» «­»¼ ¬± ­»¬ ¼¿¬¿ å¼·®»½¬·±² º±® ÐÑÎÌÝò

ý»´­» ӧᮬ »¯« ÐÑÎÌÞ Ó§Ì®·­ »¯« ÌÎ×ÍÞ

åË­» ᮬ Þ ·º Ë­»ÐÑÎÌÞ ¼»º·²»¼ò åÌÎ×ÍÞ ³«­¬ ¾» «­»¼ ¬± ­»¬ ¼¿¬¿ å¼·®»½¬·±² º±® ÐÑÎÌÞò

ý»²¼·º ¾¿²µ­»´ ½´®º ¾¿²µ­»´ ³±ª´© ³±ª©º »²¼ ӧ̮·­ ӧ̮·­ ӧᮬ ëë¸ Ó§Ð±®¬

åÍ»¬ °±®¬ ¬± ¿´´ ±«¬°«¬­ò å묫®² ¬± ¾¿²µ «­»¼ º±® °±®¬ò åÓ±ª» ¿®¾·¬®¿®§ ª¿´«» ¬± É ®»¹ò åÔ±¿¼ °±®¬ ­»´»½¬»¼ ©·¬¸ ëë¸ò

4.42

ý·²½´«¼» - INCLUDE ADDITIONAL SOURCE FILE
4.42.1 Syntax

Preferred:
ý·²½´«¼» ·²½´«¼»Áº·´» ý·²½´«¼» þ·²½´«¼»Áº·´»þ ý·²½´«¼» ä·²½´«¼»Áº·´»â

Supported:
·²½´«¼» ·²½´«¼»Áº·´» ·²½´«¼» þ·²½´«¼»Áº·´»þ ·²½´«¼» ä·²½´«¼»Áº·´»â

4.42.2

Description

The specified file is read in as source code. The effect is the same as if the entire text of the included file were inserted into the file at the location of the include statement. Upon end-of-file, source code assembly will resume from the original source file. Up to 5 levels of nesting are permitted. Up to 255 include files are allowed. If ·²½´«¼»Áº·´» contains any spaces, it must be enclosed in quotes or angle brackets. If a fully qualified path is specified, only that path will be searched. Otherwise, the search order is: • current working directory • source file directory • MPASM assembler executable directory

4.42.3

Usage

This directive is used in the following types of code: absolute or relocatable. For information on types of code, see Section 1.6 “Assembler Operation”. You should use the ·²½´«¼» directive once to include that standard header file for your selected processor. This file contains defined register, bit and other names for a specific processor, so there is no need for you to define all of these in your code.

DS33014K-page 90

2009 Microchip Technology Inc.

Generated by Foxit PDF Creator © Foxit Software http://www.foxitsoftware.com For evaluation only.

Directives

4.42.4

See Also

ý¼»º·²» ý«²¼»º·²»

4.42.5

Simple Example

ý·²½´«¼» °ïèºìëîò·²½ å­¬¿²¼¿®¼ ·²½´«¼» º·´» ý·²½´«¼» þ½æÄЮ±¹®¿³ Ú·´»­Ä³§¼»º­ò·²½þ å«­»® ¼»º·²»­

4.43

´·­¬ - LISTING OPTIONS
4.43.1 Syntax

´·­¬ Å´·­¬Á±°¬·±²ô òòòô ´·­¬Á±°¬·±²Ã

4.43.2

Description

Occurring on a line by itself, the list directive has the effect of turning listing output on, if it had been previously turned off. Otherwise, one of a list of options can be supplied to control the assembly process or format the listing file.

4.43.3

Usage

This directive is used in the following types of code: absolute or relocatable. For information on types of code, see Section 1.6 “Assembler Operation”. TABLE 4-1:
Option ¾ã²²² ½ã²²² ºãº±®³¿¬ 8 132 INHX8M

LIST DIRECTIVE OPTIONS
Default Set tab spaces. Set column width. Set the hex file output. format can be INHX32, INHX8M, or INHX8S. Note: Hex file format is set in MPLAB IDE (Build Options dialog.) Use free-format parser. Provided for backward compatibility. Use fixed-format parser. Print memory map in list file. Set lines per page. Set processor type; for example, PIC16F54. See also °®±½»­­±®ò Note: Processor type is set in MPLAB IDE (Configure>Device.) Set processor type and enable extended instruction set, for example; Ô×ÍÌ °»ãÐ×ÝïèÚìêîð Only valid with processors which support the extended instruction set and the generic processor PIC18XXX. Is overridden by command-line option ñ§ó (disable extended instruction set). Note: Processor type is set in MPLAB IDE (Configure>Device.) Set radix: hex, dec, oct. See also ®¿¼·¨. Print symbol table in list file. Truncate lines of listing (otherwise wrap). Set the message level. See also »®®±®´»ª»´. Description

º®»» º·¨»¼ ³³ã¥ÑÒ¤ÑÚÚ£ ²ã²²² °ã¬§°»

FIXED FIXED On 60 None

°»ã¬§°»

None

®ã®¿¼·¨ ­¬ã¥ÑÒ¤ÑÚÚ£ ¬ã¥ÑÒ¤ÑÚÚ£ ©ã¥ð¤ï¤î£

hex On Off 0

2009 Microchip Technology Inc.

DS33014K-page 91

http://www.foxitsoftware.com Assembler/Linker/Librarian User’s Guide
TABLE 4-1:
Option ¨ã¥ÑÒ¤ÑÚÚ£ On

Generated by Foxit PDF Creator © Foxit Software For evaluation only.

LIST DIRECTIVE OPTIONS (CONTINUED)
Default Description Turn macro expansion on or off.

Note:

All list options are evaluated as decimal numbers by default.

4.43.4

See Also

»®®±®´»ª»´ »¨°¿²¼ ²±»¨°¿²¼ ²±´·­¬ °®±½»­­±® ®¿¼·¨

4.43.5

Simple Example

Set the processor type to PIC18F452, the hex file output format to INHX32 and the radix to decimal.
´·­¬ °ãïèºìëîô ºã×ÒØÈíîô ®ãÜÛÝ

4.44

´±½¿´ - DECLARE LOCAL MACRO VARIABLE
4.44.1 Syntax

Preferred:
´±½¿´ ´¿¾»´Åô´¿¾»´òòòÃ

Supported:
ò´±½¿´ ´¿¾»´Åô´¿¾»´òòòÃ

4.44.2

Description

Declares that the specified data elements are to be considered in local context to the macro. ´¿¾»´ may be identical to another label declared outside the macro definition; there will be no conflict between the two. If the macro is called recursively, each invocation will have its own local copy.

4.44.3

Usage

This directive is used in the following types of code: absolute or relocatable. For information on types of code, see Section 1.6 “Assembler Operation”. If you use a macro more than once and there is a label in it, you will get a “Duplicate Label” error unless you use this directive.

4.44.4

See Also

»²¼³ ³¿½®±

4.44.5

Simple Example

䳿·² ½±¼» ­»¹³»²¬â æ æ ´»² »¯« ïð ­·¦» »¯« î𠬻­¬

å ¹´±¾¿´ ª»®­·±² å ²±¬» ¬¸¿¬ ¿ ´±½¿´ ª¿®·¿¾´» å ³¿§ ²±© ¾» ½®»¿¬»¼ ¿²¼ ³±¼·º·»¼

³¿½®± ­·¦» ´±½¿´ ´»²ô ´¿¾»´ å ´±½¿´ ´»² ¿²¼ ´¿¾»´ ´»² ­»¬ ­·¦» å ³±¼·º§ ´±½¿´ ´»² ´¿¾»´ ®»­ ´»² å ®»­»®ª» ¾«ºº»® ´»² ­»¬ ´»²óîð »²¼³ å »²¼ ³¿½®±

DS33014K-page 92

2009 Microchip Technology Inc.

Generated by Foxit PDF Creator © Foxit Software http://www.foxitsoftware.com For evaluation only.

Directives

4.44.6

Application Example - ´±½¿´

This code demonstrates the utility of ´±½¿´ directive, which declares that the specified data elements are to be considered in local context to the macro.
ý·²½´«¼» °ïêºèéé¿ò·²½ åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò åß­­»³¾´»® ª¿®·¿¾´» ·²½® ·­ ­»¬ 廯«¿´ ¬± îò åÜ»½´¿®¿¬·±² ±º ³¿½®± ù¿¼¼Á·²½®ùò åÔ±½¿´ ¿­­»³¾´»® ª¿®·¿¾´» ù·²½®ùò

·²½®

»¯«

î

¿¼¼Á·²½® ³¿½®± ´±½¿´ ·²½®

The same name ·²½® is used in the main code, where its value is set to 2.
·²½® ­»¬ í åÔ±½¿´ ù·²½®ù ·­ ­»¬ ¬± íô ·² å½±²¬®¿­¬ ¬± ù·²½®ù ª¿´«» 屺 î ·² ³¿·² ½±¼»ò å© ®»¹·­¬»® ·­ ­»¬ ¬± ¦»®± å© ®»¹·­¬»® ·­ ¿¼¼»¼ ¬± ·²½® ¿²¼ å®»­«´¬ °´¿½»¼ ¾¿½µ å·² © ®»¹·­¬»®ò ð¨ð å̸» ½±¼» ­»½¬·±² ²¿³»¼ ÎÍÌ å·­ °´¿½»¼ ¿¬ °®±¹®¿³ ³»³±®§ å´±½¿¬·±² ð¨ðò ̸» ²»¨¬ ¬©± å·²­¬®«½¬·±²­ ¿®» °´¿½»¼ ·² å½±¼» ­»½¬·±² ÎÍÌò åÖ«³°­ ¬± ¬¸» ´±½¿¬·±² ´¿¾»´´»¼ 厭¬¿®¬Žò å̸·­ ·­ ¬¸» ¾»¹·²²·²¹ ±º ¬¸» å½±¼» ­»½¬·±² ²¿³»¼ ÐÙÓò ׬ ·­ å¿ ®»´±½¿¬¿¾´» ½±¼» ­»½¬·±² å­·²½» ²± ¿¾­±´«¬» ¿¼¼®»­­ ·­ å¹·ª»² ¿´±²¹ ©·¬¸ ¼·®»½¬·ª» ÝÑÜÛò åÉ ®»¹·­¬»® ­»¬ ¬± ¦»®±ò ·²½® åÉ ®»¹·­¬»® ·­ ¿¼¼»¼ ©·¬¸ ¬¸» 媿´«» ±º ·²½® ©¸·½¸ ·­ ²±© »¯«¿´ 嬱 îò åÉ ®»¹·­¬»® ·­ ¿¼¼»¼ ©·¬¸ ¬¸» 媿´«» ±º ·²½® ©¸·½¸ ·­ ²±© »¯«¿´ 嬱 í øª¿´«» ­»¬ ´±½¿´´§ ·² ¬¸» 峿½®± ¿¼¼Á·²½®÷ò åÉ ®»¹·­¬»® ·­ ­»¬ ¬± ¦»®± ¿¹¿·²ò ·²½® å·²½® ·­ ¿¼¼»¼ ¬± É ®»¹·­¬»® ¿²¼ å®»­«´¬ °´¿½»¼ ·² É ®»¹·­¬»®ò å·²½® ª¿´«» ·­ ¿¹¿·² îô ²±¬ 忺º»½¬»¼ ¾§ ¬¸» ª¿´«» ­»¬ ·² ¬¸» 峿½®±ò åÙ± ¬± ½«®®»²¬ ´·²» ø´±±° ¸»®»÷

½´®© ¿¼¼´© »²¼³ ÎÍÌ

·²½®

ÝÑÜÛ

°¿¹»­»´ ¹±¬± ÐÙÓ ÝÑÜÛ

­¬¿®¬ ­¬¿®¬

­¬¿®¬ ½´®© ¿¼¼´©

¿¼¼Á·²½®

½´®© ¿¼¼´©

¹±¬± »²¼

ü

2009 Microchip Technology Inc.

DS33014K-page 93

http://www.foxitsoftware.com Assembler/Linker/Librarian User’s Guide

Generated by Foxit PDF Creator © Foxit Software For evaluation only.

4.45

³¿½®± - DECLARE MACRO DEFINITION
4.45.1 Syntax

´¿¾»´ ³¿½®± Å¿®¹ô òòòô ¿®¹Ã

4.45.2

Description

A macro is a sequence of instructions that can be inserted in the assembly source code by using a single macro call. The macro must first be defined, then it can be referred to in subsequent source code. Arguments are read in from the source line, stored in a linked list and then counted. The maximum number of arguments would be the number of arguments that would fit on the source line, after the label and macro terms. Therefore, the maximum source line length is 200 characters. A macro can call another macro, or may call itself recursively. The maximum number of nested macro calls is 16. Please refer to Chapter 7. “Macro Language” for more information.

4.45.3

Usage

This directive is used in the following types of code: absolute or relocatable. For information on types of code, see Section 1.6 “Assembler Operation”.

4.45.4

See Also

»²¼³ »¨·¬³ ´±½¿´

4.45.5

Simple Example

åÜ»º·²» ³¿½®± λ¿¼ λ¿¼ ³¿½®± ¼»ª·½»ô ¾«ºº»®ô ½±«²¬ ³±ª´© ¼»ª·½» ³±ª©º ®¿³Áîð ³±ª´© ¾«ºº»® å ¾«ºº»® ¿¼¼®»­­ ³±ª©º ®¿³Áîï ³±ª´© ½±«²¬ å ¾§¬» ½±«²¬ ½¿´´ ­§­Áîï å ­«¾®±«¬·²» ½¿´´ »²¼³ æ åË­» ³¿½®± λ¿¼ λ¿¼ ð¨ðô ð¨ëëô ð¨ðë

4.45.6

Application Example - ³¿½®±/»²¼³
åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò åß­­·¹² ª¿´«» îðØ ¬± ´¿¾»´ å®»­«´¬ò å̸» º±´´±©·²¹ ½±¼» ©·´´ ¾» °´¿½»¼ å·² ®»­»¬ ¿¼¼®»­­ ðò åÖ«³° ¬± ¿² ¿¼¼®»­­ ©¸±­» ´¿¾»´ ·­ åù­¬¿®¬ùò åù¿¼¼ù ·­ ¿ ³¿½®±ò ̸» ª¿´«»­ ±º åù²«³ïù ¿²¼ ù²«³îù ³«­¬ ¾» °¿­­»¼ 嬱 ¬¸·­ ³¿½®±ò

This code demonstrates the utility of ³¿½®± directive, which is used to define a macro.
ý·²½´«¼» °ïêºèéé¿ò·²½

®»­«´¬

»¯«

ð¨îð

ÑÎÙ ¹±¬±

ð¨ðððð ­¬¿®¬

¿¼¼

ÓßÝÎÑ

²«³ïô²«³î

DS33014K-page 94

2009 Microchip Technology Inc.

46 ÁÁ³¿¨®¿³ . Directives ³±ª´© ²«³ï åÔ±¿¼ É ®»¹·­¬»® ©·¬¸ ¿ ´·¬»®¿´ 媿´«» ¿­­·¹²»¼ ¬± ¬¸» ´¿¾»´ åù²«³ïùò åÔ±¿¼ É ®»¹·­¬»® ¬± ¿² ¿¼¼®»­­ å´±½¿¬·±² ¿­­·¹²»¼ ¬± ¬¸» ´¿¾»´ åù®»­«´¬ùò åÔ±¿¼ É ®»¹·­¬»® ©·¬¸ ¿ ´·¬»®¿´ 媿´«» ¿­­·¹²»¼ ¬± ¬¸» ´¿¾»´ åù²«³îùò åß¼¼ É ®»¹·­¬»® ©·¬¸ ¬¸» ³»³±®§ å´±½¿¬·±² ¿¼¼®»­­»¼ ¾§ ù®»­«´¬ù 忲¼ ´±¿¼ ¬¸» ®»­«´¬ ¾¿½µ ¬± åù®»­«´¬ùò 廲¼ ±º ù¿¼¼ù ÓßÝÎÑ ³±ª©º ®»­«´¬ ³±ª´© ²«³î ¿¼¼©º ®»­«´¬ »²¼³ ÑÎÙ ­¬¿®¬ ð¨ððïð åÓ¿·² °®±¹®¿³ ­¬¿®¬­ ¿¬ ïðØò å̸» ´¿¾»´ ù­¬¿®¬ù ·­ ¿­­·¹²»¼ ¿² 忼¼®»­­ ïðØò ¿¼¼ òïððôòçð åÝ¿´´ ù¿¼¼ù ÓßÝÎÑ ©·¬¸ ¼»½·³¿´ 岫³¾»®­ ïðð ¿²¼ çð ¿­­·¹²»¼ ¬± åù²«³ïù ¿²¼ ù²«³îù ´¿¾»´­ô å®»­°»½¬·ª»´§ò ïðð ¿²¼ çð ©·´´ ¾» 忼¼»¼ ¿²¼ ¬¸» ®»­«´¬ ©·´´ ¾» ·² åù®»­«´¬ùò »²¼ 4. Each use redefines the maximum valid RAM address and resets the RAM map to all locations. strict RAM address checking is enabled.foxitsoftware. 2009 Microchip Technology Inc. 4. ÁÁ³¿¨®¿³ defines the absolute maximum valid RAM address and initializes the map of valid RAM addresses to all addresses valid at and below »¨°®.46.Generated by Foxit PDF Creator © Foxit Software http://www. This directive is designed for use with the ÁÁ¾¿¼®¿³ directive.com For evaluation only. ÁÁ³¿¨®¿³ can be used more than once in a source file. »¨°® must be greater than or equal to the maximum page 0 RAM address and less than 1000H.2 Description The ÁÁ³¿¨®¿³ and ÁÁ¾¿¼®¿³ directives together flag accesses to unimplemented registers.DEFINE MAXIMUM RAM LOCATION Note: ³¿¨®¿³ is preceded by two underline characters. using the RAM map specified by ÁÁ¾¿¼®¿³.1 Syntax ÁÁ³¿¨®¿³ »¨°® 4.46. Once the ÁÁ³¿¨®¿³ directive is used. DS33014K-page 95 .

For information on types of code.5 Simple Example See the examples for ÁÁ¾¿¼®±³. ÁÁ³¿¨®±³ can be used more than once in a source file. strict ROM address checking is enabled. 4.47. using the ROM map specified by ÁÁ¾¿¼®±³.46.47.47. 4.DEFINE MAXIMUM ROM LOCATION Note: ³¿¨®±³ is preceded by two underline characters.6 “Assembler Operation”. see Section 1.3 Usage This directive is used in the following types of code: absolute or relocatable.3 Usage This directive is used in the following types of code: absolute or relocatable. 4. This directive is not commonly used in user code.48. 4. as RAM and ROM details are handled by the include files (öò·²½) or linker script files (öò´µ®).47 ÁÁ³¿¨®±³ . This directive is not commonly used in user code. ÁÁ³¿¨®±³ defines the absolute maximum valid ROM address and initializes the map of valid ROM addresses to all addresses valid at and below »¨°®. as RAM and ROM details are handled by the include files (öò·²½) or linker script files (öò´µ®).CREATE USER DEFINED MESSAGE 4.2 Description The ÁÁ³¿¨®±³ and ÁÁ¾¿¼®±³ directives together flag accesses to unimplemented registers. see Section 1.5 Simple Example See the examples for ÁÁ¾¿¼®¿³.46.1 Syntax ³»­­¹ þ³»­­¿¹»Á¬»¨¬þ DS33014K-page 96 2009 Microchip Technology Inc. 4.4 ÁÁ¾¿¼®±³ See Also 4.47. .4 ÁÁ¾¿¼®¿³ See Also 4. 4. Once the ÁÁ³¿¨®±³ directive is used. »¨°® must be greater than or equal to the maximum ROM address of the target device.foxitsoftware.1 Syntax ÁÁ³¿¨®±³ »¨°® 4. Each use redefines the maximum valid ROM address and resets the ROM map to all locations.6 “Assembler Operation”.http://www.47. 4.48 ³»­­¹ . For information on types of code.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. This directive is designed for use with the ÁÁ¾¿¼®±³ directive.46.

48. to verify in the assembled program which code was built. The message text can be up to 80 characters. 2400. 9600 or 19200 Hz. ÎÍÌ ÝÑÜÛ ð¨ð å̸» ½±¼» ­»½¬·±² ²¿³»¼ ÎÍÌ å·­ °´¿½»¼ ¿¬ °®±¹®¿³ ³»³±®§ å´±½¿¬·±² ð¨ðò ̸» ²»¨¬ ¬©± å·²­¬®«½¬·±²­ ¿®» °´¿½»¼ ·² å½±¼» ­»½¬·±² ÎÍÌò åÖ«³°­ ¬± ¬¸» ´±½¿¬·±² ´¿¾»´´»¼ 厭¬¿®¬Žò å̸·­ ·­ ¬¸» ¾»¹·²²·²¹ ±º ¬¸» å½±¼» ­»½¬·±² ²¿³»¼ ÐÙÓò ׬ ·­ å¿ ®»´±½¿¬¿¾´» ½±¼» ­»½¬·±² å­·²½» ²± ¿¾­±´«¬» ¿¼¼®»­­ ·­ å¹·ª»² ¿´±²¹ ©·¬¸ ¼·®»½¬·ª» ÝÑÜÛò °¿¹»­»´ ¹±¬± ÐÙÓ ÝÑÜÛ ­¬¿®¬ ­¬¿®¬ 2009 Microchip Technology Inc.48.48.Generated by Foxit PDF Creator © Foxit Software http://www.2 Description Causes an informational message to be printed in the listing file. 4.48. For information on types of code. 4800. which sets a message to be printed in the listing file and error file.6 Application Example . Directives 4.5 Simple Example ³­­¹Á³¿½®± ³¿½®± ³»­­¹ þ³­­¹Á³¿½®±óððï ·²ª±µ»¼ ©·¬¸±«¬ ¿®¹«³»²¬þ »²¼³ 4. This directive may be used to generate any desired message. DS33014K-page 97 .4 »®®±® See Also 4.foxitsoftware.6 “Assembler Operation”.48. Issuing a messg directive does not set any error return codes.3 Usage This directive is used in the following types of code: absolute or relocatable. 4.com For evaluation only. It can be useful with conditional assembly. ý·²½´«¼» °ïêºèéé¿ò·²½ åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò 媿®·¿¾´» «­»¼ ¬± ¼»º·²» å®»¯«·®»¼ ¾¿«¼ ®¿¬» åÛ²¬»® ¬¸» ®»¯«·®»¼ ª¿´«» ±º 徿«¼ ®¿¬» ¸»®»ò ª¿®·¿¾´» ¾¿«¼®¿¬» ¾¿«¼®¿¬» ­»¬ Üùëêððù ·º ø¾¿«¼®¿¬»ÿãÜùïîððù÷úúø¾¿«¼®¿¬»ÿãÜùîìððù÷úú ø¾¿«¼®¿¬»ÿãÜùìèððù÷úúø¾¿«¼®¿¬»ÿãÜùçêððù÷úú ø¾¿«¼®¿¬»ÿãÜùïçîððù÷ »®®±® þÍ»´»½¬»¼ ¾¿«¼ ®¿¬» ·­ ²±¬ ­«°°±®¬»¼þ ³»­­¹ þ±²´§ ¾¿«¼ ®¿¬»­ ïîððôîìððôìèððôçêðð ú ïçîðð ئ þúú þ¿®» ­«°°±®¬»¼þ »²¼·º The ·º-»²¼·º code outputs »®®±® and ³»­­¹ if the baud rate selected is other than 1200.³»­­¹ This program demonstrates the ³»­­¹ assembler directive. see Section 1.

2 Description and Usage Turn off listing file output. .TURN OFF LISTING OUTPUT 4. This directive is used in the following types of code: absolute. see Section 1.4 Simple Example Code example: æ åÜ»º·²» ¿ ³¿½®± ¬± ¿¼¼ ¬©± ²«³¾»®­ ¿¼¼ ³¿½®± ²«³ïô²«³î ³±ª´© ²«³ï ³±ª©º ®»­«´¬ ³±ª´© ²«³î ¿¼¼©º ®»­«´¬ »²¼³ æ ²±»¨°¿²¼ åË­» ³¿½®± ¿¼¼ ¿¼¼ òïððôòçð Resulting listing file: ðððîç ðððíð ðððíï ²±»¨°¿²¼ ¿¼¼ òïððôòçð 4.49.49 ²±»¨°¿²¼ .foxitsoftware. see Section 1.49.http://www. 4. This directive suppresses the information required for the listing file and source-level debugging.3 ´·­¬ See Also DS33014K-page 98 2009 Microchip Technology Inc.49.2 Description and Usage Turns off macro expansion in the listing file. For information on types of code. For information on types of code.49.com Assembler/Linker/Librarian User’s Guide ­¬¿®¬ ¹±¬± ü »²¼ Generated by Foxit PDF Creator © Foxit Software For evaluation only.50. 4.50.6 “Assembler Operation”.3 »¨°¿²¼ See Also 4. åÙ± ¬± ½«®®»²¬ ´·²» ø´±±° ¸»®»÷ 4. This directive is used in the following types of code: absolute or relocatable.50 ²±´·­¬ .1 ²±´·­¬ Syntax 4.50.6 “Assembler Operation”.1 ²±»¨°¿²¼ Syntax 4.TURN OFF MACRO EXPANSION 4. This will prevent the ability to debug the source code.

SET PROGRAM ORIGIN 4.4 See Also º·´´ ®»­ »²¼ 4. the ±®¹ directive is interpreted as introducing an absolute ÝÑÜÛ section with an internally generated name. For information on types of code. and will be distinct from every name previously generated in this context. 4. For example: Ôïæ ±®¹ ð¨îðð is interpreted as: ò­½²²¿³» Ôïæ ÝÑÜÛ ð¨îðð where ò­½²²¿³» is generated by the assembler. Directives 4.6 PIC16 Application Example .com For evaluation only. 0x8 (PIC18 device high-priority interrupt vector) and 0x18 (PIC18 device low-priority interrupt vector).51 ±®¹ . ±®¹ is commonly used in single-file assembly programs whenever code needs to be placed at a particular location.foxitsoftware. If no ±®¹ is specified.51. When generating an object file. A data table may be placed either in a program memory region or in an EE data memory region. For PIC18 devices. Commonly used values are 0x0 (reset).±®¹ This example shows the usage of the ±®¹ directive.51.51.6 “Assembler Operation”. ý·²½´«¼» °ïêºèéé¿ò·²½ åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò å̸» º±´´±©·²¹ ½±¼» ©·´´ ¾» å°´¿½»¼ ·² ®»­»¬ ¿¼¼®»­­ ðò åÖ«³° ¬± ¿² ¿¼¼®»­­ ©¸±­» ´¿¾»´ å·­ ùÓ¿·²ùò å̸» º±´´±©·²¹ ½±¼» ©·´´ ¾» å°´¿½»¼ ·² ·²¬»®®«°¬ ¿¼¼®»­­ ìò ±®¹ ¹±¬± ð¨ðððð Ó¿·² ±®¹ ð¨ðððì 2009 Microchip Technology Inc.3 Usage This directive is used in the following types of code: absolute.51. code generation will begin at address zero. The origin of a data table also can be specified by this directive. 4.5 Simple Example ·²¬Áï ±®¹ ð¨îð å Ê»½¬±® îð ½±¼» ¹±»­ ¸»®» ·²¬Áî ±®¹ ·²¬Áïõð¨ïð å Ê»½¬±® íð ½±¼» ¹±»­ ¸»®» 4.51.51.2 Description Set the program origin for subsequent code at the address defined in »¨°®. 0x4 (PIC16 device interrupt vector). see Section 1. If ´¿¾»´ is specified.Generated by Foxit PDF Creator © Foxit Software http://www. it will be given the value of the »¨°®. Code generation begins at an address specified by ±®¹ address. only even-numbered »¨°® values are allowed. as in case of a PIC1X device with EE data FLASH.1 Syntax Å´¿¾»´Ã ±®¹ »¨°® 4. DS33014K-page 99 .

The origin of a data table also can be specified by this directive. åÖ«³° ¬± ¿² ¿¼¼®»­­ ©¸±­» ´¿¾»´ å·­ ù·²¬Á®±«¬·²»ùò å̸» º±´´±©·²¹ ½±¼» ­»½¬·±² ©·´´ å°´¿½»¼ ­¬¿®¬·²¹ º®±³ ¿¼¼®»­­ ïðØò åÉ®·¬» §±«® ³¿·² °®±¹®¿³ ¸»®»ò ±®¹ Ó¿·² å å å ¹±¬± ±®¹ ð¨ððïð Ó¿·² ð¨ðïðð åÔ±±° ¾¿½µ ¬± ùÓ¿·²ùò å̸» º±´´±©·²¹ ½±¼» ­»½¬·±² ©·´´ å¾» °´¿½»¼ ­¬¿®¬·²¹ º®±³ ¿¼¼®»­­ åïððØò ·²¬Á®±«¬·²» å å å ®»¬º·» åÉ®·¬» §±«® ·²¬»®®«°¬ ­»®ª·½» å®±«¬·²» ¸»®»ò å묫®² º®±³ ·²¬»®®«°¬ò ±®¹ ð¨ïððð åDZ« ½¿² ½®»¿¬» ¿ ¼¿¬¿ ±® 彸¿®¿½¬»® ¬¿¾´» ­¬¿®¬·²¹ º®±³ 忲§ ¿¼¼®»­­ ·² °®±¹®¿³ ³»³±®§ò åײ ¬¸·­ ½¿­» ¬¸» ¿¼¼®»­­ ·­ åïððð¸ò åê °®±¹®¿³ ³»³±®§ ´±½¿¬·±²­ åø­¬¿®¬·²¹ º®±³ ïððð¸÷ ©·´´ å¾» º·´´»¼ ©·¬¸ ­·¨ ïìó¾·¬ å°¿½µ»¼ ²«³¾»®­ô »¿½¸ å®»°®»­»²¬·²¹ ¬©± éó¾·¬ ßÍÝ×× å½¸¿®¿½¬»®­ò ½¸Á¬¾´ï ¼¿ þÐ×Ý©·¬¸ÚÔßÍØþ ±®¹ ð¨îïðð å̸» ¿¾­±´«¬» ¿¼¼®»­­ îïð𸠷­ 峿°°»¼ ¬± ¬¸» ðððð ´±½¿¬·±² ±º åÛÛ ¼¿¬¿ ³»³±®§ ·² Ð×ÝïêÚ¨¨¨ò åDZ« ½¿² ½®»¿¬» ¿ ¼¿¬¿ ±® 彸¿®¿½¬»® ¬¿¾´» ­¬¿®¬·²¹ º®±³ 忲§ ¿¼¼®»­­ ·² ÛÛ ¼¿¬¿ ³»³±®§ò åïî ÛÛ ¼¿¬¿ ³»³±®§ ´±½¿¬·±²­ åø­¬¿®¬·²¹ º®±³ ð÷ ©·´´ ¾» 康´´»¼ ©·¬¸ ïî ßÍÝ×× å½¸¿®¿½¬»®­ò ½¸Á¬¾´î ¼» þÐ×Ý©·¬¸ÚÔßÍØþ »²¼ 4.7 PIC18 Application Example .51. as in case of a PIC1X device with EE data FLASH.http://www. ý·²½´«¼» °ïèºìëîò·²½ åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò å̸» º±´´±©·²¹ ½±¼» ©·´´ ¾» å°®±¹®¿³³»¼ ·² ®»­»¬ ¿¼¼®»­­ ðò ±®¹ ð¨ðððð DS33014K-page 100 2009 Microchip Technology Inc.±®¹ This example shows the usage of the ±®¹ directive. .foxitsoftware.com Assembler/Linker/Librarian User’s Guide ¹±¬± ·²¬Á®±«¬·²» Generated by Foxit PDF Creator © Foxit Software For evaluation only. Code generation begins at an address specified by ±®¹ address. A data table may be placed either in a program memory region or in an EE data memory region.

INSERT LISTING PAGE EJECT 4.52 °¿¹» . DS33014K-page 101 .52.1 °¿¹» Syntax 2009 Microchip Technology Inc.com For evaluation only.foxitsoftware. Directives ¹±¬± Ó¿·² åÖ«³° ¬± ¿² ¿¼¼®»­­ ©¸±­» ´¿¾»´ ·­ åùÓ¿·²ùò å̸» º±´´±©·²¹ ½±¼» ©·´´ ¾» å°®±¹®¿³³»¼ ·² ¸·¹¸ °®·±®·¬§ å·²¬»®®«°¬ ¿¼¼®»­­ èò åÖ«³° ¬± ¿² ¿¼¼®»­­ ©¸±­» ´¿¾»´ ·­ åù·²¬Á¸·ùò å̸» º±´´±©·²¹ ½±¼» ©·´´ ¾» å°®±¹®¿³³»¼ ·² ´±© °®·±®·¬§ å·²¬»®®«°¬ ¿¼¼®»­­ ïè¸ò åÖ«³° ¬± ¿² ¿¼¼®»­­ ©¸±­» ´¿¾»´ ·­ åù·²¬Á´±ùò å̸» º±´´±©·²¹ ½±¼» ­»½¬·±² ©·´´ å¾» °®±¹®¿³³»¼ ­¬¿®¬·²¹ º®±³ 忼¼®»­­ îðØò åÉ®·¬» §±«® ³¿·² °®±¹®¿³ ¸»®»ò ±®¹ ð¨ðððè ¹±¬± ·²¬Á¸· ±®¹ ð¨ððïè ¹±¬± ·²¬Á´± ±®¹ ð¨ððîð Ó¿·² å å å ¹±¬± ±®¹ Ó¿·² ð¨ðïðð åÔ±±° ¾¿½µ ¬± ùÓ¿·²ù å̸» º±´´±©·²¹ ½±¼» ­»½¬·±² ©·´´ å¾» °®±¹®¿³³»¼ ­¬¿®¬·²¹ º®±³ 忼¼®»­­ ïððØò ·²¬Á¸· å å å ®»¬º·» ±®¹ ð¨ðîðð åÉ®·¬» §±«® ¸·¹¸ °®·±®·¬§ å·²¬»®®«°¬ ­»®ª·½» ®±«¬·²» ¸»®»ò å묫®² º®±³ ·²¬»®®«°¬ò å̸» º±´´±©·²¹ ½±¼» ­»½¬·±² ©·´´ å¾» °®±¹®¿³³»¼ ­¬¿®¬·²¹ º®±³ 忼¼®»­­ îððØò ·²¬Á´± å å å ®»¬º·» ±®¹ ð¨ïððð åÉ®·¬» §±«® ´±© °®·±®·¬§ å·²¬»®®«°¬ ­»®ª·½» ®±«¬·²» ¸»®»ò å묫®² º®±³ ·²¬»®®«°¬ò åDZ« ½¿² ½®»¿¬» ¿ ¼¿¬¿ ±® 彸¿®¿½¬»® ¬¿¾´» ­¬¿®¬·²¹ º®±³ ¿²§ 忼¼®»­­ ·² °®±¹®¿³ ³»³±®§ò ײ 嬸·­ ½¿­» ¬¸» ¿¼¼®»­­ ·­ ïððð¸ò ½¸Á¬¾´ï »²¼ ¼¾ þÐ×Ý©·¬¸ÚÔßÍØþ 4.Generated by Foxit PDF Creator © Foxit Software http://www.

If the device contains only one page of program memory. 4. For PIC18 devices. a combination of BSF and BCF commands will be used to adjust bits 3 and 4 of the PCLATH register. this command will do nothing as these devices do not use paging. For information on types of code. For PIC16 extended devices.2 Description and Usage Inserts a page eject into the listing file.2 Description An instruction to the linker to generate page selecting code to set the page bits to the page containing the designated ´¿¾»´. since it automatically generates code.3 Usage This directive is used in the following types of code: absolute or relocatable. 4.52. This directive saves you from having to manually code page bit changes. This directive is used in the following types of code: absolute or relocatable.http://www. no code will be generated.GENERATE PAGE SELECTING CODE (PIC10/12/16 MCUs) 4.4 See Also ¾¿²µ·­»´ ¾¿²µ­»´ 4. see Section 1. The linker will generate the appropriate page selecting code: For 12-bit instruction width (PIC10F. the appropriate bit set/clear instructions on the STATUS register will be generated.5K for 12-bit instruction width devices). For information on types of code.6 “Assembler Operation”. you must use the °¿¹»­»´© directive.1 Syntax °¿¹»­»´ ´¿¾»´ 4. some PIC12/PIC16) devices. it is recommended that you use this directive. For 14-bit instruction width (most PIC12/PIC16) devices.6 “Assembler Operation”. Only one ´¿¾»´ should be specified. a ³±ª´° instruction is generated to set the page. If you are using relocatable code and your device has more than 2k program memory (or 0.53.53. No operations can be performed on ´¿¾»´. . see Section 1.53.foxitsoftware. 4. 4. Also.3 See Also ´·­¬ ­«¾¬·¬´» ¬·¬´» 4.53.52.5 Simple Example °¿¹»­»´ Ù±¬±Ü»­¬ ¹±¬± Ù±¬±Ü»­¬ æ °¿¹»­»´ Ý¿´´Ü»­¬ ½¿´´ Ý¿´´Ü»­¬ DS33014K-page 102 2009 Microchip Technology Inc. ´¿¾»´ must have been previously defined. especially when code must jump between two or more code sections. If you wish to indicate the start address of a RETLW table or a jump table for computed GOTOs.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. the code is much more portable.53 °¿¹»­»´ .53.

´¿¾»´ must have been previously defined. no code will be generated. Only one ´¿¾»´ should be specified.1 Syntax °¿¹»­»´© ´¿¾»´ 4. The linker will generate the appropriate page selecting code.54. since it automatically generates code.2 Description An instruction to the linker to generate page selecting code to set the page bits to the page containing the designated ´¿¾»´.3 Usage This directive is used in the following types of code: absolute or relocatable.Generated by Foxit PDF Creator © Foxit Software http://www.foxitsoftware. see Section 1. the appropriate bit set/clear instructions on the STATUS register will be generated. ý·²½´«¼» °ïêºèéé¿ò·²½ åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò å̸» ½±¼» ­»½¬·±² ²¿³»¼ ÎÍÌ å·­ °´¿½»¼ ¿¬ °®±¹®¿³ ³»³±®§ å´±½¿¬·±² ð¨ðò ̸» ²»¨¬ ¬©± å·²­¬®«½¬·±²­ ¿®» °´¿½»¼ ·² å½±¼» ­»½¬·±² ÎÍÌò åÖ«³°­ ¬± ¬¸» ´±½¿¬·±² ´¿¾»´´»¼ 厭¬¿®¬Žò å̸» ½±¼» ­»½¬·±² ²¿³»¼ ÐÙÓï ·­ å°´¿½»¼ ¿¬ ð¨ëððò 忼¼®»­­ ¾·¬­ ïî ú ïï ±º å°¿¹»ïÁ°¹³ ¿®» ½±°·»¼ ¬± ÐÝÔßÌØ åì ú í ®»­°»½¬·ª»´§ò ÎÍÌ ÝÑÜÛ ð¨ð °¿¹»­»´ ¹±¬± ÐÙÓð ­¬¿®¬ ­¬¿®¬ ð¨ëðð ÝÑÜÛ ­¬¿®¬ °¿¹»­»´ °¿¹»ïÁ°¹³ ¹±¬± ÐÙÓï °¿¹»ïÁ°¹³ ÝÑÜÛ ð¨çðð å̸» ½±¼» ­»½¬·±² ²¿³»¼ ÐÙÓï ·­ å°´¿½»¼ ¿¬ ð¨çððò Ô¿¾»´ å°¿¹»ïÁ°¹³ ·­ ´±½¿¬»¼ ·² ¬¸·­ å½±¼» ­»½¬·±²ò åÙ± ¬± ½«®®»²¬ ´·²» ø´±±° ¸»®»÷ °¿¹»ïÁ°¹³ ¹±¬± ü »²¼ 4. 4. 2009 Microchip Technology Inc.54 °¿¹»­»´© . which generates the appropriate code to set/clear ÐÝÔßÌØ bits. this command will do nothing as these devices do not use paging. DS33014K-page 103 . some PIC12/PIC16) devices.6 Application Example . If the device contains only one page of program memory. For information on types of code.54. This directive saves you from having to manually code page bit changes. Also.GENERATE PAGE SELECTING CODE USING WREG COMMANDS (PIC10/12/16 MCUs) 4. This allows easier use of paged memory such as found on PIC16 devices. the code is much more portable. No operations can be performed on ´¿¾»´.°¿¹»­»´ This program demonstrates the °¿¹»­»´ directive.6 “Assembler Operation”. For 14-bit instruction width (most PIC12/PIC16) devices.com For evaluation only. ÓÑÊÔÉ and ÓÑÊÉÚ instructions will be generated to modify the PCLATH. For PIC18 devices.54.53. For 12-bit instruction width (PIC10F. Directives 4.

5 Simple Example åÍ»¬­ °®±½»­­±® ¬± Ð×ÝïêÚèééß °®±½»­­±® ïêºèéé¿ DS33014K-page 104 2009 Microchip Technology Inc.55. You must use this directive instead of °¿¹»­»´ if you wish to indicate the start address of a RETLW table or a jump table for computed GOTOs.4 See Also ¾¿²µ·­»´ ¾¿²µ­»´ 4.54.6 “Assembler Operation”. 4. 4. see Section 1.54. it is recommended that you use this directive. especially when code must jump between two or more code sections. 4. Only then will all the 5 top-most bits of the PC will be loaded with the appropriate value when an 8-bit offset is added to the PC.http://www.5 Simple Example °¿¹»­»´© ݱ³³¿²¼Ì¿¾´»Í¬¿®¬ åÙ»¬ ¬¸» ¾§¬» ®»¿¼ ¿²¼ «­» ·¬ ¬± ³±ª´© ݱ³³¿²¼Ì¿¾´»Í¬¿®¬ å·²¼»¨ ·²¬± ±«® ¶«³° ¬¿¾´»ò ׺ ¿¼¼©º ݱ³³òΨ̨ާ¬»ô© å©» ½®±­­»¼ ¿ îëê󾧬» ¾±«²¼¿®§ô ¾¬º­½ ÍÌßÌËÍôÝ å¬¸»² ·²½®»³»²¬ ÐÝÔßÌØò ̸»² ´±¿¼ ¬¸» ·²½º ÐÝÔßÌØôº å°®±¹®¿³ ½±«²¬»® ©·¬¸ ½±³°«¬»¼ ¹±¬±ò ³±ª©º ÐÝÔ Ý±³³¿²¼Ì¿¾´»Í¬¿®¬ ¹±¬± Ù»¬Ê»®­·±² ¹±¬± Ù»¬ÎÌÍ¿³°´» ¹±¬± ݱ²º·¹«®» ¹±¬± Ù± ¹±¬± λ¿¼Þ«ºº»® ¹±¬± ß®»Ç±«Ì¸®±«¹¸Ç»¬ ¹±¬± ݱ³³Ü±²» ¹±¬± ݱ³³Ü±²» åð¨ðð åð¨ðï åð¨ðî åð¨ðí åð¨ðì åð¨ðë åð¨ðê åð¨ðé ó ó ó ó ó Ù»¬ Ê»®­·±² Ù»¬ λ¿´ Ì·³» ­¿³°´» ­¬«¾ ­¬«¾ λ¿¼ Þ«ºº»®ô ¶«­¬ ­»²¼­ ʱ«¬ 4. . The 256-word boundaries will still have to be considered. If you are using relocatable code and your device has more than 2k program memory (or 0. This directive is not generally used as the processor is set in MPLAB IDE (Configure>Device.) If it must be set in code.55 °®±½»­­±® .55.SET PROCESSOR TYPE 4.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only.55. For information on types of code. as discussed in Application Note AN586.55.55.1 Syntax °®±½»­­±® °®±½»­­±®Á¬§°» 4.foxitsoftware.2 Description Sets the processor type to °®±½»­­±®Á¬§°».4 ´·­¬ See Also 4. use °®±½»­­±® or the ´·­¬ directive option °ã to set the processor.5K for 12-bit instruction width devices).3 Usage This directive is used in the following types of code: absolute or relocatable.

Directives 4. the default radix.Generated by Foxit PDF Creator © Foxit Software http://www.5 Simple Example ®¿¼·¨ ¼»½ 4. then the default radix is in hex(adecimal). is used and there is no need to set the radix. Valid radix values are: • hex .4 “Numeric Constants and Radix”.com For evaluation only. For specifying the radix of constants.1 Syntax ®¿¼·¨ ¼»º¿«´¬Á®¿¼·¨ 4. For information on types of code.octal (base 8) You may also specify a radix using the ´·­¬ directive. you should exercise care. see Section 1. see Section 3.6 “Assembler Operation”. DS33014K-page 105 .56. If not declared. 4.6 Application Example . if you need to change the radix in your program.56. ´·­¬ ®ã¼»½ ý·²½´«¼» °ïêºèéé¿ò·²½ åÍ»¬ ¬¸» ®¿¼·¨ ¿­ ¼»½·³¿´ò åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò åëð ·­ ·² ¸»¨ åß²±¬¸»® ©¿§ ±º ¼»½´¿®·²¹ ë𠸻¨ åëð ·­ ·² ±½¬¿´ åëð ·­ ²±¬ ¼»½´¿®»¼ ¿­ ¸»¨ ±® å±½¬¿´ ±® ¼»½·³¿´ò ͱ ¾§ ¼»º¿«´¬ å·¬ ·­ ·² ¼»½·³¿´ ¿­ ¼»º¿«´¬ ®¿¼·¨ å·­ ¼»½´¿®»¼ ¿­ ¼»½·³¿´ò åË­» ®¿¼·¨Ž ¬± ¼»½´¿®» ¼»º¿«´¬ 宿¼·¨ ¿­ ±½¬¿´ò åëð ·­ ·² ¸»¨ò åß²±¬¸»® ©¿§ ±º ¼»½´¿®·²¹ ë𠸻¨ò åëð ·­ ·² ¼»½·³¿´ò ³±ª´© ³±ª´© ³±ª´© ³±ª´© ëðØ ð¨ëð ëðÑ ëð ®¿¼·¨ ±½¬ ³±ª´© ³±ª´© ³±ª´© ëðØ ð¨ëð òëð 2009 Microchip Technology Inc.56. For many programs.56.2 Description Sets the default radix for data expressions.3 Usage This directive is used in the following types of code: absolute or relocatable.hexadecimal (base 16) • dec . hex.SPECIFY DEFAULT RADIX 4.foxitsoftware. See the radix example for more on the implications of changing the radix.4 ´·­¬ See Also 4. The default radix is hex. 4.56.®¿¼·¨ This example shows the usage of the ®¿¼·¨ directive for data presentation. However. Use the ®¿¼·¨ directive or the ´·­¬ directive option ®ã to change the radix in your code.56.56 ®¿¼·¨ .decimal (base 10) • oct . as all numeric values following the ®¿¼·¨ declaration will use that radix value.

the ®»­ directive does not reserve an odd number of locations for PIC18 MCUs in non-relocatable mode.http://www. 4.foxitsoftware.6 Application Example .2 Description Causes the memory location pointer to be advanced from its current location by the value specified in ³»³Á«²·¬­.57 ®»­ .6 “Assembler Operation”.30 and later. The calculated perimeter will be stored in the double-precision buffer addressed by °»®·³»¬»®. In relocatable code (using MPLINK linker). Length and width of the rectangle will be stored in buffers addressed by ´»²¹¬¸ and ©·¼¬¸.57. Address locations are defined in words for PIC12/16 MCUs. In non-relocatable code. ´¿¾»´ is assumed to be a program memory address. ý·²½´«¼» °ïèºìëîò·²½ åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò å̸·­ ¼·®»½¬·ª» ¿´´±©­ ¬¸» 庱´´±©·²¹ ¼¿¬¿ ¬± ¾» °´¿½»¼ ±²´§ å·² ¬¸» ¼¿¬¿ ¿®»¿ò ËÜßÌß DS33014K-page 106 2009 Microchip Technology Inc.com Assembler/Linker/Librarian User’s Guide ³±ª´© ëð Generated by Foxit PDF Creator © Foxit Software For evaluation only.4 See Also º·´´ ±®¹ »¯« ½¾´±½µ 4. For MPASM v3.®»­ This example shows the advantage of ®»­ directive in developing relocatable code. see Section 1.RESERVE MEMORY 4. The program calculates the perimeter of a rectangle. 4.57. and bytes for PIC18 MCUs. ®»­ can be used to reserve data storage.57.57. The most common usage for ®»­ is for data storage in relocatable code. For information on types of code.1 Syntax Å´¿¾»´Ã ®»­ ³»³Á«²·¬­ 4.57. .57. åëð ·­ ²±¬ ¼»½´¿®»¼ ¿­ ¸»¨ ±® å±½¬¿´ ±® ¼»½·³¿´ò ͱ ¾§ ¼»º¿«´¬ å·¬ ·­ ·² ±½¬¿´ ¿­ ¼»º¿«´¬ ®¿¼·¨ å·­ ¼»½´¿®»¼ ¿­ ±½¬¿´ò åÒ±© ¼»º¿«´¬ ®¿¼·¨ ·­ ·² ¸»¨ò åëð ·­ ¼»½´¿®»¼ ·² ¼»½·³¿´ò åëð ·­ ¼»½´¿®»¼ ·² ±½¬¿´ åëð ·­ ²±¬ ¼»½´¿®»¼ ¿­ ¸»¨ ±® å±½¬¿´ ±® ¼»½·³¿´ò ͱ ¾§ ¼»º¿«´¬ å·¬ ·­ ·² ¸»¨ ¿­ ¼»º¿«´¬ ®¿¼·¨ å·­ ¼»½´¿®»¼ ¿­ ¸»¨ò ®¿¼·¨ ³±ª´© ³±ª´© ³±ª´© ¸»¨ òëð ëðÑ ëð »²¼ 4.3 Usage This directive is used in the following types of code: absolute or relocatable.5 Simple Example ¾«ºº»® ®»­ êì å ®»­»®ª» êì ¿¼¼®»­­ ´±½¿¬·±²­ ±º ­¬±®¿¹» 4.

DS33014K-page 107 . ¹±¬± »²¼ ü åÙ± ¬± ½«®®»²¬ ´·²» ø´±±° ¸»®»÷ 2009 Microchip Technology Inc. ½±¼» is also different in that an address is not normally specified. But ±®¹ is used with MPASM assembler to generate absolute code and ½±¼» is used with MPLINK linker to generate an object file. Directives °»®·³»¬»® ®»­ î ´»²¹¬¸ ®»­ ï ©·¼¬¸ ®»­ ï åÌ©± ´±½¿¬·±²­ ±º ³»³±®§ ¿®» å®»­»®ª»¼ º±® ¬¸» ´¿¾»´ åù°»®·³»¬»®ùò ß¼¼®»­­»­ ±º ¬¸» å³»³±®§ ´±½¿¬·±²­ ©·´´ ¾» å¿´´±½¿¬»¼ ¾§ ¬¸» ´·²µ»®ò åѲ» ´±½¿¬·±² ±º ³»³±®§ ·­ å®»­»®ª»¼ º±® ¬¸» ´¿¾»´ ù´»²¹¬¸ùò åß¼¼®»­­ ±º ¬¸» ³»³±®§ ´±½¿¬·±² å©·´´ ¾» ¿´´±½¿¬»¼ ¾§ ¬¸» ´·²µ»®ò åѲ» ´±½¿¬·±² ±º ³»³±®§ ·­ å®»­»®ª»¼ º±® ¬¸» ´¿¾»´ ù©·¼¬¸ùò åß¼¼®»­­ ±º ¬¸» ³»³±®§ ´±½¿¬·±² å©·´´ ¾» ¿´´±½¿¬»¼ ¾§ ¬¸» ´·²µ»®ò åÚ±´´±©·²¹ ½±¼» ©·´´ ¾» °´¿½»¼ ·² 忼¼®»­­ ðò ͬ¿®¬ ÝÑÜÛ ð¨ðððð Here the directive ½±¼» has the same effect as ±®¹. the linker handles the allocation of space.com For evaluation only. both in program Flash and data RAM memory.foxitsoftware. ¹±¬± ÐÛÎÁÝßÔ ÝÑÜÛ åÖ«³° ¬± ´¿¾»´ ÐÛÎÁÝßÔ åÝÑÜÛ ¼·®»½¬·ª» ¸»®» ¼·½¬¿¬»­ ¬¸¿¬ 嬸» º±´´±©·²¹ ´·²»­ ±º ½±¼» ©·´´ å¾» °´¿½»¼ ·² °®±¹®¿³ ³»³±®§ô ¾«¬ 嬸» ­¬¿®¬·²¹ ¿¼¼®»­­ ©·´´ ¾» å¼»½·¼»¼ ¾§ ¬¸» ´·²µ»®ò ÐÛÎÁÝßÔ ½´®º °»®·³»¬»®õï ³±ªº ´»²¹¬¸ô© ¿¼¼©º ©·¼¬¸ô© ³±ª©º °»®·³»¬»® ®´º °»®·³»¬»®õï ®´º ®´º °»®·³»¬»® °»®·³»¬»®õï åÝ´»¿® ¬¸» ¸·¹¸ ¾§¬» ±º ¬¸» ´¿¾»´ åù°»®·³»¬»®ùò åÓ±ª» ¬¸» ¼¿¬¿ °®»­»²¬ ·² ¬¸» å®»¹·­¬»® ¿¼¼®»­­»¼ ¾§ ù´»²¹¬¸ù 嬱 ù©ùò åß¼¼ ¼¿¬¿ ·² ù©ù ©·¬¸ ¼¿¬¿ ·² ¬¸» å®»¹·­¬»® ¿¼¼®»­­»¼ ¾§ ù©·¼¬¸ùò åÍÌßÌËÍ ®»¹·­¬»® ½¿®®§ ¾·¬ Ý å³¿§ ¾» ¿ºº»½¬»¼ò åÓ±ª» ù©ù ¬± ¬¸» °»®·³»¬»® ´±© 徧¬» ¿¬ ¿¼¼®»­­ îðØò Ý¿®®§ ¾·¬ å·­ «²¿ºº»½¬»¼ò åײ½®»³»²¬ ®»¹·­¬»® îïØ ·º ½¿®®§ å©¿­ ¹»²»®¿¬»¼ò ß´­± ½´»¿® ½¿®®§ å·º ¾·¬ ©¿­ ­»¬ò åÓ«´¬·°´§ ®»¹·­¬»® îðØ ¾§ îò åÝ¿®®§ ¾·¬ ³¿§ ¾» ¿ºº»½¬»¼ò åß¹¿·²ô ·²½®»³»²¬ ®»¹·­¬»® îïØ å·º ½¿®®§ ©¿­ ¹»²»®¿¬»¼ò The previous two lines of code will multiply (by left-shifting one bit) the intermediate result by 2.Generated by Foxit PDF Creator © Foxit Software http://www.

58 ­»¬ .5 ¿®»¿ ©·¼¬¸ ´»²¹¬¸ ¿®»¿ ´»²¹¬¸ Simple Example ­»¬ ­»¬ ­»¬ ­»¬ ­»¬ ð ð¨ïî ð¨ïì ´»²¹¬¸ ö ©·¼¬¸ ´»²¹¬¸ õ ï 4. .g.6 “Assembler Operation”.4 See Also »¯« ª¿®·¿¾´» ©¸·´» 4. ´²¹¬¸ ©¼¬¸ »¯« »¯« ëðØ îëØ å̸» 嬸» å̸» 嬸» ´¿¾»´ ª¿´«» ´¿¾»´ ª¿´«» ù´²¹¬¸ù ·­ ¿­­·¹²»¼ ëðØò ù©¼¬¸ù ·­ ¿­­·¹²»¼ îëØò DS33014K-page 108 2009 Microchip Technology Inc..) 4. The ­»¬ directive is functionally equivalent to the »¯« directive except that set values may be subsequently altered by other ­»¬ directives.58.6 Application Example .58. Because ­»¬ directive values may be altered by later ­»¬ directives. a ©¸·´» loop.58.­»¬/»¯« This example shows the usage of the ­»¬ directive. For information on types of code. ­»¬ is particularly useful when defining a variable in a loop (e.2 Description ´¿¾»´ is assigned the value of the valid MPASM assembler expression specified by »¨°®.1 Syntax Preferred: ´¿¾»´ ­»¬ »¨°® Supported: ´¿¾»´ ò­»¬ »¨°® 4. used for creating symbols which may be used in MPASM assembler expressions only. ý·²½´«¼» °ïêºèéé¿ò·²½ åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò å̸» ´¿¾»´ ù°»®·³»¬»®ù ·­ å¿­­·¹²»¼ ª¿´«» ðò å̸» ´¿¾»´ ù¿®»¿ù ·­ ¿­­·¹²»¼ 媿´«» ðò °»®·³»¬»® ­»¬ ¿®»¿ ­»¬ ð ð The value assigned by the ­»¬ directive may be reassigned later.58.foxitsoftware.DEFINE AN ASSEMBLER VARIABLE 4.58. 4. see Section 1.3 Usage This directive is used in the following types of code: absolute or relocatable.58.http://www. The symbols created with this directive do not occupy any physical memory location on the microcontroller.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. 4.

60. This directive establishes a second program header line for use as a subtitle in the listing output.6 “Assembler Operation”.2 Description and Usage Insert »¨°® number of blank lines into the listing file.INSERT BLANK LISTING LINES 4.59.60 ­«¾¬·¬´» .3 ´·­¬ See Also 4.Generated by Foxit PDF Creator © Foxit Software http://www. 4. °»®·³»¬»® ­»¬ ¿®»¿ ­»¬ »²¼ îöø´²¹¬¸õ©¼¬¸÷ ´²¹¬¸ö©¼¬¸ åÞ±¬¸ ù°»®·³»¬»®ù ¿²¼ åù¿®»¿ù ª¿´«»­ ¿®» å®»¿­­·¹²»¼ò 4. Directives The value assigned by the »¯« directive may not be reassigned later.60.4 Simple Example ­°¿½» í åײ­»®¬­ ¬¸®»» ¾´¿²µ ´·²»­ 4.6 “Assembler Operation”.SPECIFY PROGRAM SUBTITLE 4.2 Description and Usage ­«¾Á¬»¨¬ is an ASCII string enclosed in double quotes.59. For information on types of code. 60 characters or less in length.com For evaluation only.59.3 See Also ´·­¬ ¬·¬´» 4. This directive is used in the following types of code: absolute or relocatable.1 Syntax Preferred: ­«¾¬·¬´» þ­«¾Á¬»¨¬þ Supported: ­¬·¬´» þ­«¾Á¬»¨¬þ ­«¾¬·¬´ þ­«¾Á¬»¨¬þ 4.4 Simple Example ­«¾¬·¬´» þ¼·¿¹²±­¬·½ ­»½¬·±²þ 2009 Microchip Technology Inc.60. For information on types of code.59.foxitsoftware.59 ­°¿½» . This directive is used in the following types of code: absolute or relocatable.60. DS33014K-page 109 .1 Syntax Preferred: ­°¿½» »¨°® Supported: ­°¿½ »¨°® 4. 4. see Section 1. see Section 1.

62 «¼¿¬¿ . see Section 1. For absolute code. which declares the beginning of a section of uninitialized data. you must do this in code.SPECIFY PROGRAM TITLE 4. Note: Two sections in the same source file are not permitted to have the same name.1 Syntax ¬·¬´» þ¬·¬´»Á¬»¨¬þ 4. The ®»­ directive should be used to reserve space for data.62. It must be 60 characters or less. If ´¿¾»´ is not specified. 4.61.62.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only.5 Simple Example «¼¿¬¿ Ê¿®ï ®»­ ï ܱ«¾´» ®»­ î 4.2 Description and Usage ¬·¬´»Á¬»¨¬ is a printable ASCII string enclosed in double quotes. the section is named ò«¼¿¬¿.4 Simple Example ¬·¬´» þ±°»®¿¬·±²¿´ ½±¼»ô ®»ª ëòðþ 4. For information on types of code.«¼¿¬¿ This program demonstrates the «¼¿¬¿ directive. this directive is used to create a data (RAM) section.4 See Also »¨¬»®² ¹´±¾¿´ ·¼¿¬¿ «¼¿¬¿Á¿½­ «¼¿¬¿Á±ª® «¼¿¬¿Á­¸® 4.62.62. For information on types of code. Use directives »¯« or ½¾´±½µ. The starting address is initialized to the specified address or will be assigned at link time if no address is specified. «¼¿¬¿ does not set (initialize) the starting value of the variables.62.61. For relocatable code.1 Syntax Å´¿¾»´Ã «¼¿¬¿ ÅÎßÓÁ¿¼¼®»­­Ã 4.foxitsoftware. 4.3 See Also ´·­¬ ­«¾¬·¬´» 4. DS33014K-page 110 2009 Microchip Technology Inc. This directive establishes the text to be used in the top line of each page in the listing file.http://www. see Section 1.6 “Assembler Operation”. 4. do not use this directive.6 Application Example .61.61. This directive is used in the following types of code: absolute or relocatable. .2 Description This directive declares the beginning of a section of uninitialized data. No code can be generated in this segment.6 “Assembler Operation”. 4.BEGIN AN OBJECT FILE UNINITIALIZED DATA SECTION 4.61 ¬·¬´» .62.3 Usage This directive is used in the following types of code: relocatable.

If ´¿¾»´ is not specified. The ®»­ directive should be used to reserve space for data. Note: Two sections in the same source file are not permitted to have the same name. DS33014K-page 111 .BEGIN AN OBJECT FILE ACCESS UNINITIALIZED DATA SECTION (PIC18 MCUs) 4.Generated by Foxit PDF Creator © Foxit Software http://www.2 Description This directive declares the beginning of a section of access uninitialized data. the section is named ò«¼¿¬¿Á¿½­. No code can be generated in this segment.1 Syntax Å´¿¾»´Ã «¼¿¬¿Á¿½­ ÅÎßÓÁ¿¼¼®»­­Ã 4. 2009 Microchip Technology Inc.63 «¼¿¬¿Á¿½­ .com For evaluation only. The starting address is initialized to the specified address or will be assigned at link time if no address is specified.63.63. This directive is used to declare variables that are allocated in access RAM of PIC18 devices.foxitsoftware. Directives ý·²½´«¼» °ïêºèéé¿ò·²½ åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò å¹®±«°ï ¼¿¬¿ å­¬¿®¬·²¹ ¿¬ å¹®±«°ïÁª¿®ï å¹®±«°ïÁª¿®î ­¬±®»¼ ¿¬ ´±½¿¬·±²­ ð¨îðò ´±½¿¬»¼ ¿¬ ð¨îðò ´±½¿¬»¼ ¿¬ ð¨îïò ¹®±«°ï «¼¿¬¿ ð¨îð ®»­ ®»­ ï ï ¹®±«°ïÁª¿®ï ¹®±«°ïÁª¿®î ¹®±«°î «¼¿¬¿ ¹®±«°îÁª¿®ï ¹®±«°îÁª¿®î ÎÍÌ ÝÑÜÛ ®»­ ®»­ ð¨ð ï ï åÜ»½´¿®¿¬·±² ±º ¹®±«°î ¼¿¬¿ò ̸» 忼¼®»­­»­ º±® ª¿®·¿¾´»­ «²¼»® 嬸·­ ¼¿¬¿ ­»½¬·±² ¿®» ¿´´±½¿¬»¼ å¿«¬±³¿¬·½¿´´§ ¾§ ¬¸» ´·²µ»®ò å̸» ½±¼» ­»½¬·±² ²¿³»¼ ÎÍÌ å·­ °´¿½»¼ ¿¬ °®±¹®¿³ ³»³±®§ å´±½¿¬·±² ð¨ðò ̸» ²»¨¬ ¬©± å·²­¬®«½¬·±²­ ¿®» °´¿½»¼ ·² å½±¼» ­»½¬·±² ÎÍÌò åÖ«³°­ ¬± ¬¸» ´±½¿¬·±² ´¿¾»´´»¼ 厭¬¿®¬Žò å̸·­ ·­ ¬¸» ¾»¹·²²·²¹ ±º ¬¸» å½±¼» ­»½¬·±² ²¿³»¼ ÐÙÓò ׬ ·­ å¿ ®»´±½¿¬¿¾´» ½±¼» ­»½¬·±² å­·²½» ²± ¿¾­±´«¬» ¿¼¼®»­­ ·­ å¹·ª»² ¿´±²¹ ©·¬¸ ¼·®»½¬·ª» ÝÑÜÛò °¿¹»­»´ ¹±¬± ÐÙÓ ÝÑÜÛ ­¬¿®¬ ­¬¿®¬ ­¬¿®¬ ¾¿²µ­»´ ¹®±«°ïÁª¿®ï ½´®º ¹®±«°ïÁª¿®ï ½´®º ¹®±«°ïÁª¿®î ¾¿²µ­»´ ¹®±«°îÁª¿®ï ½´®º ¹®±«°îÁª¿®ï ½´®º ¹®±«°îÁª¿®î ¹±¬± »²¼ ü åÙ± ¬± ½«®®»²¬ ´·²» ø´±±° ¸»®»÷ 4.

This directive declares the beginning of a section of uninitialized data.63.4 See Also »¨¬»®² ¹´±¾¿´ ·¼¿¬¿ «¼¿¬¿ «¼¿¬¿Á±ª® «¼¿¬¿Á­¸® 4.63.«¼¿¬¿Á¿½­ This program demonstrates the «¼¿¬¿Á¿½­ directive.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only.5 Simple Example «¼¿¬¿Á¿½­ Ê¿®ï ®»­ ï ܱ«¾´» ®»­ î 4. 4. except that it is used only for PIC18 devices and will only place variables in access RAM.6 Application Example .63. Variables in access memory can be used no matter where the bank select register (BSR) is pointing. PIC18 devices have an area of RAM known as access RAM.foxitsoftware. 4. This directive is similar to «¼¿¬¿.http://www.6 “Assembler Operation”. see Section 1. .3 Usage This directive is used in the following types of code: relocatable. For information on types of code.63. ý·²½´«¼» °ïèºìëîò·²½ åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò å¹®±«°ï ¼¿¬¿ ­¬±®»¼ ¿¬ ¿½½»­­ åÎßÓ ´±½¿¬·±²­ ­¬¿®¬·²¹ ¿¬ ð¨îðò å¹®±«°ïÁª¿®ï ´±½¿¬»¼ ¿¬ ð¨îðò å¹®±«°ïÁª¿®î ´±½¿¬»¼ ¿¬ ð¨îïò åÜ»½´¿®¿¬·±² ±º ¹®±«°î ¼¿¬¿ò ̸» 忼¼®»­­»­ º±® ¼¿¬¿ «²¼»® ¬¸·­ å­»½¬·±² ¿®» ¿´´±½¿¬»¼ å¿«¬±³¿¬·½¿´´§ ¾§ ¬¸» ´·²µ»®ò åß´´ ¿¼¼®»­­»­ ¾» ©·´´ ¿´´±½¿¬»¼ å·² ¿½½»­­ ÎßÓ ­°¿½» ±²´§ò å̸» ½±¼» ­»½¬·±² ²¿³»¼ ÎÍÌ å·­ °´¿½»¼ ¿¬ °®±¹®¿³ ³»³±®§ å´±½¿¬·±² ð¨ðò ̸» ·²­¬®«½¬·±² åù¹±¬± ­¬¿®¬ù ·­ °´¿½»¼ ·² å½±¼» ­»½¬·±² ÎÍÌò åÖ«³°­ ¬± ¬¸» ´±½¿¬·±² ´¿¾»´´»¼ åù­¬¿®¬ùò å̸·­ ·­ ¬¸» ¾»¹·²²·²¹ ±º ¬¸» ½±¼» å­»½¬·±² ²¿³»¼ ÐÙÓò ׬ ·­ ¿ å®»´±½¿¬¿¾´» ½±¼» ­»½¬·±² å­·²½» ²± ¿¾­±´«¬» ¿¼¼®»­­ ·­ å¹·ª»² ¿´±²¹ ©·¬¸ ¼·®»½¬·ª» ÝÑÜÛò ¹®±«°ï «¼¿¬¿Á¿½­ ®»­ ®»­ ð¨îð ï ï ¹®±«°ïÁª¿®ï ¹®±«°ïÁª¿®î ¹®±«°î «¼¿¬¿Á¿½­ ¹®±«°îÁª¿®ï ¹®±«°îÁª¿®î ÎÍÌ ÝÑÜÛ ®»­ ®»­ ð¨ð ï ï ¹±¬± ­¬¿®¬ ÐÙÓ ÝÑÜÛ ­¬¿®¬ ½´®º ½´®º ½´®º ½´®º ¹®±«°ïÁª¿®ïôß ¹®±«°ïÁª¿®îôß ¹®±«°îÁª¿®ïôß ¹®±«°îÁª¿®îôß å¹®±«°ïÁª¿®ï ·²·¬·¿´·¦»¼ ¬± ¦»®± å¹®±«°ïÁª¿®î ·²·¬·¿´·¦»¼ ¬± ¦»®± å¹®±«°îÁª¿®ï ·²·¬·¿´·¦»¼ ¬± ¦»®± å¹®±«°îÁª¿®î ·²·¬·¿´·¦»¼ ¬± ¦»®± DS33014K-page 112 2009 Microchip Technology Inc. It is very useful for frequently-used and global variables.

The space declared by this section is overlaid by all other «¼¿¬¿Á±ª® sections of the same name.4 See Also »¨¬»®² ¹´±¾¿´ ·¼¿¬¿ «¼¿¬¿ «¼¿¬¿Á¿½­ «¼¿¬¿Á­¸® 4. Note: Two sections in the same source file are not permitted to have the same name. DS33014K-page 113 .6 “Assembler Operation”. The starting address is initialized to the specified address or will be assigned at link time if no address is specified.Generated by Foxit PDF Creator © Foxit Software http://www.64. but is not needed since the assembler will automatically locate variables in access memory. if possible.com For evaluation only. 4. except that it allows you to reuse data space by “overlaying” one data area on another. “A” references the access RAM.2 Description This directive declares the beginning of a section of overlaid uninitialized data. Directives ¹±¬± »²¼ ü åÙ± ¬± ½«®®»²¬ ´·²» ø´±±° ¸»®»÷ In the code above.64. This directive is similar to «¼¿¬¿. It is an ideal way of declaring temporary variables since it allows multiple variables to be declared at the same memory location.64. the section is named ò«¼¿¬¿Á±ª®. It is used for temporary variables.64 «¼¿¬¿Á±ª® .64. 4. The ®»­ directive should be used to reserve space for data.1 Syntax Å´¿¾»´Ã «¼¿¬¿Á±ª® ÅÎßÓÁ¿¼¼®»­­Ã 4.3 Usage This directive is used in the following types of code: relocatable. 4. No code can be generated in this segment.foxitsoftware. This A designation can be explicitly stated by the code.64.5 Simple Example Ì»³°­ Ì»³°ï Ì»³°î Ì»³°í Ì»³°­ Ô±²¹Ì»³°ï «¼¿¬¿Á±ª® ®»­ ï ®»­ ï ®»­ ï «¼¿¬¿Á±ª® ®»­ î å ¬¸·­ å ­¿³» Ô±²¹Ì»³°î ®»­ î å ¬¸·­ å ­¿³» ©·´´ ¾» ¿ ª¿®·¿¾´» ¿¬ ¬¸» ´±½¿¬·±² ¿­ Ì»³°ï ¿²¼ Ì»³°î ©·´´ ¾» ¿ ª¿®·¿¾´» ¿¬ ¬¸» ´±½¿¬·±² ¿­ Ì»³°í 2009 Microchip Technology Inc. as each data section may overwrite (and thus share) the same RAM address locations. For information on types of code.BEGIN AN OBJECT FILE OVERLAID UNINITIALIZED DATA SECTION 4. If ´¿¾»´ is not specified. see Section 1.

com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only.«¼¿¬¿Á±ª® This program demonstrates the «¼¿¬¿Á±ª® directive.64. . 4.6 Application Example .foxitsoftware.http://www. This directive declares the beginning of a section of overlaid uninitialized data. ý·²½´«¼» °ïêºèéé¿ò·²½ åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò åÜ»½´¿®»­ ¿² ±ª»®´¿·¼ 嫲·²·¬·¿´·¦»¼ ¼¿¬¿ ­»½¬·±² 岿³»¼ù­¿³»Áª¿®ù ­¬¿®¬·²¹ ¿¬ å´±½¿¬·±² ð¨îðò åÜ»½´¿®»­ ¿² ±ª»®´¿·¼ 嫲·²·¬·¿´·¦»¼ ¼¿¬¿ ­»½¬·±² å©·¬¸ ¬¸» ­¿³» ²¿³» ¿­ ¬¸» ±²» å¼»½´¿®»¼ ¿¾±ª»ò ̸«­ ª¿®·¿¾´»­ 媿®ï ¿²¼ ª¿®î ¿®» ¿´´±½¿¬»¼ 忬 ¬¸» ­¿³» ¿¼¼®»­­ò å̸» ½±¼» ­»½¬·±² ²¿³»¼ ÎÍÌ å·­ °´¿½»¼ ¿¬ °®±¹®¿³ ³»³±®§ å´±½¿¬·±² ð¨ðò ̸» ²»¨¬ ¬©± å·²­¬®«½¬·±²­ ¿®» °´¿½»¼ ·² å½±¼» ­»½¬·±² ÎÍÌò åÖ«³°­ ¬± ¬¸» ´±½¿¬·±² ´¿¾»´´»¼ 厭¬¿®¬Žò å̸·­ ·­ ¬¸» ¾»¹·²²·²¹ ±º ¬¸» å½±¼» ­»½¬·±² ²¿³»¼ ÐÙÓò ׬ ·­ å¿ ®»´±½¿¬¿¾´» ½±¼» ­»½¬·±² å­·²½» ²± ¿¾­±´«¬» ¿¼¼®»­­ ·­ å¹·ª»² ¿´±²¹ ©·¬¸ ¼·®»½¬·ª» ÝÑÜÛò åß²§ ±°»®¿¬·±² ±² ª¿®ï ¿ºº»½¬­ 媿®î ¿´­± ­·²½» ¾±¬¸ ª¿®·¿¾´»­ å¿®» ±ª»®´¿·¼ò ­¿³»Áª¿® «¼¿¬¿Á±ª® ð¨î𠪿®ï ­¿³»Áª¿® ª¿®î ®»­ ï ð¨îð «¼¿¬¿Á±ª® ®»­ ï ÎÍÌ ÝÑÜÛ ð¨ð °¿¹»­»´ ¹±¬± ÐÙÓ ­¬¿®¬ ­¬¿®¬ ÝÑÜÛ ­¬¿®¬ ¾¿²µ­»´ ª¿®ï ³±ª´© ð¨ÚÚ ³±ª©º ª¿®ï ½±³º ¹±¬± ü »²¼ ª¿®î åÙ± ¬± ½«®®»²¬ ´·²» ø´±±° ¸»®»÷ DS33014K-page 114 2009 Microchip Technology Inc.

See the data sheet for the PIC16F873A for a specific example.65. 4.3 Usage This directive is used in the following types of code: relocatable.foxitsoftware.65. The ®»­ directive should be used to reserve space for data. unbanked RAM. 4. This directive is used to declare variables that are allocated in RAM that is shared across all RAM banks (i. unbanked RAM). This directive is used to declare variables that are allocated in RAM that is shared across all RAM banks (i. DS33014K-page 115 . Directives 4.5 Ì»³°­ Ì»³°ï Ì»³°î Ì»³°í Simple Example «¼¿¬¿Á­¸® ®»­ ï ®»­ ï ®»­ ï 4. For information on types of code. No code can be generated in this segment.e. If ´¿¾»´ is not specified.4 See Also »¨¬»®² ¹´±¾¿´ ·¼¿¬¿ «¼¿¬¿ «¼¿¬¿Á¿½­ «¼¿¬¿Á±ª® 4.65. see Section 1.65. This directive is similar to «¼¿¬¿. «¼¿¬¿Á­¸® sections are used with SHAREBANK locations in the linker script.6 “Assembler Operation”.Generated by Foxit PDF Creator © Foxit Software http://www.1 Syntax Å´¿¾»´Ã «¼¿¬¿Á­¸® ÅÎßÓÁ¿¼¼®»­­Ã 4.BEGIN AN OBJECT FILE SHARED UNINITIALIZED DATA SECTION (PIC12/16 MCUs) 4.) ý·²½´«¼» °ïêºèéé¿ò·²½ åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò åÜ»½´¿®»­ ¬¸» ¾»¹·²²·²¹ ±º ¿ ¼¿¬¿ å­»½¬·±² ²¿³»¼ ù­¸¿®»¼ ¼¿¬¿ùô 婸·½¸ ·­ ­¸¿®»¼ ¾§ ¿´´ ¾¿²µ­ò åùª¿®ù ·­ ¬¸» ´±½¿¬·±² ©¸·½¸ ½¿² å¾» ¿½½»­­»¼ ·®®»­°»½¬·ª» ±º 徿²µ­»´ ¾·¬­ò åÜ»½´¿®»­ ¾»¹·²²·²¹ ±º ¿ ¼¿¬¿ å­»½¬·±² ²¿³»¼ ù¾¿²µðÁª¿®ùô 婸·½¸ ·­ ·² ¾¿²µðò ª¿®ð ·­ å¿´´±½¿¬»¼ ¬¸» ¿¼¼®»­­ ð¨îðò ­¸¿®»¼Á¼¿¬¿ ª¿® «¼¿¬¿Á­¸® ®»­ ï ¾¿²µðÁª¿® «¼¿¬¿ ª¿®ð ®»­ ðÈîð ï 2009 Microchip Technology Inc. This directive declares the beginning of a section of shared uninitialized data. where as «¼¿¬¿ sections are used with DATABANK locations in the linker script.e. Note: Two sections in the same source file are not permitted to have the same name. except that it is only used on parts with memory accessible from multiple banks.2 Description This directive declares the beginning of a section of shared uninitialized data.«¼¿¬¿Á­¸® This program demonstrates the «¼¿¬¿Á­¸® directive.com For evaluation only.65.6 Application Example . the section is named ò«¼¿¬¿Á­¸®.65.65 «¼¿¬¿Á­¸® . The starting address is initialized to the specified address or will be assigned at link time if no address is specified.

66 ý«²¼»º·²» .com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only.foxitsoftware.DELETE A SUBSTITUTION LABEL 4.1 Syntax ý«²¼»º·²» ´¿¾»´ DS33014K-page 116 2009 Microchip Technology Inc. .66.http://www. ¾¿²µïÁª¿® «¼¿¬¿ ª¿®ï ®»­ ð¨¿ð ï åÜ»½´¿®»­ ¾»¹·²²·²¹ ±º ¿ ¼¿¬¿ å­»½¬·±² ²¿³»¼ ù¾¿²µïÁª¿®ùô 婸·½¸ ·­ ·² ¾¿²µïò ª¿®ï ·­ å¿´´±½¿¬»¼ ¬¸» ¿¼¼®»­­ ð¨¿ð ¾¿²µîÁª¿® «¼¿¬¿ ª¿®î ®»­ ð¨ïîð åÜ»½´¿®»­ ¾»¹·²²·²¹ ±º ¿ ¼¿¬¿ ï å­»½¬·±² ²¿³»¼ ù¾¿²µîÁª¿®ùô 婸·½¸ ·­ ·² ¾¿²µîò ª¿®î ·­ å¿´´±½¿¬»¼ ¬¸» ¿¼¼®»­­ ð¨ïîð ð¨ï¿ð åÜ»½´¿®»­ ¾»¹·²²·²¹ ±º ¿ ¼¿¬¿ ï å­»½¬·±² ²¿³»¼ ù¾¿²µíÁª¿®ùô 婸·½¸ ·­ ·² ¾¿²µíò ª¿®í ·­ å¿´´±½¿¬»¼ ¬¸» ¿¼¼®»­­ ð¨ï¿ð ð¨ð å̸» ½±¼» ­»½¬·±² ²¿³»¼ ÎÍÌ å·­ °´¿½»¼ ¿¬ °®±¹®¿³ ³»³±®§ å´±½¿¬·±² ð¨ðò ̸» ²»¨¬ ¬©± å·²­¬®«½¬·±²­ ¿®» °´¿½»¼ ·² å½±¼» ­»½¬·±² ÎÍÌò åÖ«³°­ ¬± ¬¸» ´±½¿¬·±² ´¿¾»´´»¼ 厭¬¿®¬Žò å̸·­ ·­ ¬¸» ¾»¹·²²·²¹ ±º ¬¸» å½±¼» ­»½¬·±² ²¿³»¼ ÐÙÓò ׬ ·­ å¿ ®»´±½¿¬¿¾´» ½±¼» ­»½¬·±² å­·²½» ²± ¿¾­±´«¬» ¿¼¼®»­­ ·­ å¹·ª»² ¿´±²¹ ©·¬¸ ¼·®»½¬·ª» ÝÑÜÛò åÍ»´»½¬ ¾¿²µðò 媿® ·­ ¿½½»­­·¾´» º®±³ ¾¿²µðò åÍ»´»½¬ ¾¿²µïò 媿® ·­ ¿½½»­­·¾´» º®±³ ¾¿²µï å¿´­±ò åÍ»´»½¬ ¾¿²µîò 媿® ·­ ¿½½»­­·¾´» º®±³ ¾¿²µî å¿´­±ò åÍ»´»½¬ ¾¿²µíò 媿® ·­ ¿½½»­­·¾´» º®±³ ¾¿²µí å¿´­±ò åÙ± ¬± ½«®®»²¬ ´·²» ø´±±° ¸»®»÷ ¾¿²µíÁª¿® ª¿®í «¼¿¬¿ ®»­ ÎÍÌ ÝÑÜÛ °¿¹»­»´ ¹±¬± ÐÙÓ ­¬¿®¬ ­¬¿®¬ ÝÑÜÛ ­¬¿®¬ ¾¿²µ­»´ ª¿®ð ³±ª´© ð¨ðð ³±ª©º ª¿® ¾¿²µ­»´ ª¿®ï ³±ª´© ð¨ðï ³±ª©º ª¿® ¾¿²µ­»´ ª¿®î ³±ª´© ð¨ðî ³±ª©º ª¿® ¾¿²µ­»´ ª¿®í ³±ª´© ð¨ðí ³±ª©º ª¿® ¹±¬± »²¼ ü 4.

This directive is most often used with the ·º¼»º and ·º²¼»º directives.com For evaluation only. The difference is that the variable directive does not require that symbols be initialized when they are declared. The ª¿®·¿¾´» values cannot be updated within an operand. which look for the presence of an item in the symbol table.6 Application Example .6 “Assembler Operation”. The symbol named is removed from the symbol table.66.66.ý¼»º·²»/ý«²¼»º·²» See this example under ý¼»º·²».6 “Assembler Operation”. and decrements on separate lines. 4. 4. You must place variable assignments.3 Usage This directive is used in the following types of code: absolute or relocatable.66. see Section 1. Directives 4. Note: ª¿®·¿¾´» is not used to declare a run-time variable. 4. refer to the directives ®»­.foxitsoftware. For information on types of code.66. 4.67.67.2 Description Creates symbols for use in MPASM assembler expressions.5 Simple Example ý¼»º·²» ´»²¹¬¸ îð æ ý«²¼»º·²» ´»²¹¬¸ 4. see Section 1. increments.4 See Also ½±²­¬¿²¬ ­»¬ 4.67 ª¿®·¿¾´» . »¯« or ½¾´±½µ. DS33014K-page 117 .67.DECLARE SYMBOL VARIABLE 4.67.67.4 See Also ý¼»º·²» ý·²½´«¼» ·º¼»º ·º²¼»º 4.5 Simple Example å Í»¬ Ü»º¿«´¬ å λ½Ô»²¹¬¸ å ײ·¬ Þ«ºÔ»²¹¬¸ ª¿®·¿¾´» λ½Ô»²¹¬¸ãêì ½±²­¬¿²¬ Þ«ºÔ»²¹¬¸ãëïî 2009 Microchip Technology Inc.3 Usage This directive is used in the following types of code: absolute or relocatable. Variables and constants may be used interchangeably in expressions.2 Description ´¿¾»´ is an identifier previously defined with the ý¼»º·²» directive. To create a run-time variable. The variable directive creates a symbol that is functionally equivalent to those created by the ­»¬ directive. 4. For information on types of code. This directive is most used for conditional assembly code.1 Syntax ª¿®·¿¾´» ´¿¾»´Å㻨°®ÃÅô´¿¾»´Å㻨°®Ãòòòà 4. but a variable that is used by the assembler.66.Generated by Foxit PDF Creator © Foxit Software http://www.

The symbols created with this directive do not occupy any physical memory location of microcontroller. ý·²½´«¼» °ïêºèéé¿ò·²½ åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò å̸» ­§³¾±´ ù°»®·³»¬»®ù ·­ å·²·¬·¿´·¦»¼ ¬± ð å׺ ¿ ­§³¾±´ ·­ ¼»½´¿®»¼ ¿­ 媿®·¿¾´»ô ¬¸»² ·²·¬·¿´·¦¿¬·±² å·­ ±°¬·±²¿´ô ·ò»ò ·¬ ³¿§ ±® ³¿§ å²±¬ ¾» ·²·¬·¿´·¦»¼ò ª¿®·¿¾´» °»®·³»¬»®ã𠪿®·¿¾´» ¿®»¿ ½±²­¬¿²¬ ´²¹¬¸ãëðØ å̸» ­§³¾±´ ù´²¹¬¸ù ·­ å·²·¬·¿´·¦»¼ ¬± ëðØò ½±²­¬¿²¬ ©¼¬¸ãîëØ å̸» ­§³¾±´ ù©¼¬¸ù ·­ å·²·¬·¿´·¦»¼ ¬± îëØò åß ½±²­¬¿²¬ ­§³¾±´ ¿´©¿§­ ²»»¼­ 嬱 ¾» ·²·¬·¿´·¦»¼ò °»®·³»¬»®ãîöø´²¹¬¸õ©¼¬¸÷å̸» ª¿´«» ±º ¿ ÝÑÒÍÌßÒÌ ½¿²²±¬ å¾» ®»¿­­·¹²»¼ ¿º¬»® ¸¿ª·²¹ ¾»»² å·²·¬·¿´·¦»¼ ±²½»ò ͱ ù´²¹¬¸ù ¿²¼ åù©¼¬¸ù ½¿²²±¬ ¾» ®»¿­­·¹²»¼ò Þ«¬ åù°»®·³»¬»®ù ¸¿­ ¾»»² ¼»½´¿®»¼ å¿­ ª¿®·¿¾´»ô ¿²¼ ­± ½¿² ¾» å®»¿­­·¹²»¼ò ¿®»¿ã´²¹¬¸ö©¼¬¸ »²¼ 4.68 ©¸·´» .68.foxitsoftware.67. å λ½Ô»²¹¬¸ ³¿§ å ¾» ®»­»¬ ´¿¬»® å ·² λ½Ô»²¹¬¸ãïîè å åÝ¿´½Ó¿¨Ó»³ 4. An expression that evaluates to any other value is considered logically TRUE.com Assembler/Linker/Librarian User’s Guide ò ò ò ò ½±²­¬¿²¬ Ó¿¨Ó»³ãλ½Ô»²¹¬¸õÞ«ºÔ»²¹¬¸ Generated by Foxit PDF Creator © Foxit Software For evaluation only. .http://www. DS33014K-page 118 2009 Microchip Technology Inc. FALSE a value of zero. A relational TRUE expression is guaranteed to return a non-zero value.PERFORM LOOP WHILE CONDITION IS TRUE 4.2 Description The lines between the while and the endw are assembled as long as »¨°® evaluates to TRUE.68.6 Application Example .ª¿®·¿¾´»/½±²­¬¿²¬ This example shows the usage of the ª¿®·¿¾´» directive.1 Syntax Preferred: ©¸·´» »¨°® æ »²¼© Supported: ò©¸·´» »¨°® æ ò»²¼© 4. An expression that evaluates to zero is considered logically FALSE. used for creating symbols which may be used in MPASM assembler expressions only.

DS33014K-page 119 .68. but produces assembly code based on a condition.6 “Assembler Operation”. see Section 1.68.Generated by Foxit PDF Creator © Foxit Software http://www.68.com For evaluation only. Use this directive for conditional assembly. not how it behaves at run-time. This directive is not an instruction.foxitsoftware. 4. 4. but used to control how code is assembled.6 Application Example .4 »²¼© ·º See Also 4.©¸·´»/»²¼© This example shows the usefulness of directive ©¸·´» to perform a loop while a certain condition is true.5 Simple Example ©¸·´» is not executed at run-time. Directives A ©¸·´» loop can contain at most 100 lines and be repeated a maximum of 256 times.3 Usage This directive is used in the following types of code: absolute or relocatable. For information on types of code. ý·²½´«¼» °ïêºèéé¿ò·²½ åײ½´«¼» ­¬¿²¼¿®¼ ¸»¿¼»® º·´» 庱® ¬¸» ­»´»½¬»¼ ¼»ª·½»ò åÜ»º·²» ¬¸» ­§³¾±´ ù·ù ¿­ ¿ 媿®·¿¾´»ò åß´´±½¿¬» ÎßÓ º±® ´¿¾»´­ å®»¹Á¸· ¿²¼ ®»¹Á´±ò ª¿®·¿¾´» · ³§¼¿¬¿ «¼¿¬¿ ð¨îð ®»¹Á¸· ®»­ ï ®»¹Á´± ®»­ ï ÎÍÌ ÝÑÜÛ ð¨ð °¿¹»­»´ ¹±¬± ­¸·º¬Á®·¹¸¬ ­¬¿®¬ ­¬¿®¬ ³¿½®± ¾§Á² å̸» ½±¼» ­»½¬·±² ²¿³»¼ ÎÍÌ å·­ °´¿½»¼ ¿¬ °®±¹®¿³ ³»³±®§ å´±½¿¬·±² ð¨ðò ̸» ²»¨¬ ¬©± å·²­¬®«½¬·±²­ ¿®» °´¿½»¼ ·² å½±¼» ­»½¬·±² ÎÍÌò åÖ«³°­ ¬± ¬¸» ´±½¿¬·±² ´¿¾»´´»¼ 厭¬¿®¬Žò åÞ»¹·²²·²¹ ±º ¿ ³¿½®±ô ©¸·½¸ å­¸·º¬­ ®»¹·­¬»® ¼¿¬¿ ² ¬·³»­ò åݱ¼» ´»²¹¬¸ ¹»²»®¿¬»¼ ¿º¬»® å¿­­»³¾´§ô ª¿®·»­ ¼»°»²¼·²¹ «°±² 嬸» ª¿´«» ±º °¿®¿³»¬»® ù¾§Á²ùò 2009 Microchip Technology Inc. ©¸·´» loops can be nested up to 8 deep.68. This directive is used with the »²¼© directive. View the list file (öò´­¬) or disassembly window to see the results of this example. ¬»­¬Á³¿½ ³¿½®± ½±«²¬ ª¿®·¿¾´» · · ã 𠩸·´» · ä ½±«²¬ ³±ª´© · · õã ï »²¼© »²¼³ ­¬¿®¬ ¬»­¬Á³¿½ ë »²¼ 4.

foxitsoftware.com Assembler/Linker/Librarian User’s Guide ·ã𠩸·´» Generated by Foxit PDF Creator © Foxit Software For evaluation only. ·ä ¾§Á² åײ·¬·¿´·¦» ª¿®·¿¾´» ·ò åÚ±´´±©·²¹ í ´·²»­ ±º ¿­­»³¾´§ å½±¼» ¿®» ®»°»¿¬»¼ ¿­ ´±²¹ ¿­ å·ä ¾§Á²ò Up to 100 lines of codes are allowed inside a ©¸·´» loop. . »²¼© »²¼³ ÐÙÓ ÝÑÜÛ åÛ²¼ ©¸·´» ´±±°ò ̸» ´±±° ©·´´ å¾®»¿µ ¸»®» ¿º¬»® ·ã¾§Á²ò åÛ²¼ ±º ù­¸·º¬Á®·¹¸¬ù ³¿½®±ò å̸·­ ·­ ¬¸» ¾»¹·²²·²¹ ±º ¬¸» å½±¼» ­»½¬·±² ²¿³»¼ ÐÙÓò ׬ ·­ å¿ ®»´±½¿¬¿¾´» ½±¼» ­»½¬·±² å­·²½» ²± ¿¾­±´«¬» ¿¼¼®»­­ ·­ å¹·ª»² ¿´±²¹ ©·¬¸ ¼·®»½¬·ª» ÝÑÜÛò ­¬¿®¬ ³±ª´© ³±ª©º ³±ª´© ³±ª©º ð¨èè ®»¹Á¸· ð¨ìì ®»¹Á´± í åײ·¬·¿´·¦» ®»¹Á¸· ¿²¼ å®»¹Á´± º±® ±¾­»®ª¿¬·±²ò ­¸·º¬Á®·¹¸¬ ¹±¬± »²¼ ü å͸·º¬ ®·¹¸¬ í ¬·³»­ ¬¸» ïêó¾·¬ 弿¬¿ ·² ®»¹Á¸· ¿²¼ ®»¹Á´±ò ̸·­ å·­ ¿² »¨¿³°´»ò ß ª¿´«» è ©·´´ å­¸·º¬ ¼¿¬¿ è ¬·³»­ò åÙ± ¬± ½«®®»²¬ ´·²» ø´±±° ¸»®»÷ DS33014K-page 120 2009 Microchip Technology Inc. ¾½º ®®º ®®º ·õãï ÍÌßÌËÍôÝ ®»¹Á¸·ôÚ ®»¹Á´±ôÚ åÝ´»¿® ½¿®®§ ¾·¬ò å®»¹Á¸· ¿²¼ ®»¹Á´± ½±²¬¿·²­ åïêó¾·¬ ¼¿¬¿ ©¸·½¸ ·­ ®±¬¿¬»¼ å®·¹¸¬ ¬¸®±«¹¸ ½¿®®§ò åײ½®»³»²¬ ´±±° ½±«²¬»® ·ò i cannot increment to more than 255 decimal.http://www.

These may exist to provide backward compatibility with previous assemblers from Microchip and to be compatible with individual programming practices. DS33014K-page 121 . For a reference listing of all directives discussed in examples here. MPASM assembler directives are not supported in MPLINK linker scripts. it is recommended that programs be written using the specifications contained within this document. output. Assembler Examples. ASSEMBLER/LINKER/LIBRARIAN USER’S GUIDE Chapter 5. Many of the assembler directives have alternate names and formats.foxitsoftware. If portable code is desired.1 INTRODUCTION The usage of multiple MPASM assembler directives is shown through examples. please see Chapter 4. Directives are assembler commands that appear in the source code but are not opcodes. Topics covered are: • • • • • • • • Example of Displaying Count on Ports Example of Port B Toggle and Delay Routines Example of Calculations with Variables and Constants Example of a 32-Bit Delay Routine Example of SPI Emulated in Firmware Example of Hexadecimal to ASCII Conversion Other Sources of Examples Tips and Tricks 2009 Microchip Technology Inc.Generated by Foxit PDF Creator © Foxit Software http://www. See MPLINK object linker documentation for more information on linker options to control listing and hex file output. “Directives”. and data allocation. Tips and Tricks 5.com For evaluation only. Note: Although MPASM assembler is often used with MPLINK object linker. They are used to control the assembler: its input.

i. you use only the assembler to generate the executable (not the assembler and linker). Data direction registers (TRISx) are cleared to set port pins to outputs.2 EXAMPLE OF DISPLAYING COUNT ON PORTS Directives highlighted in this example are: • ý·²½´«¼» • »²¼ 5. the program is finished with an »²¼. 5. several pins are analog.foxitsoftware. or in hardware on connected LEDs or a scope. A loop named Loop is entered where the value of each port is increased indefinitely until the program is halted. The standard header file for the processor selected is included using ý·²½´«¼».2. The port output data latches are then cleared. The application is written as absolute code.2 Commented Code Listing å̱¹¹´»­ ᮬ °·²­ ©·¬¸ ½±«²¬ ±² Ð×ÝïèÚèéîð åб®¬ß °·²­ ±² ÐÑÎæ å Îßëô Îßíæð ã ¿²¿´±¹ ·²°«¬­ å Îßêô Îßì ã ¼·¹·¬¿´ ·²°«¬­ åб®¬Þ °·²­ ±² ÐÑÎæ å ÎÞéæð ã ¼·¹·¬¿´ ·²°«¬­ ý·²½´«¼» °ïèºèéîðò·²½ åײ½´«¼» º·´» ²»»¼»¼ ¬± ®»º»®»²½» 弿¬¿ ­¸»»¬ ²¿³»­ò åÝ´»¿® ±«¬°«¬ ¼¿¬¿ ´¿¬½¸»­ ±² ᮬ­ ½´®º ½´®º ÐÑÎÌß ÐÑÎÌÞ ³±ª´© ð¨ðÚ ³±ª©º ßÜÝÑÒï ½´®º ½´®º Ô±±° ·²½º ·²½º ¹±¬± »²¼ ÌÎ×Íß ÌÎ×ÍÞ åݱ²º·¹«®» ᮬ ß º±® ¼·¹·¬¿´ ×ñÑ åÍ»¬ ¼¿¬¿ ¼·®»½¬·±² ±º ᮬ­ ¿­ ±«¬°«¬­ ÐÑÎÌßôÚ ÐÑÎÌÞôÚ Ô±±° åλ¿¼ ÐÑÎÌßô ¿¼¼ ï ¿²¼ ­¿ª» ¾¿½µò åλ¿¼ ÐÑÎÌÞô ¿¼¼ ï ¿²¼ ­¿ª» ¾¿½µò åܱ ¬¸·­ ®»°»¿¬»¼´§ ó ½±«²¬ò åß´´ °®±¹®¿³­ ³«­¬ ¸¿ª» ¿² »²¼ ¼·®»½¬·ª»ò DS33014K-page 122 2009 Microchip Technology Inc. on power-up.e. The count may be slowed down using a delay routine (see other examples.. 5. Port A must be set up for digital I/O as. Finally. .1 Program Functional Description This simple program continually increases the count on PORTA and PORTB. This count may be displayed in software in the SFR or watch window of MPLAB IDE.2.http://www. it will roll over to 0x00 and begin again.) Once the count has increased to 0xFF.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only.

Registers are assigned using the «¼¿¬¿.e. These can be found in the installation directory. you must use both the assembler and linker to generate the executable. as well as radix. 5. 0=off). the program is finished with an »²¼. DS33014K-page 123 .foxitsoftware.1 Program Functional Description This program continually alternates the output on the Port B pins from 1’s to 0’s. The application is written as relocatable code. If LEDs were attached to Port B. or list command.3. °¿¹»­»´ Program Functional Description Commented Code Listing Header Files Register and Bit Assignments Program Memory CODE Sections and Paging Banking Interrupts Items covered in this example are: 5.e. See PIC1X MCU Language Tools and MPLAB IDE for information on how to set up a project using assembler files and a linker script. ®»­ and »¯« directives. Sections of code are created using the ½±¼» statement.http://www.3.com For evaluation only. Finally. Two delay routines using interrupts provide the timing for the alternating output..3 EXAMPLE OF PORT B TOGGLE AND DELAY ROUTINES Directives highlighted in this example are: • • • • • • • • • • • «¼¿¬¿. However. The type of PIC1X MCU is set in MPLAB IDE and so does not need to be set in code. you may do so using the °®±½»­­±® and ®¿¼·¨ directives.3.. See Section 5. Data memory banking and program memory paging is accomplished as needed using ¾¿²µ­»´ and °¿¹»­»´ directives. ®»­ »¯« ½±¼» ¾¿²µ­»´. 2009 Microchip Technology Inc. Tips and Tricks Generated by Foxit PDF Creator © Foxit Software 5. in code. i. ´·­¬ °ãïêºèéé¿ô ®ã¸»¨.3 “Header Files” for more on headers. if you wish to specify the MCU. they would flash (1=on.2 Commented Code Listing åöööööööööööööööööööööööööööööööööööööö åö ÓÐßÍÓ ß­­»³¾´»® ݱ²¬®±´ Ü·®»½¬·ª»­ ö åö Û¨¿³°´» Ю±¹®¿³ ï ö åö ß´¬»®²¿¬» ±«¬°«¬ ±² ᮬ Þ ¾»¬©»»² ö åö ïù­ ¿²¼ ðù­ ö åöööööööööööööööööööööööööööööööööööööö ý·²½´«¼» °ïêºèéé¿ò·²½ åײ½´«¼» ¸»¿¼»® º·´» MPLAB IDE has many header files (öò·²½) available for supported devices. The standard header file for the processor selected is included using ý·²½´«¼». Assembler Examples. i.

the program memory location will be determined by the linker. See Section 5.5 “Program Memory CODE Sections and Paging” for more on ½±¼». the program will branch to ͬ¿®¬. ·­® ½±¼» Í»®ª×²¬ ð¨ðè åײ¬»®®«°¬ Í»®ª·½» ᫬·²» ¾¿²µ­»´ ÑÐÌ×ÑÒÁÎÛÙ ¾­º ÑÐÌ×ÑÒÁÎÛÙô ÌðÝÍ ¾¿²µ­»´ ×ÒÌÝÑÒ ¾½º ×ÒÌÝÑÒô Ìð×Ú ¾½º ÜÚÔßÙô ÜÚÔð ®»¬º·» åÍ»´»½¬ Ñ°¬·±² λ¹ Þ¿²µ øï÷ åͬ±° Ì·³»®ð åÍ»´»½¬ ×ÒÌÝÑÒ Þ¿²µ øð÷ åÝ´»¿® ±ª»®º´±© º´¿¹ åÝ´»¿® º´¿¹ ¾·¬ å묫®² º®±³ ·²¬»®®«°¬ For the PIC16F877A. ·²¬®°¬ ¹±¬± ½±¼» ð¨ðì Í»®ª×²¬ åײ¬»®®«°¬ Ê»½¬±® åÖ«³° ¬± ­»®ª·½» ·²¬»®®«°¬ Place interrupt vector code at program memory location 0x04. Set DFLAG to be the flag register at a location following the DTEMP register. the program will branch to the Í»®ª×²¬ routine. there is not enough memory to add a °¿¹»­»´ Í»®ª×²¬ statement to insure proper paging.3. DS33014K-page 124 2009 Microchip Technology Inc.7 “Interrupts” for more on the ISR code. Set DFL0 to a value to represent a bit in the DFLAG register. When an interrupt occurs. the ISR code needs to be specifically placed on page 0.http://www.foxitsoftware. Because no address is specified. . since this device automatically goes to this address for interrupts.com Assembler/Linker/Librarian User’s Guide «¼¿¬¿ ÜÌÛÓÐ ®»­ ï ÜÚÔßÙ ®»­ ï ÜÚÔ𠻯« ð¨ðð Generated by Foxit PDF Creator © Foxit Software For evaluation only. See the Additional Comments section for more information. ®­¬ ½±¼» °¿¹»­»´ ͬ¿®¬ ¹±¬± ͬ¿®¬ ð¨ðð åλ­»¬ Ê»½¬±® åÛ²­«®» ½±®®»½¬ °¿¹» ­»´»½¬»¼ åÖ«³° ¬± ͬ¿®¬ ½±¼» Place the reset vector at program memory location 0x00. in this case 0. Therefore. See Section 5. åÜ»½´¿®» ­¬±®¿¹» ±º ÎßÓ ª¿®·¿¾´»­ åλ­»®ª» ï ¿¼¼®»­­ ´±½¿¬·±² åλ­»®ª» ï ¿¼¼®»­­ ´±½¿¬·±² åÍ»¬ º´¿¹ ¾·¬ ó ð ¾·¬ ±º ÜÚÔßÙ Set DTEMP to be a temporary register at a location in RAM determined at by the linker.3. åöööööööööööööööööööööööööööööööööööööööööö åö Ó¿·² Ю±¹®¿³ ö åöööööööööööööööööööööööööööööööööööööööööö ½±¼» åͬ¿®¬ Ю±¹®¿³ Begin program code. When the program resets.

DS33014K-page 125 . 2009 Microchip Technology Inc. give the timer an initial value. Repeat until program halted. Assembler Examples.foxitsoftware. Then. enable the timer and wait for it to overflow from 0xFF to 0x00. This will generate an interrupt.7 “Interrupts” for more information. Then. Then set up Timer 0 and interrupts for later use. First. Ô±±° ³±ª´© ³±ª©º ½¿´´ ð¨ÚÚ ÐÑÎÌÞ Ü»´¿§ï åÍ»¬ б®¬Þ åÉ¿·¬ åÝ´»¿® б®¬Þ åÍ»´»½¬ Ü»´¿§î п¹» åÉ¿·¬ åÍ»´»½¬ Ô±±° п¹» åλ°»¿¬ ½´®º ÐÑÎÌÞ °¿¹»­»´ Ü»´¿§î ½¿´´ Ü»´¿§î °¿¹»­»´ Ô±±° ¹±¬± Ô±±° Set all Port B pins high and wait Delay 1. åöööööööööööööööööööööööööööööööööööööööööö åö Ü»´¿§ ï ᫬·²» ó Ì·³»®ð ¼»´¿§ ´±±° ö åöööööööööööööööööööööööööööööööööööööööööö Ü»´¿§ï ³±ª´© ³±ª©º ð¨Úð ÌÓÎð åÍ»¬ Ì·³»®ð ª¿´«» åð¨ððó´±²¹»­¬ ¼»´¿§ åð¨ÚÚ󭸱®¬»­¬ ¼»´¿§ ½´®º ¾­º ÜÚÔßÙ ÜÚÔßÙô ÜÚÔð åÍ»¬ º´¿¹ ¾·¬ åÍ»´»½¬ Ñ°¬·±² λ¹ Þ¿²µ øï÷ åͬ¿®¬ Ì·³»®ð åÍ»´»½¬ ÜÚÔßÙ Þ¿²µ øð÷ åÉ¿·¬ º±® ±ª»®º´±©æ ð¨ÚÚóâð¨ðð åߺ¬»® ·²¬»®®«°¬ô ÜÚÔð ã 𠾿²µ­»´ ÑÐÌ×ÑÒÁÎÛÙ ¾½º ÑÐÌ×ÑÒÁÎÛÙô ÌðÝÍ ¾¿²µ­»´ ÜÚÔßÙ ÌÔ±±° ¾¬º­½ ¹±¬± ®»¬«®² ÜÚÔßÙô ÜÚÔð ÌÔ±±° Use Timer 0 to create Delay 1.com For evaluation only. This will have the effect of “flashing” the pins of Port B. which will end the delay.http://www.3. set all Port B pins low and wait Delay 2. set up Port B pins to be all outputs using the data direction (TRISB) register. See Section 5. Tips and Tricks ͬ¿®¬ ½´®º Generated by Foxit PDF Creator © Foxit Software ÐÑÎÌÞ åÝ´»¿® б®¬Þ åÍ»´»½¬ ÌÎ×ÍÞ Þ¿²µ øï÷ åÍ»¬ ¿´´ б®¬Þ °·²­ ¿­ ±«¬°«¬­ åÍ»´»½¬ ×ÒÌÝÑÒ Þ¿²µ øð÷ åÛ²¿¾´» Ù´±¾¿´ ײ¬ù­ åÛ²¿¾´» Ì·³»®ð ײ¬ ¾¿²µ­»´ ÌÎ×ÍÞ ½´®º ÌÎ×ÍÞ ¾¿²µ­»´ ×ÒÌÝÑÒ ¾­º ×ÒÌÝÑÒô Ù×Û ¾­º ×ÒÌÝÑÒô Ìð×Û First.

5 “Program Memory CODE Sections and Paging” for more on ½±¼». (See Section 5. 5. This information can be typed in once.foxitsoftware.http://www.3. »²¼ End of the program. tells the assembler no further code needs to be assembled. ý·²½´«¼» °ïêºèéé¿ò·²½ Angle brackets.com Assembler/Linker/Librarian User’s Guide åöööööööööööööööööööööööööööööööööööööööööö åö Ü»´¿§ î ᫬·²» ó Ü»½®»³»²¬ ¼»´¿§ ´±±° ö åöööööööööööööööööööööööööööööööööööööööööö ¼»½¼´§ ½±¼» ð¨ïððð åп¹» î Generated by Foxit PDF Creator © Foxit Software For evaluation only..42 “ý·²½´«¼» . i. such as register and pin names.e. Place Delay2 routine at program memory location 0x1000.3 Header Files åײ½´«¼» ¸»¿¼»® º·´» A header file is included in the program flow with the ý·²½´«¼» directive. DS33014K-page 126 2009 Microchip Technology Inc. on page 2.Include Additional Source File” A header file is extremely useful for specifying often-used constants. . or let the assembler search for it.) This code was placed on a page other than 0 to demonstrate how a program functions across pages. You may specify the complete path to the included file. quotes or nothing at all may used to enclose the name of the header file. and then the file can be included in any code using the processor with those registers and pins. Ü»´¿§î ³±ª´© ³±ª©º ð¨ÚÚ ÜÌÛÓÐ åÍ»¬ ÜÌÛÓÐ ª¿´«» åð¨ðð󭸱®¬»­¬ ¼»´¿§ åð¨ÚÚó´±²¹»­¬ ¼»´¿§ åË­» ¿ ­·³°´» ½±«²¬¼±©² ¬± å½®»¿¬» ¼»´¿§ò åÛ²¼ ´±±° ©¸»² ÜÌÛÓÐãð ÜÔ±±° ¼»½º­¦ ¹±¬± ®»¬«®² ÜÌÛÓÐô Ú ÜÔ±±° Use the time it takes to decrement a register ÜÌÛÓÐ from an initial value to 0x00 as Delay 2. For more on search order. see the discussion of the ý·²½´«¼» directive in Section 4. This method requires no timers or interrupts.3.

code generation will begin at address zero.Begin an Object File Code Section” • Section 4.Begin an Object File Uninitialized Data Section” • Section 4. “Relocatable Objects” for more on the differences between relocatable and absolute code. but allows the linker to place the code appropriately.5 Program Memory CODE Sections and Paging The ½±¼» directive is used to specify sections of relocatable code. and then attempts to place the relocatable code. based on size. the likely program memory usage is shown below.Set Program Origin” If no ½±¼» directive is used.51 “±®¹ .Reserve Memory” • Section 4. suppose the locations selected by the linker are the general purpose registers (GPRs) 0x20 and 0x21.3.com For evaluation only.3. For more on these directives. Assembler Examples.foxitsoftware. For illustrative purposes. see: • Section 4. ½±¼» is used to specify code at 0x00 (reset address). 0x08 (interrupt service routine) and 0x1000 (Delay 2 address). Since the linker places addressed code first. For more on these directives. see: • Section 4.57 “®»­ . For this example. the ±®¹ directive is used.9 “½±¼» . It does not explicitly set the program start address.4 Register and Bit Assignments You can specify your own registers and bits by using the «¼¿¬¿. «¼¿¬¿ ÜÌÛÓÐ ®»­ ï ÜÚÔßÙ ®»­ ï ÜÚÔ𠻯« ð¨ðð åÜ»½´¿®» ­¬±®¿¹» ±º ÎßÓ ª¿®·¿¾´»­ åλ­»®ª» ï ¿¼¼®»­­ ´±½¿¬·±² åλ­»®ª» ï ¿¼¼®»­­ ´±½¿¬·±² åÍ»¬ º´¿¹ ¾·¬ ó ð ¾·¬ ±º ÜÚÔßÙ ÜÌÛÓÐ and ÜÚÔßÙ are assigned one address location in RAM each by the linker.28 “»¯« . 2009 Microchip Technology Inc. as is done in the following lines. For absolute code.Define an Assembler Constant” 5. Tips and Tricks Generated by Foxit PDF Creator © Foxit Software 5.http://www.62 “«¼¿¬¿ . ÜÚÔð is assigned the value ð¨ðð and will be used as the name for pin 0 in the ÜÚÔßÙ register. 0x04 (interrupt address). See Chapter 6. ®»­ and »¯« directives. DS33014K-page 127 . FIGURE 5-1: Special Function Registers PIC16F877A REGISTER FILE MAP 0x00 : ßÜÝÑÒð ÜÌÛÓÐ General Purpose Registers ÜÚÔßÙ ÜÚÔð Bank 0 0x1F 0x20 0x21 : 0x7F Bank 1 Bank 2 Bank 3 The directives «¼¿¬¿ and ®»­ are used in relocatable code to define multiple registers instead of »¯«.

com Assembler/Linker/Librarian User’s Guide FIGURE 5-2: PIC16F877A PROGRAM MEMORY MAP ®­¬ æ ·²¬®°¬ æ ·­® æ ò½±¼» øͬ¿®¬÷ æ ð¨ðððð æ ð¨ðððì æ ð¨ðððè æ ð¨ððïð ð¨ðèðð æ ¼»½¼´§ øÜ»´¿§î÷ æ ð¨ïððð æ ð¨ïèðð æ ð¨ïÚÚÚ Generated by Foxit PDF Creator © Foxit Software For evaluation only.53 “°¿¹»­»´ . Port B must be configured.Generate Bank Selecting Code” DS33014K-page 128 2009 Microchip Technology Inc. causing a switch to data memory bank 1 to access the TRISB register. For more on this directive. °¿¹»­»´ directives must be used to ensure that program branches to other sections are correct. ®­¬ ½±¼» ð¨ðð °¿¹»­»´ ͬ¿®¬ ¹±¬± ͬ¿®¬ æ ½±¼» æ °¿¹»­»´ Ü»´¿§î ½¿´´ Ü»´¿§î æ °¿¹»­»´ Ô±±° ¹±¬± Ô±±° æ åλ­»¬ Ê»½¬±® åͬ¿®¬ Ю±¹®¿³ åÍ»´»½¬ Ü»´¿§î п¹» åÉ¿·¬ åÍ»´»½¬ Ô±±° п¹» åλ°»¿¬ For more on this directive. This change to bank 1.Generate Page Selecting Code (PIC10/12/16 MCUs)” 5. see Section 4.3.7 “¾¿²µ­»´ . is easily accomplished using the ¾¿²µ­»´ directive. .foxitsoftware. ¾¿²µ­»´ ÌÎ×ÍÞ ½´®º ÌÎ×ÍÞ ¾¿²µ­»´ ×ÒÌÝÑÒ ¾­º ×ÒÌÝÑÒô Ù×Û ¾­º ×ÒÌÝÑÒô Ìð×Û åÍ»´»½¬ ÌÎ×ÍÞ Þ¿²µ øï÷ åÍ»¬ б®¬Þ ¿­ ±«¬°«¬ åÍ»´»½¬ ×ÒÌÝÑÒ Þ¿²µ øð÷ åÛ²¿¾´» Ù´±¾¿´ ײ¬ù­ åÛ²¿¾´» Ì·³»®ð ײ¬ Two other routines also use ¾¿²µ­»´ to access the Option register (ÑÐÌ×ÑÒÁÎÛÙ).6 Banking In this example.http://www. Page 0 Page 1 Page 2 Page 3 Since the actual location of the main code (ò½±¼» section) is unknown. see Section 4. and subsequent return to bank 0.

so it may be run again.foxitsoftware. the program branches to the interrupt vector. is generated by the programmer to handle the specific requirements of the peripheral interrupt and the program. the program-defined flag bit is cleared. Here code is located to jump to a location where interrupt-handling code is found. Finally. the cleared flag bit ÜÚÔð now causes the delay loop ÌÔÑÑÐ to end. ·­® ½±¼» Í»®ª×²¬ ð¨ðè åײ¬»®®«°¬ Í»®ª·½» ᫬·²» ¾¿²µ­»´ ÑÐÌ×ÑÒÁÎÛÙ ¾­º ÑÐÌ×ÑÒÁÎÛÙô ÌðÝÍ ¾¿²µ­»´ ×ÒÌÝÑÒ ¾½º ×ÒÌÝÑÒô Ìð×Ú ¾½º ÜÚÔßÙô ÜÚÔð ®»¬º·» åÍ»´»½¬ Ñ°¬·±² λ¹ Þ¿²µ øï÷ åͬ±° Ì·³»®ð åÍ»´»½¬ ×ÒÌÝÑÒ Þ¿²µ øð÷ åÝ´»¿® ±ª»®º´±© º´¿¹ åÝ´»¿® º´¿¹ ¾·¬ å묫®² º®±³ ·²¬»®®«°¬ When the program code begins to execute again. ·²¬®°¬ ¹±¬± ½±¼» ð¨ðì Í»®ª×²¬ åײ¬»®®«°¬ Ê»½¬±® åÖ«³° ¬± ­»®ª·½» ·²¬»®®«°¬ The interrupt-handling code. thus ending Delay 1 routine. also known as the interrupt service routine or ISR. Then. Tips and Tricks Generated by Foxit PDF Creator © Foxit Software 5. DS33014K-page 129 . In this case.3. Timer 0 is stopped and its flag bit is cleared. ®»¬º·» takes the program back to the instruction that was about to be executed when the interrupt occurred.7 Interrupts The Delay 1 routine in this program uses the Timer 0 overflow interrupt as a timing mechanism.http://www.com For evaluation only. Once the interrupt occurs. 2009 Microchip Technology Inc. Assembler Examples.

For more on these directives. ®­¬ ½±¼» ð¨ðð °¿¹»­»´ ͬ¿®¬ ¹±¬± ͬ¿®¬ ½±¼» ͬ¿®¬ ½´®º ¼·­¬¿²½»Á®»¹ ³±ª´© ̼·­¬¿²½»ï åλ­»¬ Ê»½¬±® åͬ¿®¬ Ю±¹®¿³ åÝ´»¿® ®»¹·­¬»® åÓ±ª» ª¿´«» ±º ̼·­¬¿²½»ï DS33014K-page 130 2009 Microchip Technology Inc.4. ý«²¼»º·²» • ­»¬ • ½±²­¬¿²¬. see example 1.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. Sections of code are created using the ½±¼» statement.e. i. 5. .. Then ý«²¼»º·²» was used to remove ̼·­¬¿²½»î from the symbol table.http://www. The standard header file for the processor selected is included using ý·²½´«¼». i. «¼¿¬¿ ð¨îð ¼·­¬¿²½»Á®»¹ ®»­ ï åÍ»¬ «° ¼·­¬¿²½»Á®»¹ 忬 ÙÐÎ ð¨îð The «¼¿¬¿ and ®»­ directives are used to assign ¼·­¬¿²½»Á®»¹ to register 0x20.2 Commented Code Listing åöööööööööööööööööööööööööööööööööööööö åö ÓÐßÍÓ ß­­»³¾´»® ݱ²¬®±´ Ü·®»½¬·ª»­ ö åö Û¨¿³°´» Ю±¹®¿³ î ö åö л®º±®³ ½¿´½«´¿¬·±²­ ö åöööööööööööööööööööööööööööööööööööööö ý·²½´«¼» °ïêºèéé¿ò·²½ ý¼»º·²» ý¼»º·²» ý«²¼»º·²» ̼·­¬¿²½»ï ̼·­¬¿²½»î ̼·­¬¿²½»î ëð îë åײ½´«¼» ¸»¿¼»® º·´» åÜ»º·²» ¬¸» ­§³¾±´ å̼·­¬¿²½»ï åÜ»º·²» ¬¸» ­§³¾±´ å̼·­¬¿²½»î åλ³±ª» ̼·­¬¿²½»î º®±³ 嬸» ­§³¾±´ ¬¿¾´» The ý¼»º·²» directive was used to define two substitution strings: ̼·­¬¿²½»ï to substitute for 50 and ̼·­¬¿²½»î to substitute for 25.4 EXAMPLE OF CALCULATIONS WITH VARIABLES AND CONSTANTS Directives highlighted in this example are: • ý¼»º·²».4. ª¿®·¿¾´» Items covered in this example are: • Program Functional Description • Commented Code Listing • Using Watch Windows 5.1 Program Functional Description This program performs several calculations using defined constants and variables. you must use both the assembler and linker to generate the executable. 5.. ̼·­¬¿²½»î can no longer be used to substitute for 25. The application is written as relocatable code.e.foxitsoftware.

¼·­¬¿²½»í ­»¬ ïë ¼·­¬¿²½»îã¼·­¬¿²½»îõ¼·­¬¿²½»í åݸ¿²¹» ª¿´«» ±º ¼·­¬¿²½»í åß¼¼ ¼·­¬¿²½»í 嬱 ¼·­¬¿²½»î åÓ±ª» ª¿´«» ±º ¼·­¬¿²½»î å·²¬± ¼·­¬¿²½»Á®»¹ åÔ±±° ¾¿½µ ¬± ͬ¿®¬ ³±ª´© ³±ª©º ¼·­¬¿²½»î ¼·­¬¿²½»Á®»¹ ¹±¬± ͬ¿®¬ »²¼ 5.3 Using Watch Windows Once the program begins. you will see it change to 3A. ¼·­¬¿²½»í ­»¬ ïð åÜ»º·²» ¿ ª¿´«» º±® 嬸» ­§³¾±´ ¼·­¬¿²½»í Define symbol ¼·­¬¿²½»í as 10. If you had a watch window open to see ¼·­¬¿²½»Á®»¹ loaded with the value of 50. the value of ̼·­¬¿²½»ï is placed into ¼·­¬¿²½»Á®»¹.com For evaluation only. 2009 Microchip Technology Inc. This can be observed in a watch window in MPLAB IDE. ¼·­¬¿²½»ï. Assembler Examples. where the value of ¼·­¬¿²½»Á®»¹ will become 50. The final lines of the example program write the final value of ¼·­¬¿²½»î to ¼·­¬¿²½»Á®»¹. ª¿®·¿¾´» ¼·­¬¿²½»î åÜ»½´¿®» ¼·­¬¿²½»î å¿ ª¿®·¿¾´» ­§³¾±´ Declare a variable symbol.foxitsoftware. with a value of 10. increments and decrements must be placed on separate lines. ¼·­¬¿²½»îò The ª¿®·¿¾´» directive does not require the symbol to be initialized when declared.4. ¼·­¬¿²½»îãïë ¼·­¬¿²½»îã¼·­¬¿²½»ïõ¼·­¬¿²½»î åÙ·ª» ¼·­¬¿²½»î ¿² å·²·¬·¿´ ª¿´«» åß¼¼ ¼·­¬¿²½»ï 嬱 ¼·­¬¿²½»î Variable assignments. as symbols defined using the ý¼»º·²» directive are not available for viewing in MPLAB IDE because they are not RAM variables. Remember that the radix is hexadecimal. Tips and Tricks ³±ª©º ¼·­¬¿²½»Á®»¹ ¼·­¬¿²½»ïãïð å·²¬± ¼·­¬¿²½»Á®»¹ åÜ»½´¿®» ¼·­¬¿²½»ï å¿ ½±²­¬¿²¬ ­§³¾±´ Generated by Foxit PDF Creator © Foxit Software ½±²­¬¿²¬ Declare a constant symbol. DS33014K-page 131 .http://www. The symbol ̼·­¬¿²½»ï will not be found in the watch window symbol list. so hex addition was used to determine the ¼·­¬¿²½»î value. Once a constant is declared. its value cannot be altered.

with the routine having a range of 40 us to 23. For this example. .5.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. (This assumes a 4 MHz clock.) 5.2 Commented Code Listing åÛ¿½¸ ´±±° ¬¿µ»­ îð ½´±½µ­ô ±® îð «­ °»® ´±±°ô 忬 ìÓئ ±® ïÓ×ÐÍ ½´±½µò åÌ«®² ±ºº ·² ½±²º·¹ ¾·¬­ ÉÜÌ º±® ´±²¹ ­·³«´¿¬·±²­ ý·²½´«¼» °ïêÚèééßò·²½ «¼¿¬¿ ®»­ ®»­ ®»­ ®»­ ð¨îð ï åͬ±®»­ ì ¾§¬»­ ±º ¼¿¬¿ º±® ¬¸» ¼»´¿§ ½±«²¬ ï åÜ´§ð ·­ ¬¸» ´»¿­¬ ­·¹²·º·½¿²¬ ¾§¬» ï 婸·´» Ü´§í ·­ ¬¸» ³±­¬ ­·¹²·º·½¿²¬ ¾§¬» ï Ü´§ð Ü´§ï Ü´§î Ü´§í Ü´§íî ÓßÝÎÑ ÜÔÇ ¹±¬± üõï ¹±¬± üõï å¼»´¿§ î ½§½´»­ å¼»´¿§ ¬±¬¿´ ±º ì ½§½´»­ åÌ¿µ» ¬¸» ¼»´¿§ ª¿´«» ¿®¹«³»²¬ º®±³ ¬¸» ³¿½®±ô °®»½¿´½«´¿¬» 嬸» ®»¯«·®»¼ ì ÎßÓ ª¿´«»­ ¿²¼ ´±¿¼ ¬¸» ̸» ÎßÓ ª¿´«»­ Ü´§í 嬸±«¹¸ Ü´§ðò ÞßÒÕÍÛÔ Ü´§í ³±ª´© øÜÔÇóï÷ ú ØùÚÚù ³±ª©º Ü´§ð ³±ª´© øÜÔÇóï÷ ââÜùðèù ú ØùÚÚù ³±ª©º Ü´§ï ³±ª´© øÜÔÇóï÷ ââÜùïêù ú ØùÚÚù åÞ§¬»­ ¿®» ­¸·º¬»¼ ¿²¼ ¿²¼»¼ ¾§ ¬¸» ¿­­»³¾´»® ¬± ³¿µ» «­»® 彿´½«´¿¬·±²­ »¿­·»®ò ³±ª©º Ü´§î ³±ª´© øÜÔÇóï÷ ââÜùîìù ú ØùÚÚù åÝ¿´´ ܱܴ§íî ¬± ®«² ¬¸» ¼»´¿§ ´±±°ò ³±ª©º Ü´§í ½¿´´ ܱܴ§íî ÛÒÜÓ åÛ²¼ ±º Ó¿½®± ¼»º·²·¬·±² ÎÍÌ ÝÑÜÛ ð¨ðð °¿¹»­»´ Ì»­¬Ý±¼» ¹±¬± Ì»­¬Ý±¼» åλ­»¬ Ê»½¬±® ÝÑÜÛ Ì»­¬Ý±¼» Ü´§íî ²±° åݱ¼» ­¬¿®¬­ ¸»®» Üùëððððù åÓ¿¨ ì ¾·´´·±²õ ø®«²­ Ü´§íî Ó¿½®±ô åï ­»½ ·² ¬¸·­ ½¿­»÷ò åÆÛÎÑ ÍÌÑÐÉßÌÝØô °«¬ ¾®»¿µ°±·²¬ ¸»®»ò DS33014K-page 132 2009 Microchip Technology Inc.5.8 hours. 5.foxitsoftware.http://www.5 EXAMPLE OF A 32-BIT DELAY ROUTINE Directives highlighted in this example are: • ³¿½®±ô »²¼³ • ¾¿²µ­»´ 5. delay increments are 20 us.1 Program Functional Description A delay routine is needed in many applications.

foxitsoftware.http://www. DS33014K-page 133 . Assembler Examples.com For evaluation only. Tips and Tricks ¹±¬± Ì»­¬Ý±¼» åÙ± ¾¿½µ ¬± ¬±° ±º °®±¹®¿³ ¿²¼ 宫² ¬¸» ¼»´¿§ ¿¹¿·²ò Generated by Foxit PDF Creator © Foxit Software åÍ«¾®±«¬·²»ô ½¿´´»¼ ¾§ ¬¸» Ó¿½®± Ü´§íî øîð ̽§ °»® ´±±°÷ ܱܴ§íî ³±ª´© ØùÚÚù åͬ¿®¬ ©·¬¸ óï ·² É ¿¼¼©º ¾¬º­½ ½´®© ¿¼¼©º ¾¬º­½ ½´®© ¿¼¼©º ¾¬º­½ ½´®© ¿¼¼©º ¾¬º­½ ½´®© ·±®©º ·±®©º ·±®©º ·±®©º ¾¬º­­ ¹±¬± ®»¬´© ÛÒÜ Ü´§ðôÚ ÍÌßÌËÍôÝ åÔÍÞ ¼»½®»³»²¬ å©¿­ ¬¸» ½¿®®§ º´¿¹ ­»¬á å׺ ­±ô ð ·­ °«¬ ·² É åÛ´­»ô ©» ½±²¬·²«»ò åð ·² É Ü´§îôÚ ÍÌßÌËÍôÝ åð ·² É Ü´§íôÚ ÍÌßÌËÍôÝ åð ·² É Ü´§ðôÉ Ü´§ïôÉ Ü´§îôÉ Ü´§íôÉ ÍÌßÌËÍôÆ Ü±Ü´§íî ð åײ½´«­·ª»óÑÎ ¿´´ ª¿®·¿¾´»­ 嬱¹»¬¸»® ¬± ­»» ·º ©» ¸¿ª» ®»¿½¸»¼ åð ±² ¿´´ ±º ¬¸»³ò Ü´§ïôÚ ÍÌßÌËÍôÝ åÌ»­¬ ·º ®»­«´¬ ±º ײ½´«­·ª»óÑÎù­ ·­ ð å׬ ©¿­ ÒÑÌ ¦»®±ô ­± ½±²¬·²«» ½±«²¬·²¹ å׬ ÉßÍ ¦»®±ô ­± »¨·¬ ¬¸·­ ­«¾®±«¬·²»ò 2009 Microchip Technology Inc.

External code is accessed using ¹´±¾¿´. 5.2 Commented Code Listing åöööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö å Û³«´¿¬»­ ÍÐ× ·² º·®³©¿®» å д¿½» ¾§¬» ·² Þ«ºº»®ô ½¿´´ ÍÐ×ÁÑ«¬ ó ­»²¼­ ÓÍÞ º·®­¬ åöööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö Ô×ÍÌ ý·²½´«¼» ´·­¬ ÐãïèÚìëîð äÐïèÚìëîðò×ÒÝâ ½ãïíîô ²ãð å¼»º·²» °®±½»­­±® å·²½´«¼» º·´» åïíî ½±´ô ²± °¿¹·²¹ åöööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö ý¼»º·²» Ý´µ ÔßÌÞôð ý¼»º·²» Ü¿¬ ÔßÌÞôï ý¼»º·²» Þ«­ ÔßÌÞôî å ÍÐ× ½´±½µ ±«¬°«¬ å ÍÐ× ¼¿¬¿ ±«¬°«¬ å ¾«­§ ·²¼·½¿¬±® åöööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö åÊ¿®·¿¾´» ¼»º·²·¬·±²­ «¼¿¬¿ Þ«ºº»® ®»­ ï å ÍÐ× ¬®¿²­³·¬ ¼¿¬¿ ݱ«²¬»® ®»­ ï å ÍÐ× ¬®¿²­³·¬ ¾·¬ ½±«²¬»® Ü»´¿§Ý¬® ®»­ ï åöööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö ½±¼» ÍÐ×ÁÑ«¬ ½´®º ݱ«²¬»® å ·²·¬ ¾·¬ ½±«²¬»® ¾­º ݱ«²¬»®ôé ¾½º ¾½º ¾­º Ý´µ Ü¿¬ Þ«­ å ½´»¿® ½´±½µ å ½´»¿® ¼¿¬¿ ±«¬ å ·²¼·½¿¬» ¾«­§ DS33014K-page 134 2009 Microchip Technology Inc. The ´·­¬ directive is used to define the processor and set listing file formatting.. The application is written as relocatable code.foxitsoftware. SPI variables are declared using ý¼»º·²». .http://www. i. 5. ®»­ ¹´±¾¿´ 5. The standard header file for the processor selected is included using ý·²½´«¼».6.e. Program registers are assigned using the «¼¿¬¿ and ®»­ directives.6 EXAMPLE OF SPI EMULATED IN FIRMWARE Directives highlighted in this example are: • Ÿ • • ´·­¬ ý¼»º·²» «¼¿¬¿. Sections of code are created using the ½±¼» statement. you must use both the assembler and linker to generate the executable.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only.1 Program Functional Description This program is used to emulate SPI function in firmware.6.

com For evaluation only. Tips and Tricks Ô«° ³±ªº ¿²¼©º ¾¬º­­ ¾­º ¾­º ¾½º ¾½º ®®²½º ¾¬º­­ ¾®¿ ¾½º ®»¬«®² åöööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö ¹´±¾¿´ »²¼ ÍÐ×ÁÑ«¬ô Þ«ºº»® ݱ«²¬»®ôÉ Þ«ºº»®ôÉ ÍÌßÌËÍôÆ Ü¿¬ Ý´µ Ý´µ Ü¿¬ ݱ«²¬»®ôÚ Ý±«²¬»®ôé Ô«° Þ«­ å ¹»¬ ³¿­µ å ¬»­¬ ­»´»½¬»¼ ¾·¬ å ©¿­ ®»­«´¬ ¦»®±á å ­»¬ ¼¿¬¿ å ­»¬ ½´±½µ å ½´»¿® ½´±½µ å ½´»¿® ¼¿¬¿ å ¬»­¬ ²»¨¬ ¾·¬ å ¼±²» ©·¬¸ ¾§¬»á å ²± å ·²¼·½¿¬» ²±¬ ¾«­§ Generated by Foxit PDF Creator © Foxit Software 2009 Microchip Technology Inc.http://www. Assembler Examples.foxitsoftware. DS33014K-page 135 .

External code is accessed using ¹´±¾¿´. .7. i. 5.2 Commented Code Listing åöööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö å ¹»¬ ¿ ¸»¨ ¾§¬» ·² Éô ½±²ª»®¬ ¬± î ßÍÝ×× ¾§¬»­ ·² ßÍÝ××ØæßÍÝ××Ô å ®»¯ î ­¬¿½µ ´»ª»´­ å åöööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö Ê¿®·¿¾´»­ «¼¿¬¿ Ø»¨Ì»³° ®»­ ï ßÍÝ××Ø ®»­ ï ßÍÝ××Ô ®»­ ï åöööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö ½±¼» Ø»¨îßÍÝ ³±ªº Ø»¨Ì»³°ôÉ ¿²¼´© ð¨ðÚ å ¹»¬ ´±© ²·¾¾´» ½¿´´ Ü»½Ø»¨ ³±ª©º ßÍÝ××Ô ­©¿°º ³±ªº ¿²¼´© ½¿´´ ³±ª©º ®»¬«®² åöööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö Ü»½Ø»¨ ­«¾´© ð¨ðç å çóÉÎÛÙ ¾¬º­­ ÍÌßÌËÍôÝ å ·­ ²·¾¾´» Ü»½á ¹±¬± Ø»¨Ý å ²±ô ½±²ª»®¬ ¸»¨ Ü»½ ³±ªº ¿²¼´© ¿¼¼´© ®»¬«®² Ø»¨Ý ³±ªº ¿²¼´© ¿¼¼´© ®»¬«®² Ø»¨Ì»³°ôÉ ð¨ðÚ ßùßùóð¨ðß å ½±²ª»®¬ ØÛÈ ²·¾¾´» ¬± ßÍÝ×× Ø»¨Ì»³°ôÉ ð¨ðÚ ßùðù å ½±²ª»®¬ ÜÛÝ ²·¾¾´» ¬± ßÍÝ×× Ø»¨Ì»³°ôÚ Ø»¨Ì»³°ôÉ ð¨ðÚ Ü»½Ø»¨ ßÍÝ××Ø å ¹»¬ ¸·¹¸ ²·¾¾´» DS33014K-page 136 2009 Microchip Technology Inc.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. ®»­ • ¹´±¾¿´ 5.7 EXAMPLE OF HEXADECIMAL TO ASCII CONVERSION Directives highlighted in this example are: • «¼¿¬¿.http://www. Program registers are assigned using the «¼¿¬¿ and ®»­ directives. The application is written as relocatable code. 5.foxitsoftware.e.7.. Sections of code are created using the ½±¼» statement. you must use both the assembler and linker to generate the executable.1 Program Functional Description This program converts a hexadecimal byte into two ASCII bytes.

Website . • • • • • • TIP #1: Delay Techniques TIP #2: Optimizing Destinations TIP #3: Conditional Bit Set/Clear TIP #4: Swap File Register with W TIP #5: Bit Shifting Using Carry Bit TIP #6: Using External Memory 5. buttons.http://www. designers need to make the most of the available program memory in MCUs.http://www. pause for a handshake or decrease the data rate for a shared bus.foxitsoftware. Optimizing the code helps to avoid buying more memory than needed. Technical Briefs . See Chapter 4.9 TIPS AND TRICKS To reduce costs. For more information. Here are some ideas that can help reduce code size. Examples of use for multiple directives are available from the following sources: • readme.8 OTHER SOURCES OF EXAMPLES Short examples of use for each directive are listed under each directive topic. see Tips ‘n Tricks (DS40040).asm .Serial EEPROM Support • Application Notes.MPLAB IDE installation directory .microchip. åööööööööööööööööööööööööööööööööööööööööööööööööö ÒÑÐ ÒÑÐ åî ·²­¬®«½¬·±²­ô î ½§½´»­ åööööööööööööööööööööööööööööööööööööööööööööööööö ÙÑÌÑ üõï åï ·²­¬®«½¬·±²ô î ½§½´»­ åööööööööööööööööööööööööööööööööööööööööööööööööö Ý¿´´ ά®² åï ·²­¬®«½¬·±²ô ì ½§½´»­ æ ά®² ÎÛÌËÎÒ åööööööööööööööööööööööööööööööööööööööööööööööööö MCUs are commonly used to interface with the “outside world” by means of a data bus. etc.com • Code Examples and Templates .microchip. 2009 Microchip Technology Inc.com For evaluation only.1 TIP #1: Delay Techniques • Use ÙÑÌÑ Ò»¨¬ ײ­¬®«½¬·±² instead of two ÒÑÐs.com 5. latches. Assembler Examples.9.http://www. LED’s. • Use ÝßÔÔ Î¬®² as quad. Tips and Tricks Generated by Foxit PDF Creator © Foxit Software åöööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö ¹´±¾¿´ ÛÒÜ Ø»¨îßÍÝô ßÍÝ××Øô ßÍÝ××Ô 5. DS33014K-page 137 . it will often need delay routines to meet setup/hold times of other devices. “Directives”. Because the MCU runs at a fixed frequency. 1 instruction NOP (where ά®² is the exit label from existing subroutine). Program memory is typically a large portion of the MCU cost.Website .

The second bit test determines if the bit is set. In the first example. the MCU will jump to the next memory location. This created a two-cycle delay using only one location of program memory. If the bit is clear. For shorter delays of a few cycles. the MCU delays two instruction cycles to execute the CALL and two more to execute the RETURN. Longer delays are well-suited for the DECFSZ and INCFSZ instructions where a variable is decremented or incremented until it reaches zero when a conditional jump is executed. and if the bit is set. it is common to use two NOP instructions which uses two program memory locations. here a few ideas to decrease code size. the same result was achieved by adding a single CALL instruction. Instead of using four NOP instructions to create a four cycle delay. 5.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. The ü represents the current program counter value in MPASM assembler. DS33014K-page 138 2009 Microchip Technology Inc. This sequence requires four instructions. In the second example. The same result can be achieved by using ÙÑÌÑ üõï. In the first example. the BCF instruction is executed and clears the REGB bit. When this instruction is encountered. In this example.foxitsoftware. add a label to an existing RETURN instruction in the code. the bit in REGA is tested using a BTFSS instruction. When executing ÝßÔÔ Î¬®². For a two cycle delay. A MOVWF instruction is used to move the result from the working register to register A. a two-cycle delay was created. the ADDWF instruction uses the destination bit to place the result into the A register saving an instruction. register A and register B are summed and the result is put into the A register. Here. A destination option is available for logic and arithmetic operations. This is what it would have done if two NOP’s were used. but since the GOTO instruction uses two instruction cycles to execute.9. will execute the BSF and set the REGB bit.3 TIP #3: Conditional Bit Set/Clear • To move single bit of data from REGA to REGB • Precondition REGB bit • Test REGA bit and fix REGB if necessary ÞÌÚÍÍ ÞÝÚ ÞÌÚÍÝ ÞÍÚ ÎÛÙßôîÞÝÚ ÎÛÙÞôë ÎÛÙÞôëÞÌÚÍÝ ÎÛÙßôî ÎÛÙßôîÞÍÚ ÎÛÙÞôë ÎÛÙÞôë ì ·²­¬®«½¬·±²­í ·²­¬®«½¬·±²­ One technique for moving one bit from the REGA register to REGB is to perform bit tests.http://www. To create a four cycle delay. the instruction is skipped. and if so. .2 TIP #2: Optimizing Destinations • Destination bit determines É or Ú for result • Look at data movement and restructure Example: A + B ÓÑÊÚ ßÜÜÉÚ ÓÑÊÉÚ ßôÉÓÑÊÚ ÞôÉßÜÜÉÚ ß A ÞôÉ ßôÚ í ·²­¬®«½¬·±²­î ·²­¬®«½¬·±²­ Careful use of the destination bits in instructions can save program memory. 5. the result of the ADDWF instruction is placed in the working register. the label ά®² was added to the ÎÛÌËÎÒ of subroutine that already existed somewhere in the code. otherwise the instruction is skipped.9.

5 TIP #5: Bit Shifting Using Carry Bit Rotate a byte through carry without using RAM variable for loop count: • Easily adapted to serial interface transmit routines. Needs: 0 TEMP registers.http://www. DS33014K-page 139 . otherwise the REGB bit is set.com For evaluation only.4 ÍÉßÐÉÚ TIP #4: Swap File Register with W ÓßÝÎÑ ÈÑÎÉÚ ÈÑÎÉÚ ÈÑÎÉÚ ÛÒÜÓ ÎÛÙ ÎÛÙôÚ ÎÛÙôÉ ÎÛÙôÚ The following macro swaps the contents of W and REG without using a second register. ´·­¬ °ãïîºêîç ý·²½´«¼» °ïîºêîçò·²½ ¾«ºº»® »¯« ð¨îð ¾­º ÍÌßÌËÍôÝ ®´º ¾«ºº»®ôÚ Í»²¼ÁÔ±±° ¾½º ÙÐ×Ñôܱ«¬ ¾¬º­½ ÍÌßÌËÍôÝ ¾­º ÙÐ×Ñôܱ«¬ ¾½º ÍÌßÌËÍôÝ ®´º ¾«ºº»®ôÚ ³±ªº ¾«ºº»®ôÚ ¾¬º­­ ÍÌßÌËÍôÆ ¹±¬± Í»²¼ÁÔ±±° åÍ»¬ »²¼ ±º ´±±°Ž º´¿¹ åд¿½» º·®­¬ ¾·¬ ·²¬± Ý åЮ»½±²¼·¬·±² ±«¬°«¬ åݸ»½µ ¼¿¬¿ ó ð ±® ïá åÝ´»¿® ¼¿¬¿ ·² Ý åд¿½» ²»¨¬ ¾·¬ ·²¬± Ý åÚ±®½» Æ ¾·¬ åÛ¨·¬á Related Topic: TIP #3: Conditional Bit Set/Clear 2009 Microchip Technology Inc. • Carry bit is cleared (except last cycle) and the cycle repeats until the zero bit sets indicating the end.9. and clear the REGB bit. and test if the REGA bit is clear. It requires no temporary registers and three instructions. One important point is that the second example will create a two cycle glitch if REGB is a port outputting a high. Tips and Tricks A more efficient technique is to assume the bit in REGA is clear. If so.9. the assumption was correct and the BSF instruction is skipped. The sequence in the second example uses three instructions because one bit test was not needed. 3 Tcy An efficient way of swapping the contents of a register with the working register is to use three XORWF instructions. Assembler Examples.foxitsoftware. 3 Instructions. This is caused by the BCF and BTFSC instructions that will be executed regardless of the bit value in REGA. Generated by Foxit PDF Creator © Foxit Software 5. Here’s an example: É ïðïðïïðð ïðïðïïðð ðïðïïïðð ðïðïïïðð ÎÛ٠ײ­¬®«½¬·±² ðïðïïïðð ÈÑÎÉÚ ÎÛÙôÚ ïïïïðððð ÈÑÎÉÚ ÎÛÙôÉ ïïïïðððð ÈÑÎÉÚ ÎÛÙôÚ ïðïðïïðð λ­«´¬ 5.

the maximum allowable address must be redefined by using the ÁÓßÈÎÑÓ directive.foxitsoftware. 5. when using the PIC18F87J10 in extended microcontroller mode.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. For example.6 TIP #6: Using External Memory To use external memory. .9. the ÁÓßÈÎÑÓ directive must be used as follows: ý·²½´«¼» äÐï轨¨¨ò·²½â ÁÁÓßÈÎÑÓ ð¨ïÚÚÚÚÚ å èéÖïð ݱ²º·¹«®¿¬·±² º±® »¨¬»®²¿´ ³»³±®§ ÝÑÒÚ×Ù ÓÑÜÛãÈÓîðô ÛßÍØÚÌãÑÚÚô ÞÉ ã ïêô Éß×ÌãÑÚÚ ±®¹ ¹±¬± ÛÒÜ ð¨ðððð ð¨ïðððð DS33014K-page 140 2009 Microchip Technology Inc.http://www.

has the ability to generate and link precompiled object modules.42 “ý·²½´«¼» . used with MPLINK object linker. These header files define the special function registers for the target processor.g. 2009 Microchip Technology Inc. Topics covered in this chapter: • • • • • • • • • Header Files Program Memory Low. High and Upper Operators RAM Allocation Configuration Bits and ID Locations Accessing Labels From Other Modules Paging and Banking Issues Generating the Object Module Code Example 6. °ïèºèéîðò·²½) should be used when generating object modules. Relocatable Objects 6. ASSEMBLER/LINKER/LIBRARIAN USER’S GUIDE Chapter 6. Writing source code that will be assembled to an object module is slightly different from writing code used to generate an executable (hex) file directly.foxitsoftware.com For evaluation only. DS33014K-page 141 .2 HEADER FILES The Microchip-supplied standard header files (e.Generated by Foxit PDF Creator © Foxit Software http://www. EXAMPLE 6-1: INCLUDE HEADER FILE ý·²½´«¼» °ïèºèéîðò·²½ æ See 4..1 INTRODUCTION MPASM assembler. MPASM assembler routines designed for absolute address assembly will require minor modifications to compile correctly into relocatable object modules.Include Additional Source File” for more information.

6. Return upper byte of section end operand. Return low byte of section end operand. Return upper byte of operand.3 PROGRAM MEMORY Program memory code must be organized into a logical code section. The physical address of the code can be fixed by supplying the optional address parameter of the ½±¼» directive. Return upper byte of section size. Return high byte of operand. Situations where this might be necessary are: • Specifying reset and interrupt vectors • Ensuring that a code segment does not overlap page boundaries EXAMPLE 6-2: RELOCATABLE CODE λ­»¬ ½±¼» ð¨ð´ÚÚ åÚ·¨»¼ ¿¼¼®»­­ ¹±¬± ͬ¿®¬ й³ ½±¼» åß¼¼®»­­ ¼»¬»®³·²»¼ ¾§ ¬¸» ´·²µ»® ½´®© ±°¬·±² 6. If high is used.4 LOW. Return low byte of section start operand. If low is used. Return high byte of section end operand. . To do this. only bits 0 through 7 of the expression will be used. the code must be preceded by a ½±¼» section declaration (See 4. Each program memory section must be contiguous within a single source file. it will be given the default name ò½±¼».9 “½±¼» . Definition Operator precedence information may be found in 3.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. Return high byte of section start operand. each section must have a unique name. HIGH AND UPPER OPERATORS Low. Return upper byte of section start operand.Begin an Object File Code Section”) to make it relocatable. A section may not be broken into pieces within a singe source file. only bits 16 through 21 of the expression will be used. Operator ´±© ¸·¹¸ «°°»® ­½²­¦Á´±© ­½²­¦Á¸·¹¸ ­½²­¦Á«°°»® ­½²»²¼Á´±© ­½²»²¼Á¸·¹¸ ­½²»²¼Á«°°»® ­½²­¬¿®¬Á´±© ­½²­¬¿®¬Á¸·¹¸ ­½²­¬¿®¬Á«°°»® Return low byte of operand. high and upper operators are used to return one byte of a multi-byte label value. Return low byte of section size. If upper is used.http://www. only bits 8 through 15 of the expression will be used.5 “Arithmetic Operators and Precedence”. DS33014K-page 142 2009 Microchip Technology Inc. Return high byte of section size. Absolute Code ͬ¿®¬ ½´®© ±°¬·±² Equivalent Relocatable Code ½±¼» ͬ¿®¬ ½´®© ±°¬·±² Ю±¹ï ±®¹ ð¨ðïðð ³±ª´© ð¨ðß ³±ª©º ª¿®ï Ю±¹ï ½±¼» ð¨ðïðð åͬ¿®¬ ¿¬ ð¨ðïðð ³±ª´© ð¨ðß ³±ª©º ª¿®ï åß¼¼®»­­ ¼»¬»®³·²»¼ 徧 ¬¸» ´·²µ»®ò If more than one ½±¼» section is defined in a source file. If the name is not specified.foxitsoftware.

´±©. EXAMPLE 6-3: GENERAL OPERATOR USE The general operators. may be used to access data in tables. This instruction loads LFSR with the end address of the section. where ² is 0. 1. This instruction loads LFSR with the start address of the section. DS33014K-page 143 . Pseudo-Instruction ­½²»²¼Á´º­® Definition ­½²»²¼Á´º­® ²ô­. where ² is 0.com For evaluation only. ­½²­¬¿®¬Á´º­® ²ô­. the ´±©.foxitsoftware. For example. they cannot be used when generating absolute code. ¸·¹¸ and «°°»® operators must be of the form: Å´±©¤¸·¹¸¤«°°»®Ã ø®»´±½¿¬¿¾´»Á­§³¾±´ õ ½±²­¬¿²¬Á±ºº­»¬÷ where: • ®»´±½¿¬¿¾´»Á­§³¾±´ is any label that defines a program or data memory address • ½±²­¬¿²¬Á±ºº­»¬ is an expression that is resolvable at assembly time to a value between -32768 and 32767 Either ®»´±½¿¬¿¾´»Á­§³¾±´ or ½±²­¬¿²¬Á±ºº­»¬ may be omitted. The following code example was taken the °ïè¼»³±ò¿­³ file provided with PICDEM 2 Plus demo board. 1. The excerpt shows how “Microchip” is read from the table and displayed on the demo board LCD.Generated by Foxit PDF Creator © Foxit Software http://www. or 2 (as with the ÔÚÍÎ instruction) and ­ is a string which is taken to be the name of a section. In addition to section operators. Operands of the form: ®»´±½¿¬¿¾´»Á­§³¾±´ ó ®»´±½¿¬¿¾´»Á­§³¾±´ will be reduced to a constant value if both symbols are defined in the same code or data section. Relocatable Objects There are some restrictions involving these operators with relocatable symbols. ¸·¹¸ and «°°»®. ý·²½´«¼» °ïèºìëîò·²½ æ ÐÎÑÙï ÝÑÜÛ ­¬¿²Á¬¿¾´» å þÈÈÈÈÈÈÈÈÈÈÈÈÈÈÈÈþ å ¼¿¬¿ þ ʱ´¬³»¬»® þ ¼¿¬¿ þ Þ«¦¦»® þ ¼¿¬¿ þ Ì»³°»®¿¬«®» þ ¼¿¬¿ þ Ý´±½µ þ ¼¿¬¿ þÎßìãÒ»¨¬ ÎÞðãÒ±©þ ¼¿¬¿ þ Ó·½®±½¸·° þ ¼¿¬¿ þ Ð×ÝÜÛÓ î ÐÔËÍ þ ¼¿¬¿ þÎßìãÍ»¬ ÎÞðãÓ»²«þ ¼¿¬¿ þÎßìã óóâ ÎÞÑã õõþ ¼¿¬¿ þ ÎÞð ã Û¨·¬ þ ¼¿¬¿ þʱ´¬­ ã þ ¼¿¬¿ þЮ¼òãïîè ÜÝãïîè þ æ 嬿¾´» º±® ­¬¿²¼¿®¼ ½±¼» °¬®æ åð åïê åíî åìè åêì åèð åçê åïïî åïîè åïìì åïêð åïéê 2009 Microchip Technology Inc. ­½²­¬¿®¬Á´º­® These operators and instructions only have meaning when an object file is generated. or 2 (as with the ÔÚÍÎ instruction) and ­ is a string which is taken to be the name of a section. there are section pseudo-instructions.

foxitsoftware. .com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. åöööööööööööööööö ÍÌßÒÜßÎÜ ÝÑÜÛ ÓÛÒË ÍÛÔÛÝÌ×ÑÒ ööööööööööööööööööö ³±ª´© òèð å­»²¼ þÓ·½®±½¸·°þ ¬± ÔÝÜ ³±ª©º °¬®Á°±­ ½¿´´ ­¬¿²Á½¸¿®Áï æ åóóóóͬ¿²¼¿®¼ ½±¼»ô д¿½» ½¸¿®¿½¬»®­ ±² ´·²»óïóóóó ­¬¿²Á½¸¿®Áï ½¿´´ ÔÝÜÔ·²»Áï å³±ª» ½«®­±® ¬± ´·²» ï ³±ª´© òïê åï󺫴´ ´·²» ±º ÔÝÜ ³±ª©º °¬®Á½±«²¬ ³±ª´© ËÐÐÛÎ ­¬¿²Á¬¿¾´» å«­» ±°»®¿¬±®­ ¬± ´±¿¼ ³±ª©º ÌÞÔÐÌÎË å¬¿¾´» °±·²¬»® ª¿´«»­ ³±ª´© Ø×ÙØ ­¬¿²Á¬¿¾´» ³±ª©º ÌÞÔÐÌÎØ ³±ª´© ÔÑÉ ­¬¿²Á¬¿¾´» ³±ª©º ÌÞÔÐÌÎÔ ³±ªº °¬®Á°±­ôÉ ¿¼¼©º ÌÞÔÐÌÎÔôÚ ½´®º ÉÎÛÙ ¿¼¼©º½ ÌÞÔÐÌÎØôÚ ¿¼¼©º½ ÌÞÔÐÌÎËôÚ ­¬¿²Á²»¨¬Á½¸¿®Áï ¬¾´®¼ öõ ³±ªºº ÌßÞÔßÌô¬»³°Á©® ½¿´´ ¼Á©®·¬» ¼»½º­¦ ¾®¿ ³±ª´© ³±ª©º ¾¬º­­ ¹±¬± ³±ª´© ³±ª©º ¾¬º­­ ¹±¬± ®»¬«®² æ °¬®Á½±«²¬ôÚ ­¬¿²Á²»¨¬Á½¸¿®Áï þIJþ ÌÈÎÛÙ ÌÈÍÌßôÌÎÓÌ üóî þÄ®þ ÌÈÎÛÙ ÌÈÍÌßôÌÎÓÌ üóî å­»²¼ ½¸¿®¿½¬»® ¬± ÔÝÜ å³±ª» °±·²¬»® ¬± ²»¨¬ ½¸¿® å³±ª» ¼¿¬¿ ·²¬± ÌÈÎÛÙ å²»¨¬ ´·²» å©¿·¬ º±® ¼¿¬¿ ÌÈ å³±ª» ¼¿¬¿ ·²¬± ÌÈÎÛ٠彿®®·¿¹» ®»¬«®² å©¿·¬ º±® ¼¿¬¿ ÌÈ DS33014K-page 144 2009 Microchip Technology Inc.http://www.

• udata_ovr . these locations will be initialized during execution of the startup code.Begin an Object File Initialized Data Section”.Uninitialized shared data. • idata . ½¾´±½µ ð¨îð Ø·­¬±®§Ê»½¬±® åÓ«­¬ ¾» ·²·¬·¿´·¦»¼ ¬± ð ײ°«¬Ù¿·²ô Ñ«¬°«¬Ù¿·² åݱ²¬®±´ ´±±° ¹¿·²­ Ì»³°´ô Ì»³°îô Ì»³°í åË­»¼ º±® ·²¬»®²¿´ ½¿´½«´¿¬·±²­ »²¼½ Equivalent Relocatable Code Use data declarations to define register locations and initialize.63 “«¼¿¬¿Á¿½­ . • udata_shr .5 RAM ALLOCATION RAM space must be allocated in a data section.8 “½¾´±½µ . See 4.Define a Block of Constants”.62 “«¼¿¬¿ Begin an Object File Uninitialized Data Section”.Begin an Object File Shared Uninitialized Data Section (PIC12/16 MCUs)”. This is the most common type of data section. overlaid or shared data varies by device. This data section is used for variables that will be placed in RAM of PIC12/16 devices that is unbanked or shared across all banks. ·¼¿¬¿ Ø·­¬±®§Ê»½¬±® ¼¾ ð «¼¿¬¿ ײ°«¬Ù¿·² ®»­ ï Ñ«¬°«¬Ù¿·² ®»­ ï «¼¿¬¿Á±ª® Ì»³°´ ®»­ ï Ì»³°î ®»­ ï Ì»³°í ®»­ ï åײ·¬·¿´·¦»¼ ¬± ð åݱ²¬®±´ ´±±° ¹¿·²­ åË­»¼ º±® ·²¬»®²¿´ ½¿´½«´¿¬·±²­ 2009 Microchip Technology Inc. Relocatable Objects 6. See 4. Five types of data sections are available: Note: The ability to use access.) Variable values will need to be specified in code. • udata_acs .Uninitialized data.64 “«¼¿¬¿Á±ª® . See 4. DS33014K-page 145 . When linked with MPLAB C17 or C18 code. A typical use of this section is for temporary variables. Access RAM is used as quick data access for specified instructions.Generated by Foxit PDF Creator © Foxit Software http://www. The linker will generate a lookup table that can be used to initialize the variables in this section to the specified values. This data section is used for variables that can be declared at the same address as other variables in the same module or in other linked modules.65 “«¼¿¬¿Á­¸® . Consult your device data sheet for more information. The locations reserved by this section can be accessed only by the labels defined in this section or by indirect accesses.foxitsoftware.com For evaluation only.Uninitialized access data. See 4.Initialized data. EXAMPLE 6-4: RAM ALLOCATION Absolute Code Use ½¾´±½µ to define variable register locations (See 4. Locations reserved in this section are not initialized and can be accessed only by the labels defined in this section or by indirect accesses. This data section is used for variables that will be placed in access RAM of PIC18 devices. See 4. • udata .36 “·¼¿¬¿ .Begin an Object File Overlaid Uninitialized Data Section”.Uninitialized overlaid data. The following example shows how a data declaration might be created.Begin an Object File Access Uninitialized Data Section (PIC18 MCUs)”.

If necessary.Set Processor ID Locations” Only one linked module can specify these directives. After using these directives. ¼©. The following example shows how data will be initialized. ¼© and ¼¿¬¿ will define successive words of data memory in low-byte/high-byte order.Set Processor Configuration Bits (PIC18 MCUs)” • Section 4. ò«¼¿¬¿. They should be used prior to declaring any ½±¼» sections. ò«¼¿¬¿Á¿½­. An example of using the ¹´±¾¿´ and »¨¬»®² directives is shown below. each section must have a unique name. 6. When defining initialized data in an ·¼¿¬¿ section. If a name is not provided. the directives ¼¾. and ¼¿¬¿ can be used.33 “»¨¬»®² .11 “ÁÁ½±²º·¹ .Declare an Externally Defined Label”) to declare the existence of these labels. EXAMPLE 6-5: RELOCATABLE CODE LISTING ×ÜßÌß Þ§¬»­ ÜÞ ïôîôí ɱ®¼­ ÜÉ ð¨ïîíìôð¨ëêéè ͬ®·²¹ ÜÞ þßÞÝþô ð ððððï ðððð ðï ðî ðí ððððî ðððí íì ïî éè ëê ððððí ðððé ìï ìî ìí ðð ððððì 6. ¼¾ will define successive bytes of data memory.Set Processor Configuration Bits” • Section 4.12 “½±²º·¹ .38 “ÁÁ·¼´±½­ . DEFINING MODULE «¼¿¬¿ ײ°«¬Ù¿·² ®»­ ï Ñ«¬°«¬Ù¿·² ®»­ ï ¹´±¾¿´ ײ°«¬Ù¿·²ô Ñ«¬°«¬Ù¿·² ½±¼» Ú·´¬»® ¹´±¾¿´ Ú·´¬»® æ å Ú·´¬»® ½±¼» EXAMPLE 6-7: RELOCATABLE CODE. REFERENCING MODULE »¨¬»®² ײ°«¬Ù¿·²ô Ñ«¬°«¬Ù¿·²ô Ú·´¬»® «¼¿¬¿ λ¿¼·²¹ ®»­ ï ½±¼» æ ³±ª´© ³±ª©º ³±ª´© ³±ª©º Ùß×Òï ײ°«¬Ù¿·² Ùß×Òî Ñ«¬°«¬Ù¿·² DS33014K-page 146 2009 Microchip Technology Inc. If more than one of each section type is specified.6 CONFIGURATION BITS AND ID LOCATIONS Configuration bits and ID locations can still be defined in a relocatable object using the following directives: • Section 4.Export a Label”. the default section names are: ò·¼¿¬¿.foxitsoftware.http://www. . the location of the section may be fixed in memory by supplying the optional address parameter. and ò«¼¿¬¿Á±ª®. EXAMPLE 6-6: RELOCATABLE CODE. the current section is undefined.35 “¹´±¾¿´ .com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only.) Modules that use these labels must use the »¨¬»®² directive (see 4. ò«¼¿¬¿Á­¸®.7 ACCESSING LABELS FROM OTHER MODULES Labels that are defined in one module for use in other modules must be exported using the ¹´±¾¿´ directive (see 4.

RAM allocation will span multiple banks. respectively. These directives instruct the linker to generate the correct bank or page selecting code for a specified label.8 PAGING AND BANKING ISSUES In many cases.Generate Bank Selecting Code”) and °¿¹»­»´ (4. it is not always possible to place the proper code in the source file. Relocatable Objects ³±ªº ½¿´´ λ¿¼·²¹ôÉ Ú·´¬»® 6. DS33014K-page 147 . ¾¿²µ­»´ (4. ý·²½´«¼» °ïîºëðçò·²½ Ê¿®´ »¯« ð¨ïð Ê¿®î »¯« ð¨íð òòò ³±ª´© ײ·¬·¿´Ê¿´«» ¾½º ÚÍÎô ë ³±ª©º Ê¿®´ ¾­º ÚÍÎô ë ³±ª©º Ê¿®î ¾­º ÍÌßÌËÍô Ðß𠽿´´ Í«¾®±«¬·²» òòò Í«¾®±«¬·²» ½´®© òòò ®»¬´© ð åÜ»½´¿®» ª¿®·¿¾´»­ åÜ¿¬¿ ³»³±®§ Ê¿®ï ¾¿²µ øð÷ åÜ¿¬¿ ³»³±®§ Ê¿®î ¾¿²µ øï÷ åЮ±¹®¿³ ³»³±®§ °¿¹» ï åѲ п¹» ï BANKSEL for Banking and PAGESEL for Paging Use ¾¿²µ­»´ and °¿¹»­»´ for banking and paging.com For evaluation only. since the absolute addresses of these variable and address labels may not be known at assembly time. it is necessary to perform proper bank and page set-up to properly access the labels. An example of how code should be converted is shown below. ý·²½´«¼» °ïîºëðçò·²½ »¨¬»®² Ê¿®ïô Ê¿®î ½±¼» ³±ª´© ײ·¬·¿´Ê¿´«» ¾¿²µ­»´ Ê¿®´ ³±ª©º Ê¿®´ ¾¿²µ­»´ Ê¿®î ³±ª©º Ê¿®î °¿¹»­»´ Í«¾®±«¬·²» ½¿´´ Í«¾®±«¬·²» òòò Í«¾®±«¬·²» ½´®© òòò ®»¬´© ð åÜ»½´¿®» ª¿®·¿¾´»­ åÍ»´»½¬ ¼¿¬¿ ³»³±®§ Ê¿®ï ¾¿²µ åÍ»´»½¬ ¼¿¬¿ ³»³±®§ Ê¿®î ¾¿²µ åÍ»´»½¬ °®±¹®¿³ ³»³±®§ °¿¹» åп¹» «²µ²±©² ¿¬ ¿­­»³¾´§ ¬·³» 2009 Microchip Technology Inc. For these situations two directives. have been added. and executable code will span multiple pages.7 “¾¿²µ­»´ .53 “°¿¹»­»´ Generate Page Selecting Code (PIC10/12/16 MCUs)”). In these cases. respectively. However.foxitsoftware. EXAMPLE 6-8: BANKSEL AND PAGESEL Hard-Coded Banking and Paging Use indirect addressing (FSR) and the Status register for banking and paging.Generated by Foxit PDF Creator © Foxit Software http://www.

com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. it would be handy to break this off into a separate object file that can be linked in when required. .http://www.9 GENERATING THE OBJECT MODULE Once the code conversion is complete. generic routine. 6. The output file will have a ò± extension. EXAMPLE 6-9: ABSOLUTE CODE å ײ°«¬æ º·¨»¼ °±·²¬ ¿®¹«³»²¬­ ·² ßßÎÙÞð ¿²¼ ÞßÎÙÞð å Ñ«¬°«¬æ °®±¼«½¬ ßßÎÙ¨ÞßÎÙ ·² ßßÎÙÞðæßßÎÙÞï å Ѭ¸»® ½±³³»²¬­ ¬®«²½¿¬»¼ò Í»» ßÒêïéò åöööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö ý·²½´«¼» °ïêºèéé¿ò·²½ åË­» ¿²§ Ð×Ýïê ¼»ª·½» §±« ´·µ» ÔÑÑÐÝÑËÒÌ ßßÎÙÞð ßßÎÙÞï ÞßÎÙÞð ÛÏË ÛÏË ÛÏË ÛÏË ð¨îð ð¨îï ð¨îî ð¨îí åé ´±±°­ ²»»¼»¼ ¬± ½±³°´»¬» ®±«¬·²» åÓÍÞ ±º ®»­«´¬ ±«¬ô å±°»®¿²¼ ß ·² øè ¾·¬­÷ åÔÍÞ ±º ®»­«´¬ ±«¬ô å±°»®¿²¼ Þ ·² øè ¾·¬­÷ Ì»­¬Ý±¼» ½´®º ³±ª´© ³±ª©º ³±ª´© ³±ª©º ½¿´´ ¹±¬± ÛÒÜ ßßÎÙÞï Üùïïù ßßÎÙÞð Üùíðù ÞßÎÙÞð ËÓËÔðèðèÔ ü åÝ´»¿® °¿®¬·¿´ °®±¼«½¬ ¾»º±®» ¬»­¬·²¹ åߺ¬»® ´±¿¼·²¹ ßßÎÙÞð ¿²¼ ÞßÎÙÞðô 彿´´ ®±«¬·²» åλ­«´¬ ²±© ·² ßßÎÙÞðæßßÎÙÞïô 婸»®» øÞð ·­ ÓÍÞ÷ ËÓËÔðèðèÔ ³±ª´© ð¨ðè ³±ª©º ÔÑÑÐÝÑËÒÌ ³±ªº ßßÎÙÞðôÉ ÔÑÑÐËÓðèðèß ®®º ÞßÎÙÞðô Ú ¾¬º­½ ÍÌßÌËÍôÝ ¹±¬± ÔËÓðèðèÒßÐ ¼»½º­¦ ÔÑÑÐÝÑËÒÌô Ú ¹±¬± ÔÑÑÐËÓðèðèß ½´®º ßßÎÙÞð ®»¬´© ð¨ðð ÔËÓðèðèÒßÐ ¾½º ÍÌßÌËÍôÝ ¹±¬± ÔËÓðèðèÒß DS33014K-page 148 2009 Microchip Technology Inc. check the checkbox labeled “Object File”. specify the ñ± option. The absolute code file can be broken into two relocatable code files: a calling file representing an application and a generic routine that could be incorporated in a library.10 CODE EXAMPLE Since an eight-by-eight bit multiply is a useful. 6.foxitsoftware. the object module is generated automatically in MPLAB IDE or by requesting an object file on the command line or in the shell interface. When using the command line interface. When using MPASM assembler for Windows. This code was adapted from application note AN617. Please see the Microchip website for a downloadable PDF of this application note.

LIBRARY ROUTINE å ײ°«¬æ º·¨»¼ °±·²¬ ¿®¹«³»²¬­ ·² ßßÎÙÞð ¿²¼ ÞßÎÙÞð å Ñ«¬°«¬æ °®±¼«½¬ ßßÎÙ¨ÞßÎÙ ·² ßßÎÙÞðæßßÎÙÞï å Ѭ¸»® ½±³³»²¬­ ¬®«²½¿¬»¼ò Í»» ßÒêïéò åöööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö ý·²½´«¼» °ïêºèéé¿ò·²½ åË­» ¿²§ Ð×Ýïê ¼»ª·½» §±« ´·µ» ÙÔÑÞßÔ ËÜßÌß ÔÑÑÐÝÑËÒÌ ßßÎÙÞð ßßÎÙÞï ÞßÎÙÞð ËÓËÔðèðèÔô ßßÎÙÞðô ßßÎÙÞïô ÞßÎÙÞð ÎÛÍ ÎÛÍ ÎÛÍ ÎÛÍ ï ï ï ï åé ´±±°­ ²»»¼»¼ ¬± ½±³°´»¬» ®±«¬·²» åÓÍÞ ±º ®»­«´¬ ±«¬ô å±°»®¿²¼ ß ·² øè ¾·¬­÷ åÔÍÞ ±º ®»­«´¬ ±«¬ô å±°»®¿²¼ Þ ·² øè ¾·¬­÷ 2009 Microchip Technology Inc.foxitsoftware. Relocatable Objects ÔÑÑÐËÓðèðè ®®º ¾¬º­½ ¿¼¼©º ÔËÓðèðèÒß ®®º ®®º ¼»½º­¦ ¹±¬± ®»¬´© ÛÒÜ ÞßÎÙÞðô Ú ÍÌßÌËÍôÝ ßßÎÙÞðô Ú ßßÎÙÞðô Ú ßßÎÙÞïô Ú ÔÑÑÐÝÑËÒÌô Ú ÔÑÑÐËÓðèðè ð EXAMPLE 6-10: RELOCATABLE CODE.com For evaluation only. DS33014K-page 149 . CALLING FILE å ײ°«¬æ º·¨»¼ °±·²¬ ¿®¹«³»²¬­ ·² ßßÎÙÞð ¿²¼ ÞßÎÙÞð å Ñ«¬°«¬æ °®±¼«½¬ ßßÎÙ¨ÞßÎÙ ·² ßßÎÙÞðæßßÎÙÞï å Ѭ¸»® ½±³³»²¬­ ¬®«²½¿¬»¼ò Í»» ßÒêïéò åöööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö ý·²½´«¼» °ïêºèéé¿ò·²½ åË­» ¿²§ Ð×Ýïê ¼»ª·½» §±« ´·µ» ÛÈÌÛÎÒ ËÓËÔðèðèÔô ßßÎÙÞðô ßßÎÙÞïô ÞßÎÙÞð λ­»¬ ÝÑÜÛ ð¨ð °¿¹»­»´ Ì»­¬Ý±¼» ¹±¬± Ì»­¬Ý±¼» ÝÑÜÛ Ì»­¬Ý±¼» ¾¿²µ­»´ ½´®º ³±ª´© ³±ª©º ³±ª´© ³±ª©º °¿¹»­»´ ½¿´´ ¹±¬± ÛÒÜ ßßÎÙÞï ßßÎÙÞï Üùïïù ßßÎÙÞð Üùíðù ÞßÎÙÞð ËÓËÔðèðèÔ ËÓËÔðèðèÔ ü åÝ´»¿® °¿®¬·¿´ °®±¼«½¬ ¾»º±®» ¬»­¬·²¹ åÔ±¿¼ ·² î ¬»­¬ ª¿´«»­ åߺ¬»® ´±¿¼·²¹ ßßÎÙÞð ¿²¼ ÞßÎÙÞðô 彿´´ ®±«¬·²» åλ­«´¬ ²±© ·² ßßÎÙÞðæßßÎÙÞïô 婸»®» øßßÎÙÞð ·­ ÓÍÞ÷ EXAMPLE 6-11: RELOCATABLE CODE.Generated by Foxit PDF Creator © Foxit Software http://www.

DS33014K-page 150 2009 Microchip Technology Inc. .foxitsoftware.com Assembler/Linker/Librarian User’s Guide ÝÑÜÛ ËÓËÔðèðèÔ ³±ª´© ð¨ðè ³±ª©º ÔÑÑÐÝÑËÒÌ ³±ªº ßßÎÙÞðôÉ ÔÑÑÐËÓðèðèß ®®º ÞßÎÙÞðô Ú ¾¬º­½ ÍÌßÌËÍôÝ ¹±¬± ÔËÓðèðèÒßÐ ¼»½º­¦ ÔÑÑÐÝÑËÒÌô Ú ¹±¬± ÔÑÑÐËÓðèðèß ½´®º ßßÎÙÞð ®»¬´© ð¨ðð ÔËÓðèðèÒßÐ ¾½º ÍÌßÌËÍôÝ ¹±¬± ÔËÓðèðèÒß ÔÑÑÐËÓðèðè ®®º ÞßÎÙÞðô Ú ¾¬º­½ ÍÌßÌËÍôÝ ¿¼¼©º ßßÎÙÞðô Ú ÔËÓðèðèÒß ®®º ßßÎÙÞðô Ú ®®º ßßÎÙÞïô Ú ¼»½º­¦ ÔÑÑÐÝÑËÒÌô Ú ¹±¬± ÔÑÑÐËÓðèðè ®»¬´© ð ÛÒÜ Generated by Foxit PDF Creator © Foxit Software For evaluation only.http://www.

or MPASM assembler macro directives (´±½¿´ for example. Macro Language 7. DS33014K-page 151 . making them quite flexible. PIC1X MCU assembly instructions. Simplified changes..com For evaluation only. i. improving readability and reliability. Improved testability. ASSEMBLER/LINKER/LIBRARIAN USER’S GUIDE Chapter 7. Topics covered in this chapter: • • • • • Macro Syntax Macro Directives Defined Macro Definition Macro Invocation Macro Code Examples 7.Generated by Foxit PDF Creator © Foxit Software http://www.) The values assigned to these arguments at the time the macro is invoked will be substituted wherever the argument name occurs in the body of the macro.2 MACRO SYNTAX MPASM assembler macros are defined according to the following syntax: ´¿¾»´ ³¿½®± Å¿®¹ïô¿®¹î òòòô ¿®¹²Ã æ æ »²¼³ where ´¿¾»´ is a valid assembler label that will be the macro name and ¿®¹ is any number of optional arguments supplied to the macro (that will fit on the source line. forward references to macros are not permitted.1 INTRODUCTION Macros are user defined sets of instructions and directives that will be evaluated in-line with the assembler source code whenever the macro is invoked.foxitsoftware. The body of a macro may be comprised of MPASM assembler directives. and complex operations. Macros consist of sequences of assembler instructions and directives. They can be written to accept arguments. frequently used code. Applications might include creating complex tables.) The assembler continues to process the body of the macro until an »¨·¬³ or »²¼³ directive is encountered. Their advantages are: • • • • Higher levels of abstraction. Note: Macros must be defined before they are used. 2009 Microchip Technology Inc. Consistent solutions to frequently performed functions.e.

49 “²±»¨°¿²¼ . DS33014K-page 152 2009 Microchip Technology Inc.3 MACRO DIRECTIVES DEFINED There are directives that are unique to macro definitions. • • • • • • 4.5 MACRO INVOCATION Once the macro has been defined. Arguments may be used anywhere within the body of the macro. The macro call itself will not occupy any locations in memory.4 MACRO DEFINITION String replacement and expression evaluation may appear within the body of a macro. ·º¼»º.g. used to create unique variable names with common prefixes or suffixes. the argument will be an empty string.44 “´±½¿´ . The »¨·¬³ directive provides an alternate method for terminating a macro expansion. Typically. However.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. .foxitsoftware. Return the integer value of »¨°®.45 “³¿½®± . 7.End a Macro Definition” 4. The argument list is terminated by white space or a semicolon. as described below: ³¿½®±Á²¿³» Å¿®¹ô òòòô ¿®¹Ã where ³¿½®±Á²¿³» is the name of a previously defined macro and arguments are supplied as required.Turn off Macro Expansion” 4. Note: The previous syntax of the “dot” format for macro specific directives is no longer supported.31 “»¨·¬³ . Command ¿®¹ ýªø»¨°®÷ Description Substitute the argument text supplied as part of the macro invocation. During a macro expansion. it can be invoked at any point within the source module by using a macro call. They cannot be used out of the macro context. the macro expansion will begin at the current memory location. 7.Declare Local Macro Variable” When writing macros. In this case. »¨·¬³ causes code generation to return to the previous level of macro expansion. Cannot be used in conditional assembly directives (e.26 “»²¼³ . 7. Commas may be used to reserve an argument position. you can use any of these directives PLUS any other directives supported by the assembler.Exit from a Macro” 4. except as part of normal expression. this directive causes expansion of the current macro to stop and all code between the »¨·¬³ and the »²¼³ directives for this macro to be ignored.Expand Macro Listing” 4. If macros are nested.32 “»¨°¿²¼ . ©¸·´»).Declare Macro Definition” 4.http://www.

In this example. 0x56.6 MACRO CODE EXAMPLES The following are examples of macros: • Literal to RAM Conversion • Constant Compare 7.Generated by Foxit PDF Creator © Foxit Software http://www.foxitsoftware. DS33014K-page 153 . Macro Language EXAMPLE 7-1: MACRO CODE GENERATION The following macro: ¼»º·²»Á¬¿¾´» ³¿½®± ´±½¿´ ¿ ã 𠩸·´» ¿ ä í »²¬®§ýªø¿÷ ¼© ð ¿ õã ï »²¼© »²¼³ When invoked. would generate: »²¬®§ð »²¬®§ï »²¬®§î »²¬®§í ¼© ¼© ¼© ¼© ð ð ð ð 7.com For evaluation only. and 0x78. the literal 0x12345678 is put in the desired 8 bit registers as 0x12. 0x34. Any literal can be “unpacked” this way using this macro. ý·²½´«¼» «¼¿¬¿ ð¨îð Ñ«¬ð ®»­ ï Ñ«¬ï ®»­ ï Ñ«¬î ®»­ ï Ñ«¬í ®»­ ï °ïêÚèééßò·²½ å ÔÍÞ å æ å æ å ÓÍÞ Ë²°¿½µíî ÓßÝÎÑ Ê¿®ô ß¼¼®»­­ åÊ¿® ã íî ¾·¬ ´·¬»®¿´ ¬± ¾» «²°¿½µ»¼ ÞßÒÕÍÛÔ ß¼¼®»­­ åß¼¼®»­­ ­°»½·º·»­ ¬¸» ÔÍÞ ­¬¿®¬ ³±ª´© ß¼¼®»­­ åË­» ÚÍÎ ¿²¼ ×ÒÜÚ º±® ·²¼·®»½¬ ³±ª©º ÚÍΠ忽½»­­ ¬± ¼»­·®»¼ ¿¼¼®»­­ ³±ª´© ³±ª©º ³±ª´© ·²½º ³±ª©º ³±ª´© ·²½º ³±ª©º ³±ª´© ·²½º ³±ª©º Ê¿® ú ØùÚÚù åÓ¿­µ ¬± ¹»¬ ÔÍÞ ×ÒÜÚ åЫ¬ ·² º·®­¬ ´±½¿¬·±² Ê¿® ââÜùðèù ú ØùÚÚùåÓ¿­µ ¬± ¹»¬ ²»¨¬ ¾§¬» ±º ´·¬»®¿´ ÚÍÎôÚ åб·²¬ ¬± ²»¨¬ ¾§¬» ×ÒÜÚ åÉ®·¬» ¼¿¬¿ ¬± ²»¨¬ ¾§¬» Ê¿® ââÜùïêù ú ØùÚÚùåÓ¿­µ ¬± ¹»¬ ²»¨¬ ¾§¬» ±º ´·¬»®¿´ ÚÍÎôÚ åб·²¬ ¬± ²»¨¬ ¾§¬» ×ÒÜÚ åÉ®·¬» ¼¿¬¿ ¬± ²»¨¬ ¾§¬» Ê¿® ââÜùîìù ú ØùÚÚùåÓ¿­µ ¬± ¹»¬ ´¿­¬ ¾§¬» ±º ´·¬»®¿´ ÚÍÎôÚ åб·²¬ ¬± ´¿­¬ ¾§¬» ×ÒÜÚ åÉ®·¬» ¼¿¬¿ ¬± ´¿­¬ ¾§¬» ÛÒÜÓ åÛ²¼ ±º ¬¸» Ó¿½®± Ü»º·²·¬·±² ÑÎÙ ð ͬ¿®¬ ˲°¿½µíî ð¨ïîíìëêéèôÑ«¬ð ¹±¬± ü ÛÒÜ åÌÛÍÌ ÝÑÜÛ º±® ˲°¿½µíî ÓßÝÎÑ åЫ¬ ˲°¿½µ Ó¿½®± ¸»®» åܱ ²±¬¸·²¹ ø´±±° º±®»ª»®÷ 2009 Microchip Technology Inc.1 Literal to RAM Conversion This code converts any literal of 32 bits to 4 separate RAM data values.6.

2 Constant Compare As another example.6.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. 7. if the following macro were written: ý·²½´«¼» þ°·½ïêºèéé¿ò·²½þ å å ½±³°¿®» º·´» ¬± ½±²­¬¿²¬ ¿²¼ ¶«³° ·º º·´» å âã ½±²­¬¿²¬ò å ½º´Á¶¹» ³¿½®± º·´»ô ½±²ô ¶«³°Á¬± ³±ª´© ½±² ú 𨺺 ­«¾©º º·´»ô © ¾¬º­½ ­¬¿¬«­ô ½¿®®§ ¹±¬± ¶«³°Á¬± »²¼³ and invoked by: ½º´Á¶¹» ­©·¬½¸Áª¿´ô ³¿¨Á­©·¬½¸ô ­©·¬½¸Á±² it would produce: ³±ª´© ­«¾©º ¾¬º­½ ¹±¬± ³¿¨Á­©·¬½¸ ú 𨺺 ­©·¬½¸Áª¿´ô © ­¬¿¬«­ô ½¿®®§ ­©·¬½¸Á±² DS33014K-page 154 2009 Microchip Technology Inc.foxitsoftware. .http://www.

and Limitations 8. The messages will still appear in the listing file.1 INTRODUCTION Error messages. The messages are stored in the error file (ò»®®) if no MPASM assembler options are specified. 103 Symbol table full No more memory available for the symbol table. Messages.foxitsoftware. then the messages will appear on the screen.2 ASSEMBLER ERRORS MPASM assembler errors are listed numerically below: 101 ERROR: User error. then the messages will not display on the screen or in an error file. DS33014K-page 155 . warning messages and general messages produced by the MPASM assembler are listed and detailed here.Generated by Foxit PDF Creator © Foxit Software http://www. These messages always appear in the listing file directly above each line in which the error occurred. 2009 Microchip Technology Inc. Limitations of the assembler tool are also listed. ý¼»º·²»’s or internal processing. 102 Out of memory Not enough memory for macros. Errors. If the ñ»ó option is used (turns error file off). If the ñ¯ (quiet mode) option is used with the ñ»ó. invoked with the »®®±® directive. Warnings.com For evaluation only. Check the available disk space. Topics covered in this chapter: • • • • Assembler Errors Assembler Warnings Assembler Messages Assembler Limitations 8. 104 Temp file creation error Could not create a temporary file. ASSEMBLER/LINKER/LIBRARIAN USER’S GUIDE Chapter 8.

0-7 for octal. For example. 111 Missing symbol An »¯« or ­»¬ directive did not have a symbol to which to assign the value.F). and when you copy the files. and then copy the data to your computer. A. Check for nesting of ý¼»º·²»’s. If it is a source file. For example. Copying to a CD marks all files as read-only (they cannot be changed on a CD-R).. 107 Illegal digit An illegal digit in a number. 105 Cannot open file Could not open a file. 110 Unmatched ) An close parenthesis did not have a matching open parenthesis. and then restore them from CD. ÜßÌß øïõî. If it is. ÜßÌß ï î. Labels may not begin with a numeric. For example. and the question mark (?). 109 Unmatched ( An open parenthesis did not have a matching close parenthesis. If it is an output file. . A good way to prevent this is to archive all of the files in one file. a-f. The archive will preserve the original file attributes. it cannot be modified by MPLAB IDE and will generate this error message. 106 String substitution too complex A string substitution was attempted that was too complex.http://www. 108 Illegal character An illegal character in a label. 0-9 for decimal. Valid digits are 0-1 for binary. 112 Missing operator An arithmetic operator was missing from an expression.ZIP.. Choose “Properties” and see if “read-only” is checked. the old version may be write protected. the attributes move with them making them all read-only on your hard drive.foxitsoftware. and A-F for hexadecimal. This often happens when you save your project to a CD-R or similar write-once media as a backup. numeric (0-9). To check for write-protect.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. right-click on the file named by MPLAB IDE in Windows. the underscore (_).f. Valid characters for labels are alphabetic (a. DS33014K-page 156 2009 Microchip Technology Inc. ÜßÌß ïõî÷. such as a *. the file may not exist. and 0-9.

high. 117 Address wrapped around 0 For PIC12/16 devices. Additionally. low. 2009 Microchip Technology Inc. 122 Illegal opcode Token is not a valid opcode. 121 Illegal label Labels are not allowed on certain directive lines. This often happens when users try to write page-bit setting macros that generate different numbers of instructions based on the destination. 120 Call or jump not allowed at this address A call or jump cannot be made to this address. you may include files within other include files. Since the text from an include file is inserted at the location of the ý·²½´«¼» statement. spelling mistake or case change in your label. As a general rule. the label was used only once but evaluated to a different location on the second pass. ¹±¬± Ó§Ô¿¾»´ will never locate the code at Ó§´¿¾´ or Ó§´¿¾´». Errors. it wraps back to 0. 119 Code too fragmented The code is broken into too many pieces. you can get this error. DS33014K-page 157 . Error 117 is followed by error 118.foxitsoftware. Constants and variables must be declared before they are used. If this seems to cluttered. Simply put the label on its own line. the error may occur due to a typing error. Check the spelling and location of the declaration of any symbols used in your code. and bank are not allowed as labels. and you may have labels used before that point. the location counter can only advance to 0xFFFF. CALL destinations on the PIC16C5x family must be in the lower half of the page. For example..g. Ó§Ô¿¾»´ is not the same as Ó§´¿¾»´ unless case sensitivity is turned off (it is on by default). Messages. This sometimes happens when ý·²½´«¼» files are used in your project. 114 Divide by zero Division by zero encountered during an expression evaluation. above the directive. Alternately. page. Warnings. 116 Address label duplicated or different in second pass The same label was used in two locations. 115 Duplicate label A label was declared as a constant (e. Also. Check for these sorts of mistakes first. This error is very rare. After that.http://www. with the »¯« or ½¾´±½µ directive) in more than one location.com For evaluation only. put your include files at the top of each file. Also. 118 Overwriting previous address contents Code was previously generated for this address. and Limitations Generated by Foxit PDF Creator © Foxit Software 113 Symbol not previously defined A symbol was referenced that has not yet been defined. Only addresses may be used as forward references. and will only occur in source code that references addresses above 32K (including configuration bits).

For example.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. ´·­¬ º±±¾¿®. ÌÎ×Í ïð. 126 Argument out of range Opcode or directive argument out of the valid range. 133 Hex file format INHX32 required An address above 32K was specified. 132 Unknown processor The selected processor is not a valid processor. 138 Include files nested too deep The maximum include file nesting level was exceeded. 129 Expected Expected a certain type of argument. for example. for example. The expected list will be provided. 136 Duplicate macro name A macro name was duplicated. 123 Illegal directive Directive is not allowed for the selected processor. Note that until the processor is defined. DS33014K-page 158 2009 Microchip Technology Inc. for example.foxitsoftware. 135 Macro name missing A macro was defined without a name. 127 Too many arguments Too many arguments specified for a macro call. 124 Illegal argument An illegal directive argument. an unmatched »²¼·º. 128 Missing argument(s) Not enough arguments for a macro call or an opcode. . the ÁÁ·¼´±½­ directive on devices with ID locations.http://www. 125 Illegal condition A bad conditional assembly. the opcode set is not known. 137 Macros nested too deep The maximum macro nesting level was exceeded. 131 Processor type is undefined Code is being generated before the processor has been defined. 134 Illegal hex file format An illegal hex file format was specified in the ´·­¬ directive. 130 Processor type previously defined A different family of processor is being selected.

They cannot be used when generating absolute code. 2009 Microchip Technology Inc. 149 Directive only allowed when generating an object file Certain directives. 140 WHILE must terminate within 256 iterations A ©¸·´»-»²¼© loop must terminate within 256 iterations. This is to prevent infinite assembly. 144 Unmatched ENDC »²¼½ found without a ½¾´±½µ. 141 WHILEs nested too deep The maximum ©¸·´»-»²¼© nesting level was exceeded. It cannot be used when generating absolute code. 143 Illegal nesting Macros. Messages. DS33014K-page 159 . Note that ý¼»º·²» substitution does not include comments. is 200 characters. 147 Directive/operation only allowed when generating an object file The instruction/operand shown only has meaning when a linkable object file is generated.com For evaluation only. the »²¼·º must come before the »²¼©.foxitsoftware. 146 Unmatched EXITM »¨·¬³ found without a ³¿½®± definition. they cannot overlap.http://www. all data and code address labels must be defined inside a data or code section. 148 Expanded source line exceeded 200 characters The maximum length of a source line. Symbols defined by the »¯« and ­»¬ directives can be defined outside of a section. and Limitations Generated by Foxit PDF Creator © Foxit Software 139 Maximum of 100 lines inside WHILE-ENDW A ©¸·´»-»²¼© can contain at most 100 lines. after ý¼»º·²» and macro parameter substitution. Warnings. only have meaning when a linkable object file is generated. 145 Unmatched ENDM »²¼³ found without a ³¿½®± definition. ·º's and ©¸·´»'s must be completely nested. 142 IFs nested too deep The maximum ·º nesting level was exceeded. but macro parameter substitution does. If you have an ·º within a ©¸·´» loop. 150 Labels must be defined in a code or data section when making an object file When generating a linkable object file. operands must be of the form [¸·¹¸|´±©]([relocatable address label]+[offset]). Errors. 151 Operand contains unresolvable labels or is too complex When generating an object file. such as ¹´±¾¿´ and »¨¬»®².

optionally prefixed with a ‘. The lexical form of a section name is that of an identifier. ¾¿²µ­»´ or ¾¿²µ·­»´ directive must be a relocatable address label or a constant. Consult your device data sheet. 155 All overlaid sections of the same name must have the same starting address If multiple «¼¿¬¿Á±ª® sections with the same name are declared. 157 ORG at odd address For PIC18 devices. 161 Non-negative value required for this context. only even. 163 __CONFIG directives must be contiguous Do not place other code between ÁÁ½±²º·¹ directive declarations.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. 158 Cannot use RES directive with odd number of bytes For PIC18 devices. cannot be stopped and restarted within a single source file. all executable code and data declarations must be placed within appropriate sections.foxitsoftware. 152 Executable code and data must be defined in an appropriate section When generating a linkable object file. 159 Cannot use FILL directive with odd number of bytes For PIC18 devices. Variables declared by the ­»¬ or »¯« directives may not be exported. 153 Page or Bank bits cannot be evaluated for the operand The operand of a °¿¹»­»´. 156 Operand must be an address label When generating object files. only address labels in code or data sections may be declared global. only even. either name each section with its own name or move the code and data declarations such that each section is contiguous. 154 Each object file section must be contiguous Object file sections. Some contexts require non-negative values. Consult your device data sheet. . To resolve this problem. This error will also be generated if two sections of different types are given the same name.substituting CODE The ½±¼»Á°¿½µ directive can only be used with byte-addressable ROM.’. only even. 164 __IDLOC directives must be contiguous Do not place other code between ÁÁ·¼´±½ directive declarations. Consult your device data sheet. you cannot place ±®¹ at an odd address. 160 CODE_PACK directive not available for this part. except «¼¿¬¿Á±ª® sections. you cannot use ®»­ to specify an odd number of bytes. DS33014K-page 160 2009 Microchip Technology Inc. 162 Expected a section name Some operators and pseudo-operators take section names as operands. you cannot use º·´´ to fill with data an odd number of bytes. they must all have the same starting address.http://www.

http://www.foxitsoftware.com For evaluation only. Errors, Warnings, Messages, and Limitations

Generated by Foxit PDF Creator © Foxit Software

165 extended mode not available for this device
This PIC18 device does not support extended mode.

166 left bracket missing from offset operand
The left bracket is missing from an offset, i.e., Åð¨ëë.

167 right bracket missing from offset operand
The right bracket is missing from an offset, i.e., ð¨ëëÃ.

168 square brackets required around offset operand
Square brackets are required around an offset, i.e., Åð¨ëëÃ

169 access bit cannot be specified with indexed mode
When using indexed mode, the access bit cannot be specified.

170 expression within brackets must be constant
The expression specified within brackets is not a constant value.

171 address specified is not in access ram range of [0x60, 0xFF]
When making use of Access RAM, addressing must occur within the specified Access Bank range.

172 PCL, TOSL, TOSH, or TOSU cannot be destination of MOVFF or MOVSF
These registers cannot be written to with ³±ªºº or ³±ª­º commands.

174 __CONFIG directives must be listed in ascending order
List ½±²º·¹ directive configuration registers in ascending order, i.e.,
ÁÁÝÑÒÚ×Ù ÁÁÝÑÒÚ×Ù ÁÁÝÑÒÚ×Ù ÁÝÑÒÚ×Ùðô ÁÝÐÁÑÚÚÁð ÁÝÑÒÚ×Ùïô ÁÑÍÝÍÁÑÚÚÁï ú ÁÎÝ×ÑÁÑÍÝÁï ÁÝÑÒÚ×Ùîô ÁÞÑÎÁÑÒÁî ú ÁÞÑÎÊÁîëÁî æ

175 __IDLOCS directives must be listed in ascending order
List ÁÁ·¼´±½­ directive ID registers in ascending order, i.e.,
ÁÁ·¼´±½­ ÁÁ·¼´±½­ ÁÁ·¼´±½­ Á×ÜÔÑÝðô ð¨ï Á×ÜÔÑÝïô ð¨î Á×ÜÔÑÝîô ð¨í æ

176 CONFIG Directive Error:
An error was found in the ½±²º·¹ directive syntax.

177 __CONFIG directives cannot be used with CONFIG directives
Do not mix ÁÁ½±²º·¹ directives and ½±²º·¹ directives when assigning configuration bits in your code.

178 __CONFIG Directive Error:
An error was found in the __½±²º·¹ directive syntax.

2009 Microchip Technology Inc.

DS33014K-page 161

http://www.foxitsoftware.com Assembler/Linker/Librarian User’s Guide

Generated by Foxit PDF Creator © Foxit Software For evaluation only.

179 Instruction is not supported on this device
This error would occur when an instruction is used in code which is not supported on the particular family/architecture.

180 RES directive cannot reserve odd number of bytes in PIC18 absolute mode
This error would occur if you try to reserve an odd number of bytes using a PIC18 device and assemble in absolute mode (Quickbuild). For example:
±®¹ ð¨ð ¿ ®»­ ï »²¼

If you try to Quickbuild the above PIC18 MCU program, you will see error 180 and warning 231.

### UNKNOWN ERROR
An internal application error has occurred. (### is the value of the last defined error plus 1.) Contact your Microchip Field Application Engineer (FAE) or Microchip support if you cannot debug this error.

8.3

ASSEMBLER WARNINGS
MPASM assembler warnings are listed numerically below:

201 Symbol not previously defined.
The symbol being ý«²¼»º·²»d was not previously defined.

202 Argument out of range. Least significant bits used.
Argument did not fit in the allocated space. For example, literals must be 8 bits.

203 Found opcode in column 1.
An opcode was found in column one, which is reserved for labels.

204 Found pseudo-op in column 1.
A pseudo-op was found in column one, which is reserved for labels.

205 Found directive in column 1.
A directive was found in column one, which is reserved for labels.

206 Found call to macro in column 1.
A macro call was found in column one, which is reserved for labels.

207 Found label after column 1.
A label was found after column one, which is often due to a misspelled opcode.

208 Label truncated at 32 characters.
Maximum label length is 32 characters.

209 Missing quote.
A text string or character was missing a quote. For example, ÜßÌß ù¿.

DS33014K-page 162

2009 Microchip Technology Inc.

http://www.foxitsoftware.com For evaluation only. Errors, Warnings, Messages, and Limitations

Generated by Foxit PDF Creator © Foxit Software

210 Extra “,”
An extra comma was found at the end of the line.

211 Extraneous arguments on the line.
Extra arguments were found on the line.

212 Expected (ENDIF)
Expected an »²¼·º statement, i.e., an ·º statement was used without an »²¼·º.

213 The EXTERN directive should only be used when making a .o file.
The »¨¬»®² directive only has meaning if an object file is being created. This warning has been superseded by Error 149.

214 Unmatched (
An unmatched parenthesis was found. The warning is used if the parenthesis is not used for indicating order of evaluation.

215 Processor superseded by command line. Verify processor symbol.
The processor was specified on the command line as well as in the source file. The command line has precedence. If you are using MPLAB IDE with the assembly, set the device to match the source file from Configure>Select Device.

216 Radix superseded by command line.
The radix was specified on the command line as well as in the source file. The command line has precedence.

217 Hex file format specified on command line.
The hex file format was specified on the command line as well as in the source file. The command line has precedence.

218 Expected DEC, OCT, HEX. Will use HEX.
Bad radix specification.

219 Invalid RAM location specified.
If the ÁÁ³¿¨®¿³ and ÁÁ¾¿¼®¿³ directives are used, this warning flags use of any RAM locations declared as invalid by these directives. Note that the provided header files include ÁÁ³¿¨®¿³ and ÁÁ¾¿¼®¿³ for each processor.

220 Address exceeds maximum range for this processor.
A ROM location was specified that exceeds the processor's memory size.

221 Invalid message number.
The message number specified for displaying or hiding is not a valid message number.

222 Error messages cannot be disabled.
Error messages cannot be disabled with the »®®±®´»ª»´ command.

223 Redefining processor
The selected processor is being reselected by the ´·­¬ or °®±½»­­±® directive.

2009 Microchip Technology Inc.

DS33014K-page 163

http://www.foxitsoftware.com Assembler/Linker/Librarian User’s Guide

Generated by Foxit PDF Creator © Foxit Software For evaluation only.

224 Use of this instruction is not recommended.
The instruction is being obsoleted and is not recommended for current use. However, it is still supported for legacy reasons.

225 Invalid label in operand
Operand was not a valid address. For example, if the user tried to issue a CALL to a MACRO name.

226 Destination address must be word aligned
The destination address is not aligned with the start of a program memory word. For this device, use even bytes to specify address.

227 Substituting RETLW 0 for RETURN pseudo-op
Using ®»¬´© ð instead of ®»¬«®² to resume program execution.

228 Invalid ROM location specified
The data memory location specified is not valid for the operation specified or is non-existent.

229 extended mode is not in effect -- overridden by command line
A command-line option has disabled extended mode operation.

230 __CONFIG has been deprecated for PIC18 devices. Use directive CONFIG.
Although you may still use the ÁÁ½±²º·¹ directive for PIC18 MCU devices, it is strongly recommended that you use the ½±²º·¹ directive (no leading underscores) instead. For PIC18FXXJ MCUs, you must user the ½±²º·¹ directive.

231 No memory has been reserved by this instruction
This warning would appear if an instruction which is meant to reserve memory cannot actually reserve that memory. For example:
¿ ±®¹ ð¨ð ®»­ ï »²¼

The above PIC18 assembly program is attempting to reserve one byte (¿ ®»­ ï) but this is not valid for a PIC18 MCU as each word size is two bytes.

232 STATUS register has no IRP or RP1 or RP0 bits
For PIC16 extended instruction devices, you are trying to access a non-existent bit of the STATUS register (IRP or RP1 or RP0 bits).

### UNKNOWN WARNING
An internal application error has occurred. (### is the value of the last defined warning plus 1.) However, it is not severe enough to keep your code from assembling, i.e., it is a warning, not an error.

DS33014K-page 164

2009 Microchip Technology Inc.

http://www.foxitsoftware.com For evaluation only. Errors, Warnings, Messages, and Limitations

Generated by Foxit PDF Creator © Foxit Software

8.4

ASSEMBLER MESSAGES
MPASM assembler messages are listed numerically below:

301 MESSAGE:
User-definable message, invoked with the ³»­­¹ directive (see Section 4.48 “³»­­¹ - Create User Defined Message”.)

302 Register in operand not in bank 0. Ensure that bank bits are correct.
This is a commonly seen reminder message to tell you that a variable that is being accessed in not in bank 0. This message was added to remind you to check your code, particularly code in banks other than 0. Review the section on ¾¿²µ­»´ (Section 4.7 “¾¿²µ­»´ - Generate Bank Selecting Code”) and ¾¿²µ·­»´ (Section 4.6 “¾¿²µ·­»´ - Generate Indirect Bank Selecting Code (PIC12/16 MCUs)”) and ensure that your code uses bank bits whenever changing from ANY bank to ANY other bank (including bank 0). Since the assembler or linker can't tell which path your code will take, you will always get this message for any variable not in bank 0. You can use the »®®±®´»ª»´ command to turn this and other messages on and off, but be careful as you may not spot a banking problem with this message turned off. For more about »®®±®´»ª»´, see Section 4.30 “»®®±®´»ª»´ - Set Message Level”. A similar message is 306 for paging.

303 Program word too large. Truncated to core size.
The program word (instruction width) is too large for the selected device’s core (program memory) size. Therefore the word has been truncated to the proper size. For example, a 14-bit instruction would be truncated to 12 bits to be used by a PIC16F54.

304 ID Locations value too large. Last four hex digits used.
Only four hex digits are allowed for the ID locations.

305 Using default destination of 1 (file).
If no destination bit is specified, the default is used. Usually code that causes this message is missing theôÉ or ôÚ after the register name, but sometimes the bug is due to typing ³±ªº instead of ³±ª©º. It is best to fix any code that is causing this message. The default destination could not be where you want the value stored, and could cause the code to operate strangely.

306 Crossing page boundary -- ensure page bits are set.
Generated code is crossing a page boundary. This is a reminder message to tell you that code is being directed to a label that is on a page other than page 0. It is not an error or warning, but a reminder to check your page bits. Use the °¿¹»­»´ directive (Section 4.53 “°¿¹»­»´ - Generate Page Selecting Code (PIC10/12/16 MCUs)”) before this point and remember to use another °¿¹»­»´ if returning to page 0. The assembler can't tell what path your code will take, so this message is generated for any label in a page other than 0.You can use the »®®±®´»ª»´ command to turn this and other messages on and off, but be careful as you may not spot a paging problem with this message turned off. For more about »®®±®´»ª»´, see Section 4.30 “»®®±®´»ª»´ - Set Message Level”. A similar message is 302 for banking.

2009 Microchip Technology Inc.

DS33014K-page 165

¾¿²µ­»´. No code generated. 316 W Register modified. is available from the Microchip website. BSF/BCF STATUS instructions used instead. The command line has precedence. 309 Macro expansion superseded by command line. (### is the value of the last defined message plus 1.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. no page or bank selection is required. 313 CBLOCK constants will start with a value of 0. The working (W) register has not been modified 318 Superseding current maximum ROM and ROM map. Page bits are being set with the LCALL or LGOTO pseudo-op. . PIC18CXX2 Silicon/Data Sheet Errata. 308 Warning level superseded by command line value.e. High byte of address returned by ¸·¹¸ directive was greater than 0xFFFF. 311 Operand of HIGH operator was larger than H’FFFF’. i. 307 Setting page bits.) However.. The command line has precedence. The ÁÁ³¿¨®¿³ directive has been used previously. The working (W) register has been modified 317 W Register not modified. and any °¿¹»­»´. ### UNKNOWN MESSAGE An internal application error has occurred. DS33014K-page 166 2009 Microchip Technology Inc.http://www. 312 Page or Bank selection not needed for this device. this message will be generated. 310 Superseding current maximum RAM and RAM map. If a device contains only one ROM page or RAM bank. Macro expansion was specified on the command line as well as in the source file. 315 Please refer to Microchip document DS80058A for more details A downloadable PDF of this document.foxitsoftware. not an error. it is not severe enough to keep your code from assembling. it is a message. 314 LFSR instruction is not supported on some versions of the 18Cxx2 devices. See message 315 for more information. Operation will cause maximum ROM to be exceeded. or ¾¿²µ·­»´ directives will not generate any code. The warning level was specified on the command line as well as in the source file. If the first ½¾´±½µ in the source file has no starting value specified.

Maximum nesting depth = 16 • ·²½´«¼» directive limits . There is no character restriction with MPLINK linker. Messages. (2) source file directory. • ·º directive limits .1 General Limitations • If a fully qualified path is specified. DS33014K-page 167 .Create a mapped drive for the long directory chain. Errors. Work arounds: . and (3) MPASM assembler executable directory.5 ASSEMBLER LIMITATIONS 8. . . and not the assembler alone.Maximum nesting depth = 8 .Shorten your file name or move your file into a directory closer to the root directory (shorten the path name).com For evaluation only.5.Maximum nesting depth = 16 • ©¸·´» directive limits . 2009 Microchip Technology Inc.Use the linker with the assembler.File names are limited to 8.Maximum nesting depth = 5 . • There is a 62 character length restriction for file and path names in the debug (COD) file produced by MPASM assembler.Maximum iterations = 256 8.3 MPASM Assembler Versions before v3. the search order is: (1) current working directory.5.Maximum number of lines per loop = 100 .30 (v3. to generate your output. Warnings. .http://www. • There is a source file line limit (expanded) of 200 characters. • The command-line version of the assembler (³°¿­³ò»¨») has the following limitations: .3 format. only that path will be searched. Otherwise.2x and earlier) have limitations based on the generation a COD file for debugging and the support of a command-line version. 8.30 Assembler versions before v3. and Limitations Generated by Foxit PDF Creator © Foxit Software 8. This can cause problems when assembling single files with long file names and/or path names. ³°¿­³ò»¨».foxitsoftware.Maximum number of files = 255 • ³¿½®± directive limits .2 Directive Limitations • Do not use ý·²½´«¼»­ in macros.½±²º·¹ directive not supported. and try assembling your file again.5.

com Assembler/Linker/Librarian User’s Guide NOTES: Generated by Foxit PDF Creator © Foxit Software For evaluation only.foxitsoftware. DS33014K-page 168 2009 Microchip Technology Inc. .http://www.

................................. MPLINK Linker Overview ..................................................foxitsoftware.......... Errors.......... 179 Chapter 11.............. ASSEMBLER/LINKER/LIBRARIAN USER’S GUIDE Part 2 – MPLINK Object Linker Chapter 9...... Sample Applications ........ 171 Chapter 10. 181 Chapter 12..... DS33014K-page 169 .............................................................................................. Linker Scripts ................ Linker Interfaces..................Generated by Foxit PDF Creator © Foxit Software http://www................................ 223 2009 Microchip Technology Inc............. Warnings and Common Problems .......................com For evaluation only...... 195 Chapter 14....................................................................... Linker Processing ........................... 191 Chapter 13....................

com Assembler/Linker/Librarian User’s Guide NOTES: Generated by Foxit PDF Creator © Foxit Software For evaluation only. DS33014K-page 170 2009 Microchip Technology Inc.http://www.foxitsoftware. .

1 INTRODUCTION An overview of the MPLINK object linker and its capabilities is presented.3 HOW MPLINK LINKER WORKS MPLINK linker performs many functions: • Locates Code and Data. Produces a .foxitsoftware. • Identifies Address Conflicts.hex file that can be programmed into a PIC1X MCU or loaded into an emulator or simulator to be executed. see Chapter 1. and line/file information for source level debugging. ASSEMBLER/LINKER/LIBRARIAN USER’S GUIDE Chapter 9. For more information on MPLAB C18. see C compiler documentation listed in Recommended Reading.com For evaluation only. • Configures Stack Size and Location. 9.Generated by Foxit PDF Creator © Foxit Software http://www. 2009 Microchip Technology Inc. Using the linker script. • Resolves Addresses. Checks to ensure that program/data do not get assigned to space that has already been assigned or reserved. MPLINK Linker Overview 9. The linker takes as input relocatable object files. variable locations. it decides where the code will be placed in program memory and where variables will be placed in RAM. as generated by the MPLIB object librarian. The linker also accepts libraries of object files as input. The linking process is controlled by a linker script file. Allows MPLAB C18 to set aside RAM space for dynamic stack usage. Outputs a file that MPLAB IDE uses to track address labels. • Generates an Executable. External references in a source file generate relocation entries in the object file. After the linker locates code and data.2 MPLINK LINKER DEFINED MPLINK object linker (the linker) combines object modules generated by the MPASM assembler or the MPLAB C18 C compiler into a single executable (hex) file. DS33014K-page 171 . For more information on MPASM assembler. Topics covered in this chapter: • • • • • • MPLINK Linker Defined How MPLINK Linker Works How MPLINK Linker Helps You Linker Platforms Supported Linker Operation Linker Input/Output Files 9. • Provides Symbolic Debug Information. “MPASM Assembler Overview”. it uses this relocation information to update all external references with the actual addresses. which is also input into MPLINK linker.

Control over the linking process is accomplished through a linker script file and with command line options. MPLINK linker can help you with: • Reusable Source Code. The Microchip compiler for PIC18 devices requires the use of MPLINK linker and can be used with precompiled libraries and MPASM assembler. FIGURE 9-1: ³¿·²ò± MPLINK™ LINKER OPERATION °®±¹ïò± °®±¹îò± °®»½±³°ò± Object files ³¿¬¸ò´·¾ ¼»ª·½»ò´µ® Linker script file* library file °®±¹ò½±º °®±¹ò³¿° Output files DS33014K-page 172 2009 Microchip Technology Inc. 9. reusable modules. precompiled objects and libraries can be combined with new source modules and placed efficiently into available memory at link time. 9. A map file can also be generated to aid in debugging. • Accelerated Development. reusable code. readily compilable applications.http://www.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. 9. per the linker script file. . You can make libraries of related functions which can be used in creating efficient. By using application-specific linker scripts. • Centralized Memory Allocation. compilation time may be reduced. Utilities can be used to generate executable code (ò¸»¨) or a linker listing file (ò´­¬) from the COF file.6 LINKER OPERATION The MPLINK linker combines multiple input object modules and library files.4 HOW MPLINK LINKER HELPS YOU MPLINK linker allows you to produce modular. You can build up your application in small. Since tested modules and libraries don't have to be recompiled each time a change is made in your code.foxitsoftware. into a single output COF file. • MPLAB C18. The linker ensures that all symbolic references are resolved and that code and data fit into the available PIC1X MCU device. • Libraries.5 LINKER PLATFORMS SUPPORTED MPLINK linker is distributed as a Windows 32 console application suitable for Windows 95/98 and Windows NT/2000/XP platforms.

or. If there is too much code or too many variables to fit.hex. the linker will give an error message. 9.map) 2009 Microchip Technology Inc. The linker script must also tell the MPLINK linker about the ROM and RAM memory regions available in the target PIC1X MCU device. This means that you may instruct the linker. if not specified. The MPLINK linker also provides flexibility for specifying that certain blocks of data memory are reusable. Any function in the various input modules that attempts to access data or call a routine that has not been allocated or created will cause the linker to generate an error. The actual addresses of data and the location of functions will be assigned when the MPLINK linker is executed. .lst) Debug file used by MPLAB IDE v6. Finally the linker calls the MP2HEX utility to generate the executable output. Description of memory layout for a particular processor/project. Input Files Object File (. so that different routines (which never call each other and which don't depend upon this data to be retained between execution) can share limited RAM space.Generated by Foxit PDF Creator © Foxit Software http://www. side-by-side with final binary code. When using a C compiler.cof.out) Hex File Formats (. DS33014K-page 173 . to place into any available memory. A list file (ò´­¬) can also be generated by calling the MP2COD utility. Suitable for use in programming. Map File (. A collection of object files grouped together for convenience. Then. to place code and data somewhere within named regions of memory. Hexidecimal file with no debug information.hxl. Shows the memory layout after linking. The linker will only extract and link individual object files that are needed for the current application from the included libraries.lib) Linker Script File (. This file is generated by the utility MP2HEX. Indicates used and unused memory regions.7 LINKER INPUT/OUTPUT FILES The MPLINK linker combines multiple object files into one executable hex file. The MPLINK linker combines all input files and ensure that all addresses are resolved.com For evaluation only. MPLINK Linker Overview The linker is executed after assembling or compiling relocatable object modules with the MPASM assembler and/or MPLAB C18 C compiler. Note: Requires linker can find original source files. Original source code.hxh) Listing File (. This file is generated by the utility MP2COD. The MPLINK linker also generates symbolic information for debugging your application with MPLAB IDE (ò½±º and ò³¿° files).lkr) Relocatable code produced from a source file.o) Library File (. This means that relatively large libraries can be used in a highly efficient manner. libraries are available for most PIC MCU peripheral functions as well as for many standard C functions.xx and later. via a linker script. Output Files COFF Object Module File (. .foxitsoftware. it can analyze all the input files and try to fit the application's routines into ROM and assign its data variables into available RAM. .

lst) An MPLINK linker listing file provides a mapping of source code to object code.hxl. ³°î¸»¨ò»¨» uses the COF file to generate the hex file.3 “Listing File (. see Section 1. A library file may be created from object files by MPLIB librarian.5 “Hex File Formats (. 2. “Linker Scripts”.lst)” from the “Files of type” drop-down list locating the desired list file clicking on the list file name clicking Open Both the MPASM assembler and the MPLINK linker can generate listing files. use the ñ¨ option. see Chapter 15. The MPLINK linker combines object files and library files. selecting File>Open to launch the Open dialog selecting “List files (*. The MPLINK linker uses the ³°î½±¼ò»¨» utility to generate the linker list file from the COF file. use the ñ© option.o) Object files are the relocatable code produced from source files.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only.7. into a single output file.7. It also provides a list of symbol values. the object file containing that definition will be included in the link. warnings and messages generated. DS33014K-page 174 2009 Microchip Technology Inc. “MPLIB Librarian Overview”.6 Listing File (.foxitsoftware. To prevent linker list file generation.3 Linker Script File (. Object files may be created from source files by MPASM assembler and library files may be created from object files by MPLIB librarian. 4.7.xx or later. .lst)”. .7. . see Chapter 11. 3.hxh)”.5 Hex File Formats (.http://www. 9. . For MPLINK linker.hxh) Both the MPASM assembler and the MPLINK linker can generate a hex file. To prevent hex file generation.7. For more information on linker scripts. For information on the MPASM assembler listing file. . it will search libraries specified on the command line or in the linker script in an attempt to resolve the reference. Standard linker script files are located in: ÝæÄЮ±¹®¿³ Ú·´»­ÄÓ·½®±½¸·°ÄÓÐßÍÓ Í«·¬»ÄÔÕÎ During the link process.4 COFF Object Module File (.out) MPLINK linker generates a COFF file which provides debugging information to MPLAB IDE v6. . if MPLINK linker is unable to resolve a reference to a symbol.hxl. see Section 1.cof. and the number of errors. For more on the librarian. according to a linker script. 9. An alternative to a listing file would be to use the information in the Disassembly window (View>Disassembly) in MPLAB IDE. 9. 9. 5. memory usage information. For more information on this format. 9.hex.lkr) Linker script files are the command files of MPLINK linker.7. If a definition is found in a library file.1 Object File (.2 Library File (. This file may be viewed in MPLAB IDE by: 1. 9.lib) Libraries are a convenient way of grouping related object modules.7.hex.7.

” Also.foxitsoftware. associated file names have been replaced by numbers. The first column contains the base address in memory where the code will be placed.. This is the code that will be executed by the PIC MCU. (1) and (2). The fourth column lists the associated source code line. The third column displays disassembly code.com For evaluation only. MPLINK Linker Overview EXAMPLE 9-1: MPLINK LINKER LISTING FILE The MP2COD utility version and list file generation data appear at the top of each page.. The second column is reserved for the machine instruction. indicated by “. ÓÐîÝÑÜ íòèðòðíô ÝÑÚÚ ¬± ÝÑÜ Ú·´» ݱ²ª»®¬»® ݱ°§®·¹¸¬ ø½÷ îððì Ó·½®±½¸·° Ì»½¸²±´±¹§ ײ½ò Ô·­¬·²¹ Ú·´» Ù»²»®¿¬»¼æ Ì«» Ò±ª ðî ïìæííæîí îððì ß¼¼®»­­ óóóóóóó Ê¿´«» óóóóó Ü·­¿­­»³¾´§ óóóóóóóóóóóóóóóóóóó ͱ«®½» óóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóó ý·²½´«¼» °ïèºìëîò·²½ Ô×ÍÌ å ÐïèÚìëîò×ÒÝ Í¬¿²¼¿®¼ Ø»¿¼»® Ú·´»ôòòò Ô×ÍÌ «¼¿¬¿ Ü»­¬ ®»­ ï ÎÍÌ ½±¼» ¹±¬± ð¨ð ͬ¿®¬ ðððððð ðððððî »ºïê ºððð ÙÑÌÑ ð¨î½ Ú·´» óóóó øï÷ øî÷ øî÷ øî÷ øï÷ øï÷ øï÷ øï÷ øï÷ øï÷ øï÷ øï÷ øï÷ øï÷ øï÷ øï÷ ððððî½ ððððî» ððððíð ððððíî ððððíì ð»ð¿ êºèð çéè𠻺ïê ºððð ÓÑÊÔÉ ÓÑÊÉÚ ÞÝÚ ÙÑÌÑ ð¨¿ ð¨èðôð¨ï ð¨èðôð¨íôð¨ï ð¨î½ ÐÙÓ ½±¼» ͬ¿®¬ ³±ª´© ³±ª©º ¾½º ¹±¬± »²¼ ð¨ðß Ü»­¬ Ü»­¬ô í ͬ¿®¬ where: øï÷ ã ÜæÄЮ±¶»½¬­íîÄÐ×ÝïèÚìëîÄͱ«®½»Î»´±½ò¿­³ øî÷ ã ÝæÄЮ±¹®¿³ Ú·´»­ÄÓ·½®±½¸·°ÄÓÐßÍÓ Í«·¬»Ä°ïèºìëîò·²½ 2009 Microchip Technology Inc. some comments have been shortened. DS33014K-page 175 .Generated by Foxit PDF Creator © Foxit Software http://www. The fifth column lists the file associated for the source code line. Note: Due to page width restrictions. i. See the end of the listing of the actual file paths and names.e.

and its size in bytes. indicating used/unused memory. The following table is an example of the symbol table sorted by symbol name in a map file: ͧ³¾±´­ ó Ò¿³» óóóóóóó ½¿´´Á³ ´±±° ³¿·² ³°§ ­¬¿®¬ ØÁ¾§¬» ÔÁ¾§¬» ½±«²¬ ³«´½²¼ ³«´°´® ͱ®¬»¼ ¾§ Ò¿³» ß¼¼®»­­ Ô±½¿¬·±² óóóóóóóó óóóóóóóó ð¨ððððîê °®±¹®¿³ ð¨ððððî» °®±¹®¿³ ð¨ððððîì °®±¹®¿³ ð¨ððððîè °®±¹®¿³ ð¨ððððîí °®±¹®¿³ ð¨ððððîî ¼¿¬¿ ð¨ððððîí ¼¿¬¿ ð¨ððððîì ¼¿¬¿ ð¨ððððî𠼿¬¿ ð¨ððððîï ¼¿¬¿ ͬ±®¿¹» óóóóóóóó ­¬¿¬·½ ­¬¿¬·½ ­¬¿¬·½ »¨¬»®² ­¬¿¬·½ »¨¬»®² »¨¬»®² ­¬¿¬·½ »¨¬»®² »¨¬»®² Ú·´» óóóóóóóóó ÝæÄÐÎÑÙÎߢïÄÓÐÔßÞÄßÍÓÚÑÑÄ­¿³°±¾¶ò¿­³ ÝæÄÓÐßÍÓ ¿­­»³¾´»®ÊîÄÓËÔèÈèòßÍÓ ÝæÄÐÎÑÙÎߢïÄÓÐÔßÞÄßÍÓÚÑÑÄ­¿³°±¾¶ò¿­³ ÝæÄÓÐßÍÓ ¿­­»³¾´»®ÊîÄÓËÔèÈèòßÍÓ ÝæÄÐÎÑÙÎߢïÄÓÐÔßÞÄßÍÓÚÑÑÄ­¿³°±¾¶ò¿­³ ÝæÄÓÐßÍÓ ¿­­»³¾´»®ÊîÄÓËÔèÈèòßÍÓ ÝæÄÓÐßÍÓ ¿­­»³¾´»®ÊîÄÓËÔèÈèòßÍÓ ÝæÄÓÐßÍÓ ¿­­»³¾´»®ÊîÄÓËÔèÈèòßÍÓ ÝæÄÓÐßÍÓ ¿­­»³¾´»®ÊîÄÓËÔèÈèòßÍÓ ÝæÄÓÐßÍÓ ¿­­»³¾´»®ÊîÄÓËÔèÈèòßÍÓ DS33014K-page 176 2009 Microchip Technology Inc. It also provides information on memory use. whether the symbol resides in program or data memory. 9. This window is automatically reloaded after each rebuild. It provides information on the absolute location of source code symbols in the final output. whether the section resides in program or data memory. For example: Ю±¹®¿³ Ó»³±®§ Ë­¿¹» ͬ¿®¬ Û²¼ óóóóóóóóó óóóóóóóóó ð¨ðððððð ð¨ðððððë ð¨ððððî¿ ð¨ððððî¾ ð¨ðððð¾½ ð¨ððïïéì ð¨ððïïéê ð¨ððîèçë ïðîðç ±«¬ ±º íîéèê °®±¹®¿³ ¿¼¼®»­­»­ «­»¼ô °®±¹®¿³ ³»³±®§ «¬·´·¦¿¬·±² ·­ íïû The third table in the map file (Symbols .http://www.foxitsoftware.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. The information includes the name of the section.Sorted by Name) provides information about the symbols in the output module.map) The map file generated by MPLINK linker can be viewed by selecting File>Open in MPLAB IDE and choosing the file you specified in the MPLINK linker options. whether the symbol has external or static linkage. beginning address.7. . The map file contains four tables. There are four types of sections: • • • • code initialized data (idata) uninitialized data (udata) initialized ROM data (romdata) Í»½¬·±² ײº± ß¼¼®»­­ óóóóóóóóó ð¨ðððððð ð¨ððððîï ð¨ððððîí ð¨ððððîð The following table is an example of the section table in a map file: Í»½¬·±² óóóóóóóóó λ­»¬ ò½·²·¬ ò½±¼» ò«¼¿¬¿ ̧°» óóóóóóóóó ½±¼» ®±³¼¿¬¿ ½±¼» «¼¿¬¿ Ô±½¿¬·±² óóóóóóóóó °®±¹®¿³ °®±¹®¿³ °®±¹®¿³ ¼¿¬¿ Í·¦»øÞ§¬»­÷ óóóóóóóóó ð¨ðððððî ð¨ðððððì ð¨ððððîê ð¨ðððððë The second table (Program Memory Usage) lists program memory addresses that were used and provides a total usage statistic. its type.7 Map File (. The table is sorted by the symbol name and includes the address of the symbol. and the name of the file where defined. The first table (Section Info) displays information about each section.

no symbol information is provided.Generated by Foxit PDF Creator © Foxit Software http://www. should provide enough context to determine why a section could not be allocated. 2009 Microchip Technology Inc. The error map file lists all sections that were successfully allocated when the error occurred. However. MPLINK Linker Overview The fourth table in the map file (Symbols . in conjunction with the error message. but it is sorted by symbol address rather than symbol name. This file. if the ñ³ option was supplied. If a linker error is generated.foxitsoftware. DS33014K-page 177 .Sorted by Address) provides the same information that the third table provides. a complete map file can not be created. an error map file will be created. The error map file contains only section information.com For evaluation only.

.http://www.com Assembler/Linker/Librarian User’s Guide NOTES: Generated by Foxit PDF Creator © Foxit Software For evaluation only. DS33014K-page 178 2009 Microchip Technology Inc.foxitsoftware.

com For evaluation only.Generated by Foxit PDF Creator © Foxit Software http://www.2 MPLAB IDE INTERFACE The MPLINK linker is commonly used with the MPASM assembler in an MPLAB IDE project to generate relocatable code.3 COMMAND LINE INTERFACE MPLINK linker can be used in MPLAB IDE or directly from a command line. The linker will search the ´µ® directory to find the generic linker script for that part. °¿®¬²«³¾»® indicates the part number for the PIC MCU’s generic linker script to build the project. When used in MPLAB IDE. When using MPLINK linker in a batch file. All object files must have the extension ò±. The linker may also be used in MPLAB IDE with the MPLAB C18 C compiler. For more information on this use. the linker is invoked with the following two syntaxes: ³°´·²µ ³°´·²µ ½³¼º·´»­ ±¾¶º·´»­ Å´·¾º·´»­Ã ű°¬·±²­Ã ñ°°¿®¬²«³¾»® ±¾¶º·´»­ Å´·¾º·´»­Ã ű°¬·±²­Ã ½³¼º·´» is the name of a linker command file. ASSEMBLER/LINKER/LIBRARIAN USER’S GUIDE Chapter 10.foxitsoftware. ´·¾º·´» is the name of a librarian-created library file. the generic linker script for PIC18F4520 is ïèºìëîðÁ¹ò´µ®. 2009 Microchip Technology Inc. see the MPLAB C18 C compiler documentation listed in Recommended Reading. For more information on Microchip compilers. For example. see “PIC1X MCU Language Tools and MPLAB IDE”. When MPLAB IDE or MPLAB C18 is installed. All linker command files must have the extension ò´µ®. The ´µ® directory is located at the same location as the MPLINK linker executable. The linker will construct the name of the generic linker script by adding an ‘Á¹ò´µ®’ to the string value of the part number. All library files must have the extension ò´·¾. or directly from the command line. ±¾¶º·´» is the name of an assembler or compiler generated object file. all of MPLINK linker's options are available through the MPLINK Linker tab.1 INTRODUCTION MPLINK object linker usage is discussed. the MPLINK linker (³°´·²µò»¨») is also installed. DS33014K-page 179 . 10. Topics covered in this chapter: • MPLAB IDE Interface • Command Line Interface • Command Line Example 10. accessed from the Project>Build Options dialog. Linker Interfaces 10.

Add directories to library search path. Suppress the ³°î½±¼ò»¨» utility. If a ª¿´«» is not provided. º«²½¬ò±. ³°´·²µ ïèºìëîò´µ® ³¿·²ò± º«²½¬ò± ³¿¬¸ò´·¾ ñ³ ³¿·²ò³¿° ñ± ³¿·²ò±«¬ This instructs MPLINK linker to use the ïèºìëîò´µ® linker script file to link the input modules ³¿·²ò±. Specify output file º·´»²¿³». changing the order can affect the operation of the linker. Quiet mode. and the precompiled library ³¿¬¸ò´·¾. Also generated is an Intel format hex file for programming. Specifically. Library and object files are searched for in the order in which directories occur in the ´·¾®¿®§ñ±¾¶»½¬ directory search path. The output files ³¿·²ò½±º and ³¿·²ò¸»¨ will be produced if no errors occur during the link process. Default is ¿ò±«¬. additions to the ´·¾®¿®§ñ±¾¶»½¬ directory search path are appended to the end of the current ´·¾®¿®§ñ±¾¶»½¬ directory search path as they are encountered on the command line and in command files. ñ© ñ¨ There is no required order for the command line arguments. Description Specify format of hex output file. It also instructs the linker to produce a map file named ³¿·²ò³¿°. however. ±°¬·±² is one of the linker command-line options described below.4 COMMAND LINE EXAMPLE An example of an MPLINK linker command line is shown below. Therefore. Using this option will prevent the generation of a ò´­¬ file. 0 will be used. Specify number of lines per listing page.foxitsoftware.http://www. Suppress the ³°î¸»¨ò»¨» utility. Specify multiple macros using following syntax: ñ« ä­§³Å㪿´«»Ãâ where ­§³ may be a macro with alphanumeric characters and ª¿´«» maybe be a numerical value. ³¿·²ò± and º«²½¬ò± must have been previously compiled or assembled. If the ñ± option is not supplied. . Create map file º·´»²¿³». DS33014K-page 180 2009 Microchip Technology Inc. Option ñ¿ ¸»¨º±®³¿¬ ñ¸ô ñá ñµ °¿¬¸´·­¬ ñ´ °¿¬¸´·­¬ ñ³ º·´»²¿³» ñ² ´»²¹¬¸ ñ± º·´»²¿³» ñ¯ ñ« Display help screen.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. changing the order of directories may change which file is selected. The ñ± option is used to supply the name of the generated output COFF file for MPLAB IDE debugging. Add directories to linker script search path. This file has the same name as the output COFF file but with the file extension ò¸»¨. 10. the default output COFF file is named ¿ò±«¬ and the corresponding hex file is named ¿ò¸»¨. Using this option will prevent the generation of a ò¸»¨ file.

Each of these directives.4) or to select the Build Configuration as “Debug” in MPLAB IDE.8. You no longer need to add a device-specific linker script file to the command line or your MPLAB IDE project. However. you will have to add that manually. any text between a '//' and the end of a line is ignored. There are four basic categories of linker script directives. Depending on the hardware debug tool you want to use. The standard linker scripts contain conditional linker statements and MPLAB IDE uses the ñ« command line flag to utilize these statements for different builds such as debug or no debug. by default.Generated by Foxit PDF Creator © Foxit Software http://www. Linker script files are the command files of the linker.2 STANDARD LINKER SCRIPTS Standard linker script files are provided for each device and are located.foxitsoftware. DS33014K-page 181 .e. in the directory: ÝæÄЮ±¹®¿³ Ú·´»­ÄÓ·½®±½¸·°ÄÓÐßÍÓ Í«·¬»ÄÔÕÎ. You can modify a local copy of the standard linker script and use it in your project. 2009 Microchip Technology Inc. Topics covered in this chapter: • • • • • • • Standard Linker Scripts Linker Script Command Line Information Linker Script Caveats Memory Region Definition Logical Section Definition STACK Definition Conditional Linker Statements 11. i. For example. Note: Linker script comments are specified by '//'. Linker Scripts 11. Standard linker scripts are named with the following convention °¿®¬²«³¾»®Á¹ò´µ®. are discussed in the topics listed below. if you want to use a non-standard linker script file. plus some useful linker script caveats.1 INTRODUCTION Linker script files are used by the linker to generate application code.. the standard linker script for PIC16F872 is ïêÚèéîÁ¹ò´µ®.com For evaluation only. They specify: • Program and data memory regions for the target part • Stack size and location (for MPLAB C18) • A mapping of logical sections in source code into program and data regions Linker script directives form the command language that controls the linker's behavior. you may need to set certain conditional symbols on the command line (see Example 11. the linker will find the appropriate file for you as long as a device has been specified. ASSEMBLER/LINKER/LIBRARIAN USER’S GUIDE Chapter 11.

3.3 FILES The following directive specifies object or library files for linking: Ú×ÔÛÍ ±¾¶º·´»ñ´·¾º·´» ű¾¶º·´»ñ´·¾º·´»òòòà where ±¾¶º·´»ñ´·¾º·´» is either an object or library file. the following line should be added to the linker command file: Ú×ÔÛÍ ³¿·²ò± ³¿¬¸ò´·¾ DS33014K-page 182 2009 Microchip Technology Inc. EXAMPLE 11-1: LIBPATH EXAMPLE To append the current directory and the directory ÝæÄÐÎÑÖÛÝÌÍÄ×ÒÝÔËÜÛ to the ´·¾®¿®§ñ±¾¶»½¬ search path.foxitsoftware.3 LINKER SCRIPT COMMAND LINE INFORMATION The MPLAB IDE Project Manager can set this information directly. the following line should be added to the linker command file: Ô×ÞÐßÌØ òåÝæÄÐÎÑÖÛÝÌÍÄ×ÒÝÔËÜÛ 11. the following line should be added to the linker command file: ÔÕÎÐßÌØ òòåÝæÄÐÎÑÖÛÝÌÍÄÍÝÎ×ÐÌÍ 11.3.3.http://www.1 LIBPATH Library and object files which do not have a path are searched using the ´·¾®¿®§ñ±¾¶»½¬ search path. You probably only need to use these if you are linking from the command line. FILES EXAMPLE EXAMPLE 11-3: To specify that the object module ³¿·²ò± be linked with the library file ³¿¬¸ò´·¾. 11.2 LKRPATH Linker command files that are included using a linker script INCLUDE directive are searched for using the linker command file search path.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. • • • • LIBPATH LKRPATH FILES INCLUDE 11. . The following directive appends additional search directories to the linker command file search path: ÔÕÎÐßÌØ ´µ®°¿¬¸ where ´µ®°¿¬¸ is a semicolon-delimited list of directories. EXAMPLE 11-2: LKRPATH EXAMPLE To append the current directory's parent and the directory ÝæÄÐÎÑÖÛÝÌÍÄÍÝÎ×ÐÌÍ to the linker command file search path. The following directive appends additional search directories to the ´·¾®¿®§ñ±¾¶»½¬ search path: Ô×ÞÐßÌØ ´·¾°¿¬¸ where ´·¾°¿¬¸ is a semicolon-delimited list of directories. Note: More than one object or library file can be specified in a single Ú×ÔÛÍ directive.

4 LINKER SCRIPT CAVEATS Some linker script caveats: • You may need to modify the linker script files included with MPLINK linker before using them.) • You must not combine data memory regions when using MPLINK linker with MPLAB C18 C compiler. The optional keyword ÐÎÑÌÛÝÌÛÜ indicates a region of memory that only can be used when specifically identified in the source code. Regions that are marked ÐÎÑÌÛÝÌÛÜ will not be used for general allocation of program or data.5. 0xFF) number specifying an address. ¿¼¼® is a decimal (e.foxitsoftware. The linker will not use the protected area. DS33014K-page 183 . EXAMPLE 11-4: INCLUDE EXAMPLE To include the linker command file named ³§´·²µò´µ®.4 INCLUDE The following directive includes an additional linker command file: ×ÒÝÔËÜÛ ½³¼º·´» where ½³¼º·´» is the name of the linker command file to include. 2009 Microchip Technology Inc. ÍØßÎÛÞßÒÕ and ßÝÝÛÍÍÞßÒÕ directives are used for variable data in internal RAM. MPLAB C18 requires that any section be located within a single bank.Generated by Foxit PDF Creator © Foxit Software http://www. .com For evaluation only. the following line should be added to the linker command file: ×ÒÝÔËÜÛ ³§´·²µò´µ® 11. 11.1 Defining RAM Memory Regions The ÜßÌßÞßÒÕ. or if the section is assigned to the region using a ÍÛÝÌ×ÑÒ directive in the linker script file. 11.5 MEMORY REGION DEFINITION The linker script describes the memory architecture of the PIC1X MCU.g. • You may wish to reconfigure stack size to use MPLAB C18 with MPLINK linker. See MPLAB C18 documentation for directions on creating variables larger then a single bank. Banked Registers ÜßÌßÞßÒÕ ÒßÓÛã³»³Ò¿³» ÍÌßÎÌ㿼¼® ÛÒÜ㿼¼® ÅÐÎÑÌÛÝÌÛÜà Unbanked Registers ÍØßÎÛÞßÒÕ ÒßÓÛã³»³Ò¿³» ÍÌßÎÌ㿼¼® ÛÒÜ㿼¼® ÅÐÎÑÌÛÝÌÛÜà Access Registers (PIC18 devices only) ßÝÝÛÍÍÞßÒÕ ÒßÓÛã³»³Ò¿³» ÍÌßÎÌ㿼¼® ÛÒÜ㿼¼® ÅÐÎÑÌÛÝÌÛÜà where: ³»³Ò¿³» is any ASCII string used to identify an area in RAM... • You will need to split up memory pages if your code contains ¹±¬± or ½¿´´ instructions without °¿¹»­»´ pseudo-instructions (directives. Linker Scripts 11. This allows the linker to place code in available ROM space and variables in available RAM space.3. Code or data will only be allocated into these regions if an absolute address is specified for the section. The formats for these directives are as follows.g.30) or hexadecimal (e.

Banked Memory ññÍ°»½·¿´ Ú«²½¬·±² λ¹·­¬»®­ ·² Þ¿²µ­ ðóí ÜßÌßÞßÒÕ ÒßÓÛã­º®ð ÍÌßÎÌãð¨ð ÛÒÜãð¨ïÚ ÜßÌßÞßÒÕ ÒßÓÛã­º®ï ÍÌßÎÌãð¨èð ÛÒÜãð¨çÚ ÜßÌßÞßÒÕ ÒßÓÛã­º®î ÍÌßÎÌãð¨ïðð ÛÒÜãð¨ïðÚ ÜßÌßÞßÒÕ ÒßÓÛã­º®í ÍÌßÎÌãð¨ïèð ÛÒÜãð¨ïèÚ ññÙ»²»®¿´ Ы®°±­» ÎßÓ ·² Þ¿²µ­ ðóí ÜßÌßÞßÒÕ ÒßÓÛã¹°®ð ÍÌßÎÌãð¨îð ÛÒÜãð¨êÚ ÜßÌßÞßÒÕ ÒßÓÛã¹°®ï ÍÌßÎÌãð¨ßð ÛÒÜãð¨ÛÚ ÜßÌßÞßÒÕ ÒßÓÛã¹°®î ÍÌßÎÌãð¨ïïð ÛÒÜãð¨ïêÚ ÜßÌßÞßÒÕ ÒßÓÛã¹°®í ÍÌßÎÌãð¨ïçð ÛÒÜãð¨ïÛÚ ÐÎÑÌÛÝÌÛÜ ÐÎÑÌÛÝÌÛÜ ÐÎÑÌÛÝÌÛÜ ÐÎÑÌÛÝÌÛÜ RAM Memory Declarations for PIC16F877A .foxitsoftware. the ÜßÌßÞßÒÕ and ÍØßÎÛÞßÒÕ entries in the linker script file would appear as shown in the examples below the map. . Based on the RAM memory layout shown in PIC16F877A Register File Map.http://www.com Assembler/Linker/Librarian User’s Guide EXAMPLE 11-5: RAM EXAMPLE Generated by Foxit PDF Creator © Foxit Software For evaluation only. PIC16F877A Register File Map Address 00h 01h 02h 03h 04h 05h : 0Fh 10h : 1Fh 20h : 6Fh 70h : 7Fh General Purpose RAM (Unbanked) General Purpose RAM (Banked) General Purpose RAM (Banked) Bank 0 INDF0 TMR0 PCL STATUS FSR PORTA : TMR1H T1CON : ADCON0 Bank 1 INDF0 OPTION_REG PCL STATUS FSR TRISA : — — : ADCON1 General Purpose RAM (Banked) General Purpose RAM (Banked) Bank 2 INDF0 TMR0 PCL STATUS FSR — : EEADRH Bank 3 INDF0 OPTION_REG PCL STATUS FSR — : — RAM Memory Declarations for PIC16F877A .Unbanked Memory ññÙ»²»®¿´ Ы®°±­» ÎßÓ ó ¿ª¿·´¿¾´» ·² ¿´´ ¾¿²µ­ ÍØßÎÛÞßÒÕ ÒßÓÛã¹°®²±¾²µ ÍÌßÎÌãð¨éð ÛÒÜãð¨éÚ ÍØßÎÛÞßÒÕ ÒßÓÛã¹°®²±¾²µ ÍÌßÎÌãð¨Úð ÛÒÜãð¨ÚÚ ÍØßÎÛÞßÒÕ ÒßÓÛã¹°®²±¾²µ ÍÌßÎÌãð¨ïéð ÛÒÜãð¨ïéÚ ÍØßÎÛÞßÒÕ ÒßÓÛã¹°®²±¾²µ ÍÌßÎÌãð¨ïÚð ÛÒÜãð¨ïÚÚ DS33014K-page 184 2009 Microchip Technology Inc.

21FFh Address Based on this map. it may be any length divisible by full words (16 bits). initialized data values.5. ¿¼¼® is a decimal or hexadecimal number specifying an address.0FFFh 1000h .2003h 2004h . If it is in hexadecimal notation (e.20FFh 2100h .1FFFh 2000h . º·´´Ê¿´«» is a value which fills any unused portion of a memory block. It has the following format: ÝÑÜÛÐßÙÛ ÒßÓÛã³»³Ò¿³» ÍÌßÎÌ㿼¼® ÛÒÜ㿼¼® ÅÐÎÑÌÛÝÌÛÜà ÅÚ×ÔÔ㺷´´ª¿´«»Ã where: ³»³Ò¿³» is any ASCII string used to identify a CODEPAGE.07FFh 0800h . EXAMPLE 11-6: ROM EXAMPLE The program memory layout for a PIC16F877A microcontroller is shown below.Generated by Foxit PDF Creator © Foxit Software http://www.2 Defining ROM Memory Regions The ÝÑÜÛÐßÙÛ directive is used for program code.2005h 2006h 2007h 2008h . DS33014K-page 185 .17FFh 1800h . Linker Scripts 11. Memory Reset Vector Interrupt Vector User Memory Space User Memory Space User Memory Space User Memory Space ID Locations Reserved Device ID Configuration Memory Space Reserved EEPROM Data Start: 0000h Start: 0004h 0005h .foxitsoftware. If this value is in decimal notation. The optional keyword ÐÎÑÌÛÝÌÛÜ indicates a region of memory that only can be used by program code that specifically requests it. 0x2346)..com For evaluation only. constant data values and external memory.g. the CODEPAGE declarations are: ÝÑÜÛÐßÙÛ ÝÑÜÛÐßÙÛ ÝÑÜÛÐßÙÛ ÝÑÜÛÐßÙÛ ÝÑÜÛÐßÙÛ ÝÑÜÛÐßÙÛ ÝÑÜÛÐßÙÛ ÒßÓÛã°¿¹»ð ÒßÓÛã°¿¹»ï ÒßÓÛã°¿¹»î ÒßÓÛã°¿¹»í ÒßÓÛãò·¼´±½­ ÒßÓÛãò½±²º·¹ ÒßÓÛã»»¼¿¬¿ ÍÌßÎÌãð¨ðððð ÍÌßÎÌãð¨ðèðð ÍÌßÎÌãð¨ïððð ÍÌßÎÌãð¨ïèðð ÍÌßÎÌãð¨îððð ÍÌßÎÌãð¨îððé ÍÌßÎÌãð¨îïðð ÛÒÜãð¨ðéÚÚ ÛÒÜãð¨ðÚÚÚ ÛÒÜãð¨ïéÚÚ ÛÒÜãð¨ïÚÚÚ ÛÒÜãð¨îððí ÛÒÜãð¨îððé ÛÒÜãð¨îïÚÚ ÐÎÑÌÛÝÌÛÜ ÐÎÑÌÛÝÌÛÜ ÐÎÑÌÛÝÌÛÜ 2009 Microchip Technology Inc. it is assumed to be a 16-bit quantity.

use the following line prior to the desired source code: º·´¬»®Á½±»ºº­ ÝÑÜÛ 11. The following statement specifies the stack size and an optional DATABANK where the stack is to be allocated: ÍÌßÝÕ Í×ÆÛã¿´´±½Í·¦» ÅÎßÓã³»³Ò¿³»Ã where: ¿´´±½Í·¦» is the size in bytes of the stack and ³»³Ò¿³» is the name of a memory previously declared using a ßÝÝÛÍÍÞßÒÕ.. .http://www. ÜßÌßÞßÒÕ or ÍØßÎÛÞßÒÕ statement. the following line should be added to the linker command file: ÍÌßÝÕ Í×ÆÛãð¨îð ÎßÓã¹°®ð DS33014K-page 186 2009 Microchip Technology Inc. EXAMPLE 11-7: LOGICAL SECTION DEFINITION To specify that a section whose name is º·´¬»®Á½±»ºº­ be loaded into the region of program memory named ½±²­¬¿²¬­. or ÝÑÜÛÐßÙÛ. and either the block of program memory in ROM or the block of data memory in RAM which contains the section: ÍÛÝÌ×ÑÒ ÒßÓÛã­»½Ò¿³» ¥ ÎÑÓã³»³Ò¿³» ¤ ÎßÓã³»³Ò¿³» £ where: ­»½Ò¿³» is an ASCII string used to identify a section. the following line should be added to the linker command file: ÍÛÝÌ×ÑÒ ÒßÓÛ㺷´¬»®Á½±»ºº­ ÎÑÓã½±²­¬¿²¬­ EXAMPLE 11-8: LOGICAL SECTION USAGE To place MPASM source code into a section named º·´¬»®Á½±»ºº­. ÜßÌßÞßÒÕ. EXAMPLE 11-9: STACK EXAMPLE To set the stack size to be 0x20 in the RAM area previously defined by ¹°®ð.foxitsoftware. ³»³Ò¿³» is a previously defined ßÝÝÛÍÍÞßÒÕ. To use logical sections. define the section in the linker script file with the ÍÛÝÌ×ÑÒ directive and then reference that name in the source file using that language's built-in mechanism (e.7 STACK DEFINITION Only MPLAB C18 requires a software stack be set up.6 LOGICAL SECTION DEFINITION Logical sections are used to specify which of the defined memory regions should be used for a portion of source code.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. The ÎßÓ attribute must always refer to data memory previously defined with a ßÝÝÛÍÍÞßÒÕ. 11. The ÎÑÓ attribute must always refer to program memory previously defined using a ÝÑÜÛÐßÙÛ directive.g. ý°®¿¹³¿ ­»½¬·±² for MPLAB C18). ÜßÌßÞßÒÕ or ÍØßÎÛÞßÒÕ directive. The section directive defines a section by specifying its name. ÍØßÎÛÞßÒÕ.

The else clause will be parsed only in case that the if clause is not. 11. 2009 Microchip Technology Inc. 11.8 CONDITIONAL LINKER STATEMENTS Generic linker scripts contain conditional statements and macros to accommodate several different methods for linking code: • Debug vs.2 Macros Depending on what you want to do. If you are using MPLAB IDE..8. certain directives are useful with these conditional statements. Linker Scripts 11.1. macros may be set and used with conditional statements to determine how the linker script will be interpreted by the linker. Also. Several macros are used in support of the conditional statements. MPLINK linker accepts IF/ELSE type conditional statements in the linker scripts.g. See MPLAB IDE documentation for more on how to set the Build Configuration.3 #FI No macro is allowed after this directive.2 #ELSE No macro is allowed after this directive. 11.Generated by Foxit PDF Creator © Foxit Software http://www.1 #IFDEF Only one macro is allowed after this directive. all macros listed in Table 11-1 will automatically be set for you. The only exception is Debug vs. If the macro is defined before. as discussed below.com For evaluation only.8.1.8. Assembly • PIC18 Extended Microcontroller mode vs. Complex conditions must be constructed using nested if-else clauses. Release (e.1.1 IFDEF/ELSE/FI Two syntaxes are accepted for these conditional statements: Conditional 1 ý×ÚÜÛÚ ›ò ýÚ× Conditional 2 ý×ÚÜÛÚ ›ò ýÛÔÍÛ ›ò ýÚ× 11. Release. It identifies the end of if or else clause. Traditional mode Being able to use one linker script instead of several simplifies application development.8. 11.foxitsoftware. DS33014K-page 187 . which must be selected under the Build Configuration. for the MPLAB REAL ICE™ in-circuit emulator) • C code vs.8. the if clause will be parsed by the linker.

. The syntax of this directive is: ÛÎÎÑÎ ³­¹ This directive is used in the generic linker scripts to calculate the begin and end of the debug sections in code and data memory. DS33014K-page 188 2009 Microchip Technology Inc. as opposed to release.foxitsoftware. ñ«ÁÜÛÞËÙÝÑÜÛÔÛÒ㸻¨ª¿´«» 11.http://www. The macros that are available for you to set are listed below.3 Supporting Directives The #DEFINE directive may be used to define a macro or define it and set its value.. On the command line. i. ‘-’. TABLE 11-1: Macro _CRUNTIME _EXTENDEDMODE _DEBUG _DEBUGCODESTART _DEBUGCODELEN _DEBUGDATASTART _DEBUGDATALEN LINKER SCRIPT MACROS Use To link C code or mixed C code and assembly. See Section 11. or production.. The ERROR directive can be used within an if-else clause.3. The value can only be calculated using an ‘+’. i. The following syntaxes are accepted: ýÜÛÚ×ÒÛ ýÜÛÚ×ÒÛ ýÜÛÚ×ÒÛ ýÜÛÚ×ÒÛ ²»©³¿½®±³¿½®±ï ²»©³¿½®±³¿½®±ï ²»©³¿½®±³¿½®±ï ²»©³¿½®±³¿½®±ï õ ó ñ ö ³¿½®±î ³¿½®±î ³¿½®±î ³¿½®±î ²»©³¿½®± may not be a previously defined macro.2 ERROR An ÛÎÎÑÎ directive has been added to MPLINK linker.8.e. ‘/’ or ‘*’ operator over two previously defined macros. 11.e.1 #DEFINE Through this directive. mode.8. This directive allows you to stop the linker and emit the message in front of it on the standard output. The numerical values associated to these macros will be used to calculate a numerical value for ²»©³¿½®±ò 11.. precede the macro with ñ«. you must set the macros yourself.8. .8. ñ«ÁÜÛÞËÙÝÑÜÛÔÛÒ㸻¨ª¿´«» To set the start of data memory reserved registers. you can define an macro and associate a numerical value to it.4 “Examples of Use” for some examples. i. Complex calculations must be constructed using combination of multiple ýÜÛÚ×ÒÛ directives.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only.3.e.e. ³¿½®±ï and ³¿½®±î are previously defined macros. To use PIC18 extended microcontroller mode. If you are using the command line. ñ«ÁÜÛÞËÙÜßÌßÍÌßÎÌ㿼¼®»­­ To set the amount of data memory reserved. i. To set the start in program memory of the debug executive. ñ«ÁÜÛÞËÙÝÑÜÛÍÌßÎÌ㿼¼®»­­ To set the size of the debug executive. To specify debug mode.

1. Building a C project. Traditional (non-extended) mode: ³°´·²µò»¨» ñ°ïèÚêéîî ñ«ÁÝÎËÒÌ×ÓÛ ñ«ÁÜÛÞËÙ ñ«ÁÜÛÞËÙÝÑÜÛÍÌßÎÌãð¨ïº¼èð ñ«ÁÜÛÞËÙÝÑÜÛÔÛÒãð¨îèð ñ«ÁÜÛÞËÙÜßÌßÌßÎÌã𨻺ì ñ«ÁÜÛÞËÙÜßÌßÔÛÒã𨽠䱬¸»® º´¿¹­â 3.lkr ññ Ú·´»æ ïèºêéîîÁ¹ò´µ® ññ Ù»²»®·½ ´·²µ»® ­½®·°¬ º±® ¬¸» Ð×ÝïèÚêéîî °®±½»­­±® ýÜÛÚ×ÒÛ ýÜÛÚ×ÒÛ ýÜÛÚ×ÒÛ ýÜÛÚ×ÒÛ ÁÝÑÜÛÛÒÜ ÁÜÛÞËÙÝÑÜÛÍÌßÎÌ ó ï ÁÝÛÒÜ ÁÜÛÞËÙÝÑÜÛÍÌßÎÌ õ ÁÜÛÞËÙÝÑÜÛÔÛÒ ÁÜßÌßÛÒÜ ÁÜÛÞËÙÜßÌßÍÌßÎÌ ó ï ÁÜÛÒÜ ÁÜÛÞËÙÜßÌßÍÌßÎÌ õ ÁÜÛÞËÙÜßÌßÔÛÒ Ô×ÞÐßÌØ ò ý×ÚÜÛÚ ÁÝÎËÒÌ×ÓÛ ý×ÚÜÛÚ ÁÛÈÌÛÒÜÛÜÓÑÜÛ Ú×ÔÛÍ ½ðïè·Á»ò± Ú×ÔÛÍ ½´·¾Á»ò´·¾ Ú×ÔÛÍ °ïèºêéîîÁ»ò´·¾ ýÛÔÍÛ Ú×ÔÛÍ ½ðïè·ò± Ú×ÔÛÍ ½´·¾ò´·¾ Ú×ÔÛÍ °ïèºêéîîò´·¾ ýÚ× ýÚ× ý×ÚÜÛÚ ÁÜÛÞËÙÝÑÜÛÍÌßÎÌ ÝÑÜÛÐßÙÛ ÒßÓÛã°¿¹» ÝÑÜÛÐßÙÛ ÒßÓÛã¼»¾«¹ ýÛÔÍÛ ÝÑÜÛÐßÙÛ ÒßÓÛã°¿¹» ýÚ× ÝÑÜÛÐßÙÛ ÝÑÜÛÐßÙÛ ÝÑÜÛÐßÙÛ ÝÑÜÛÐßÙÛ ÒßÓÛã·¼´±½­ ÒßÓÛã½±²º·¹ ÒßÓÛã¼»ª·¼ ÒßÓÛã»»¼¿¬¿ ÍÌßÎÌãð¨ð ÍÌßÎÌãÁÜÛÞËÙÝÑÜÛÍÌßÎÌ ÍÌßÎÌãð¨ð ÛÒÜãÁÝÑÜÛÛÒÜ ÛÒÜãÁÝÛÒÜ ÛÒÜãð¨ïÚÚÚÚ ÍÌßÎÌãð¨îððððð ÍÌßÎÌãð¨íððððð ÍÌßÎÌãð¨íÚÚÚÚÛ ÍÌßÎÌãð¨Úððððð ÛÒÜãð¨îððððé ÛÒÜãð¨íððððÜ ÛÒÜãð¨íÚÚÚÚÚ ÛÒÜãð¨ÚððíÚÚ ÐÎÑÌÛÝÌÛÜ ÐÎÑÌÛÝÌÛÜ ÐÎÑÌÛÝÌÛÜ ÐÎÑÌÛÝÌÛÜ ý×ÚÜÛÚ ÁÛÈÌÛÒÜÛÜÓÑÜÛ ÜßÌßÞßÒÕ ÒßÓÛã¹°®» ýÛÔÍÛ ßÝÝÛÍÍÞßÒÕ ÒßÓÛ㿽½»­­®¿³ ýÚ× ÜßÌßÞßÒÕ ÒßÓÛã¹°®ð ÍÌßÎÌãð¨ð ÍÌßÎÌãð¨ð ÛÒÜãð¨ëÚ ÛÒÜãð¨ëÚ ÍÌßÎÌãð¨êð ÛÒÜãð¨ÚÚ 2009 Microchip Technology Inc.18f6722_g. Extended mode: ³°´·²µò»¨» ñ°ïèÚêéîî ñ«ÁÝÎËÒÌ×ÓÛ ñ«ÁÛÈÌÛÒÜÛÜÓÑÜÛ ä±¬¸»® º´¿¹­â 2.4 Examples of Use In these examples. DS33014K-page 189 .foxitsoftware. no debug: ³°´·²µò»¨» ñ°ïèºêéîî 䱬¸»® º´¿¹­â Generic Linker Script .Generated by Foxit PDF Creator © Foxit Software http://www.com For evaluation only. the generic linker script for PIC18F6722 is used to demonstrate how different options for building a project can be selected. Building a Assembly project. Linker Scripts 11.8. Building a C project for PIC18F6722 with debug sections for code at 0x1fd80 and for data at 0xef4.

http://www.com Assembler/Linker/Librarian User’s Guide ÜßÌßÞßÒÕ ÜßÌßÞßÒÕ ÜßÌßÞßÒÕ ÜßÌßÞßÒÕ ÜßÌßÞßÒÕ ÜßÌßÞßÒÕ ÜßÌßÞßÒÕ ÜßÌßÞßÒÕ ÜßÌßÞßÒÕ ÜßÌßÞßÒÕ ÜßÌßÞßÒÕ ÜßÌßÞßÒÕ ÜßÌßÞßÒÕ ÒßÓÛã¹°®ï ÒßÓÛã¹°®î ÒßÓÛã¹°®í ÒßÓÛã¹°®ì ÒßÓÛã¹°®ë ÒßÓÛã¹°®ê ÒßÓÛã¹°®é ÒßÓÛã¹°®è ÒßÓÛã¹°®ç ÒßÓÛã¹°®ïð ÒßÓÛã¹°®ïï ÒßÓÛã¹°®ïî ÒßÓÛã¹°®ïí ÍÌßÎÌãð¨ïðð ÍÌßÎÌãð¨îðð ÍÌßÎÌãð¨íðð ÍÌßÎÌãð¨ìðð ÍÌßÎÌãð¨ëðð ÍÌßÎÌãð¨êðð ÍÌßÎÌãð¨éðð ÍÌßÎÌãð¨èðð ÍÌßÎÌãð¨çðð ÍÌßÎÌãð¨ßðð ÍÌßÎÌãð¨Þðð ÍÌßÎÌãð¨Ýðð ÍÌßÎÌãð¨Üðð ÛÒÜãð¨ïÚÚ ÛÒÜãð¨îÚÚ ÛÒÜãð¨íÚÚ ÛÒÜãð¨ìÚÚ ÛÒÜãð¨ëÚÚ ÛÒÜãð¨êÚÚ ÛÒÜãð¨éÚÚ ÛÒÜãð¨èÚÚ ÛÒÜãð¨çÚÚ ÛÒÜãð¨ßÚÚ ÛÒÜãð¨ÞÚÚ ÛÒÜãð¨ÝÚÚ ÛÒÜãð¨ÜÚÚ Generated by Foxit PDF Creator © Foxit Software For evaluation only. . ý×ÚÜÛÚ ÁÜÛÞËÙÜßÌßÍÌßÎÌ ÜßÌßÞßÒÕ ÒßÓÛã¹°®ïì ÜßÌßÞßÒÕ ÒßÓÛã¼¾¹­°® ýÛÔÍÛ ññ²± ¼»¾«¹ ÜßÌßÞßÒÕ ÒßÓÛã¹°®ïì ýÚ× ÜßÌßÞßÒÕ ÒßÓÛã¹°®ïë ßÝÝÛÍÍÞßÒÕ ÒßÓÛ㿽½»­­­º® ÍÌßÎÌãð¨Ûðð ÍÌßÎÌãÁÜÛÞËÙÜßÌßÍÌßÎÌ ÍÌßÎÌãð¨Ûðð ÛÒÜãÁÜßÌßÛÒÜ ÛÒÜãÁÜÛÒÜ ÛÒÜãð¨ÛÚÚ ÐÎÑÌÛÝÌÛÜ ÍÌßÎÌãð¨Úðð ÍÌßÎÌãð¨Úêð ÛÒÜãð¨ÚëÚ ÛÒÜãð¨ÚÚÚ ÐÎÑÌÛÝÌÛÜ ý×ÚÜÛÚ ÁÝÎËÒÌ×ÓÛ ÍÛÝÌ×ÑÒ ÒßÓÛãÝÑÒÚ×Ù ÎÑÓã½±²º·¹ ý×ÚÜÛÚ ÁÜÛÞËÙÜßÌßÍÌßÎÌ ÍÌßÝÕ Í×ÆÛãð¨ïðð ÎßÓã¹°®ïí ýÛÔÍÛ ÍÌßÝÕ Í×ÆÛãð¨ïðð ÎßÓã¹°®ïì ýÚ× ýÚ× DS33014K-page 190 2009 Microchip Technology Inc.foxitsoftware.

an attempt is made to locate the corresponding symbol definition in the input library files. The linker combines like-named input sections into a single output section. The linker allocation algorithm is described in Section 12. After the linker has processed all relocation entries. the linker then proceeds to patch each section's raw data. an error is generated. The addresses of the relocatable symbols are patched into the raw data. 2009 Microchip Technology Inc.3 “Linker Allocation Algorithm”.4 “Relocation Example”. an error is generated. The symbols defined in each input section have addresses dependent upon the beginning of their sections. it resolves external symbols. Once the linker has allocated all sections from all input modules into target memory. The target memory architecture is described in a linker command file. After the linker has relocated the symbols defined in each input section.com For evaluation only. If the linker cannot find a block of target memory in which to allocate a section. The linker adjusts the symbol addresses based upon the ultimate location of their allocated sections.foxitsoftware. DS33014K-page 191 .2 LINKER PROCESSING OVERVIEW A linker combines multiple input object modules into a single executable output module. it generates the executable output module. If the corresponding symbol definition is not found. Each section contains a list of relocation entries which associate locations in a section's raw data with relocatable symbols. If the resolution of external symbols was successful. This linker command file provides a flexible mechanism for specifying blocks of target memory and for mapping sections to the specified memory blocks. Linker Processing 12. The input object modules may contain relocatable or absolute sections of code or data which the linker will allocate into target memory. The process of relocating symbols and patching section is described in Section 12. Topics covered in this chapter: • • • • • Linker Processing Overview Linker Allocation Algorithm Relocation Example Initialized Data Reserved Section Names 12.Generated by Foxit PDF Creator © Foxit Software http://www.1 INTRODUCTION Understanding how MPLINK linker processes files and information can be useful to keep in mind when writing and structuring your application code. If any external symbol references do not have a corresponding symbol definition. The linker attempts to match all external symbol references with a corresponding symbol definition. it begins the process of symbol relocation. ASSEMBLER/LINKER/LIBRARIAN USER’S GUIDE Chapter 12.

If no target memory block is assigned to an absolute section. the linker checks the assigned target memory block to verify that there is space available. Since absolute sections can only be allocated at a fixed address. The linker performs allocation of absolute (assigned and unassigned) sections first. then it gets allocated after the relocatable assigned sections and before the other relocatable unassigned sections are allocated. in target memory. 2. the target memory block has enough space and the absolute section does not overlap other sections. otherwise an error is generated. 12. 12. If the stack is unassigned. the linker allocates relocatable assigned sections. The linker command file may or may not assign the stack to a specific target memory block. The linker starts with the largest relocatable unassigned section and works its way down to the smallest relocatable unassigned section. After all relocatable assigned sections have been allocated. By starting with the largest section and choosing the smallest accommodating space.foxitsoftware.3. the linker tries to find the one for it.1 Absolute Allocation Absolute sections may be assigned to target memory blocks in the linker command file. An unassigned section is a section that has been left unassigned in this file. assigned and unassigned sections are performed in no particular order.3. an error is generated. But. it chooses the target memory block with the smallest available space that can accommodate the section.2 Relocatable Allocation Once all absolute sections have been allocated. relocatable assigned sections next. 3.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. The allocation of relocatable assigned sections occurs in the order in which they were specified in the linker command file. . For relocatable assigned sections.http://www. the linker can only verify that if there is an assigned target memory block for an absolute section. 12.3 LINKER ALLOCATION ALGORITHM The linker allocates memory areas to allow maximum control over the location of code and data.3. A relocatable section is a section that will be placed in memory based on the linker allocation algorithm. For each allocation. DS33014K-page 192 2009 Microchip Technology Inc.3 Stack Allocation The stack is not a section but gets allocated along with the sections. Absolute Assigned Absolute Unassigned Relocatable Assigned Relocatable Unassigned An absolute section is a section with a fixed (absolute) address that cannot be changed by the linker. If one can not be located. If the stack is assigned a target memory block. An assigned section is a section that has been assigned a target memory block in the linker command file. 4. since the absolute section's address is fixed. 12. There are four kinds of sections that the linker handles: 1. and relocatable unassigned sections last. it gets allocated just before the relocatable assigned sections are allocated. The linker also handles stack allocation. the linker increases the chances of being able to allocate all the relocatable unassigned sections. called “sections”. the linker allocates relocatable unassigned sections.

it creates a symbol table entry for the identifier ª¿®ï which has the following information: ͧ³¾±´Å·²¼»¨Ã ãâ ²¿³»ãª¿®ïô ª¿´«»ãðô ­»½¬·±²ãò¼¿¬¿ô ½´¿­­ã»¨¬»®² When the compiler processes source line 3.foxitsoftware. Once all identifier symbols have their final addresses assigned. The final assembly equivalent output for the above example would be: ð¨ððëð ÓÑÊÔÉ ð¨ÚÚ ð¨ððëï ÓÑÊÔÞ ð¨ï ð¨ððëî ÓÑÊÉÚ ð¨îë å п¬½¸»¼ ©·¬¸ ª¿®ïù­ ¾¿²µ å п¬½¸»¼ ©·¬¸ ª¿®ïù­ ±ºº­»¬ 2009 Microchip Technology Inc. the linker must patch all references to these symbols using the relocation entries. In the example above. Suppose the following source code fragment occurred in a file: ñö Ú·´»æ ®»ºò½ öñ ½¸¿® ª¿®ïå ª±·¼ ­»¬Ê¿®ïøª±·¼÷ ¥ ª¿®ï ã ð¨ÚÚå £ ñö Ô·²» ï öñ ñö Ô·²» î öñ ñö Ô·²» í öñ Suppose this compiles into the following assembly instructions: Note: This example deliberately ignores any code generated by MPLAB C18 to handle the function's entry and exit ð¨ðððð ÓÑÊÔÉ ð¨ÚÚ ð¨ðððï ÓÑÊÔÞ áá å Ò»»¼ ¬± °¿¬½¸ ©·¬¸ ª¿®ïù­ ¾¿²µ ð¨ðððî ÓÑÊÉÚ áá å Ò»»¼ ¬± °¿¬½¸ ©·¬¸ ª¿®ïù­ ±ºº­»¬ When the compiler processes source line 1. it generates two relocation entries in the code section for the identifier symbol ª¿®ï since its final address is unknown until link time. Linker Processing 12. the updated symbol might now be at location 0x125: ͧ³¾±´Å·²¼»¨Ã ãâ ²¿³»ãª¿®ïô ª¿´«»ãð¨ïîëô ­»½¬·±²ãò¼¿¬¿ô ½´¿­­ã»¨¬»®² If the code section above were relocated to begin at address 0x50. the final addresses are known.com For evaluation only. The relocation entries have the following information: λ´±½Å·²¼»¨Ã ãâ ¿¼¼®»­­ãð¨ðððï ­§³¾±´ãª¿®ï ¬§°»ã¾¿²µ λ´±½Å·²¼»¨Ã ãâ ¿¼¼®»­­ãð¨ðððî ­§³¾±´ãª¿®ï ¬§°»ã±ºº­»¬ Once the linker has placed every section into target memory. the updated relocation entries would now begin at location 0x51: λ´±½Å·²¼»¨Ã ãâ ¿¼¼®»­­ãð¨ððëï ­§³¾±´ãª¿®ï ¬§°»ã¾¿²µ λ´±½Å·²¼»¨Ã ãâ ¿¼¼®»­­ãð¨ððëî ­§³¾±´ãª¿®ï ¬§°»ã±ºº­»¬ The linker will step through the relocation entries and patch their corresponding sections.4 RELOCATION EXAMPLE The following example illustrates how the linker relocates sections. DS33014K-page 193 .Generated by Foxit PDF Creator © Foxit Software http://www.

Initialized data sections contain initial values (initializers) for the variables and constants defined within them. DS33014K-page 194 2009 Microchip Technology Inc. Please see the documentation for these tools to ensure that you do not use a reserved name for your own section. The ò½·²·¬ section contains a table with entries for each initialized data section. The linker will be unable to generate the application if there is a section naming conflict. The boot code accesses this table and copies the data from ROM to RAM. 12.5 INITIALIZED DATA MPLINK linker performs special processing for input sections with initialized data.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. the linker creates a section in program memory. The names of the initializer sections created by the linker are the same as the initialized data sections with a Á· appended. the linker creates a section named ò½·²·¬ in program memory. For example. 12.http://www. where in data memory the initialized data section begins. and how many bytes are in the initialized data section. The data is moved by initializing code (supplied with MPLAB C18 and MPASM assembler) to the proper RAM location(s) at start-up. Each entry is a triple which specifies where in program memory the initializer section begins. if an input object module contains an initialized data section named ò·¼¿¬¿Á³¿·²ò± the linker will create a section in program memory with the name ò·¼¿¬¿Á³¿·²ò±Á· which contains the data. For each initialized data section. In addition to creating initializer sections. .6 RESERVED SECTION NAMES Both the MPASM assembler and the MPLAB C18 C compiler have reserved names for certain types of sections.foxitsoftware. their data must be stored in nonvolatile program memory (ROM). Because the variables and constants within an initialized data section reside in RAM.

Sample Applications 13.How to find and use template files . • How to Build the Sample Applications • Sample Application 1 .com For evaluation only. The assembler and linker are automatically installed with MPLAB IDE. for some sample applications.2 HOW TO BUILD THE SAMPLE APPLICATIONS To build the sample applications. or may be acquired separately on the Microchip website or the C compiler CD-ROM.How to access external memories using C pointers 13. By default.How to place data tables in ROM memory . the MPLINK linker and.Templates and Linker Scripts .How to partition memory for a boot loader .1 INTRODUCTION You can learn the basics of how to use MPLINK linker from the four sample applications listed below. DS33014K-page 195 . the MPLAB C compiler for PIC18 MCUs (formerly MPLAB C18) installed on your PC. These sample applications can be used as templates for your own application. the tool executables are located as specified in the tables below.How to set configuration bits in C • Sample Application 3 – Using a Boot Loader . A free demo (student) version of the C compiler may be obtained on the Microchip website.How to create new linker script memory section .How to place program code in different memory regions .foxitsoftware. TABLE 13-1: Executables ASSEMBLY CODE EXECUTABLES AND PATHS Default Paths to Executables ³°¿­³©·²ò»¨» ³°´·²µò»¨» ÝæÄЮ±¹®¿³ Ú·´»­ÄÓ·½®±½¸·°ÄÓÐßÍÓ Í«·¬» ÝæÄЮ±¹®¿³ Ú·´»­ÄÓ·½®±½¸·°ÄÓÐßÍÓ Í«·¬» 2009 Microchip Technology Inc.How to declare external memory through ý°®¿¹³¿ ½±¼» directive .How to compile code that will be loaded into external RAM and executed • Sample Application 4 – Configuring External Memory . ASSEMBLER/LINKER/LIBRARIAN USER’S GUIDE Chapter 13.Generated by Foxit PDF Creator © Foxit Software http://www. The full C compiler must be purchased separately. you will need the MPASM assembler.When to modify the generic linker script file • Sample Application 2 – Placing Code and Setting Config Bits .

For C code applications or combined C code and assembly applications. Make sure the executable paths are correct. . The executable file Á³°´·²µò»¨» is not a stand-alone program. 13. 3. ­±«®½»îò¿­³ and (if customized) ­½®·°¬ò´µ®.. Select from the Build Configuration list (see below) whether you will be developing your application (Debug) or are ready to program it into a device (Release). .foxitsoftware. The sample applications should be built as relocatable code. Once the project is created. Use the Project Wizard under the Project menu to create a project.1 BUILDING APPLICATIONS To build an application with MPLAB IDE: 1.1 Using MPLAB IDE MPLAB IDE provides a GUI method of developing your code.2. Select Project>Build All to build the application.For MPLAB C compiler for PIC18 MCUs sample applications. select the “Microchip C18 Toolsuite” as the active toolsuite. Setting this control will set the value for the macro _DEBUG found in the linker script file. 4.Name the project and place it in its own folder.2.Select the device specified in the sample application. respectively. . Other macros in the linker script (e. 2. as per Table 13-1 or Table 13-2. .g.com Assembler/Linker/Librarian User’s Guide TABLE 13-2: Executables Generated by Foxit PDF Creator © Foxit Software For evaluation only.Click the MPLINK Linker tab and then click the “Generate map file” checkbox to select it. If the application fails to build.1. select the “Microchip MPASM Toolsuite” as the active toolsuite.Add the sample files to your project.http://www.g. select Project>Build Options>Project to open the Build Options for Project dialog. . e. check that the environment variables discussed in the next section were set correctly during tool installation. Use ³°´·²µò»¨» and not Á³°´·²µò»¨». where ݱ³°·´»®×²­¬¿´´¿¬·±²Ð¿¬¸ is the location where the C compiler is installed on your system. C CODE EXECUTABLES AND PATHS Default Paths to Executables ³½½ïèò»¨» ³°¿­³©·²ò»¨» ³°´·²µò»¨» Note: Ýæij½½ïèľ·² Ýæij½½ïèij°¿­³ Ýæij½½ïèľ·² Future C compiler versions may be located at: ÝæÄЮ±¹®¿³ Ú·´»­ÄÓ·½®±½¸·°ÄÓÐÔßÞ Ýïè. Note: 13. . . click the Directories tab and enter ݱ³°·´»®×²­¬¿´´¿¬·±²Ð¿¬¸Ä´·¾ under “Library Path”..For assembly applications. 5. If your project contains a single assembly file with no linker script file. you will be asked if you want to build “absolute” code or “relocatable” code. ­±«®½»ïò½. _CRUNTIME) are automatically set by MPLAB IDE. DS33014K-page 196 2009 Microchip Technology Inc.

2.Add the sample files to your project.Generated by Foxit PDF Creator © Foxit Software http://www. .e. Select “Debug“ from the Build Configuration list on the Project Manager toolbar. To build an application with MPLAB IDE: 1. select Project>Build Options>Project to open the Build Options for Project dialog. . ½ðïè·Á³±¼ò½. DS33014K-page 197 . C code mixed boot loader/application. Once the project is created. Make sure the executable paths are correct. 2. 4. . .com For evaluation only. consider Sample Application 3.foxitsoftware. 3. Sample Applications 13.Click the MPLINK Linker tab and then click the “Generate map file” checkbox to select it.2 EXAMPLE As an example.Select PIC18F8722 as the device. ³·¨»¼ò¿­³ and ³·¨»¼ò´µ®.1. 2009 Microchip Technology Inc. Select Project>Build All to build the application..View the Project window (View>Project) to see your project files. as per Table 13-2. . Use the Project Wizard under the Project menu to create a project. .Name the project and place it in its own folder.Click the Directories tab and enter Ýæij½½ïèÄ´·¾ under “Library Path”. .Select the “Microchip C18 Toolsuite” as the active toolsuite. i.

Advanced tab.If MPLAB C Compiler for PIC18 MCUs is used. use the following: ³°¿­³©·² ó° ¼»ª·½» ­±«®½»îò¿­³ where ¼»ª·½» is the device representation and ­±«®½»îò¿­³ is the assembly code source file example. use (shown on two lines but type on one): ³°´·²µ ñ°¼»ª·½» ñ«Á³¿½®± ­±«®½»ïò± ­±«®½»îò± ñ´ ½æij½½ïèÄ´·¾ ñ³ ¿°°ò³¿° or (for a modified linker script): ³°´·²µ ³±¼·º·»¼ò´µ® ñ«Á³¿½®± ­±«®½»ïò± ­±«®½»îò± ñ´ ½æij½½ïèÄ´·¾ ñ³ ¿°°ò³¿° where: Option ¼»ª·½» ³±¼·º·»¼ò´µ® The device representation. 13. For MPASM assembly. 2. The modified linker script file. For C code compilation. a) ÐßÌØ . as per Table 13-1 and Table 13-2. as here to generate ­±«®½»ïò± from ­±«®½»ïò½. 13.g.http://www. For multiple files. For multiple files. 3.2.foxitsoftware. For more details. View and edit variables here. leave a space between each file..Make sure the executables can be found. Description Á³¿½®± ­±«®½»ïò± ­±«®½»îò± ½æij½½ïèÄ´·¾ ¿°°ò³¿° DS33014K-page 198 2009 Microchip Technology Inc. 18F8772 for the PIC18F8722 device) and ­±«®½»ïò½ is the C code source file example.2 Using the Command Line The command line provides a platform independent method to develop your code. To set these variables.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. this should point to the ĸ subdirectory of the C compiler installation directory. leave a space between each file. only needed if the MPLAB® C compiler for PIC18 MCUs was used. .2.8 “Conditional Linker Statements”. go to Start>Settings>Control Panel>System. An assembly code object file.g. The listed Environment Variables need to be set as specified.. use the following: ³½½ïè ó° ¼»ª·½» ­±«®½»ïò½ where ¼»ª·½» is the device representation (e.1 BUILDING APPLICATIONS To build an application on the command line: 1. In Windows OS. The map file. A C code object file. The library path.2. see Section 11. 4. For MPLINK linking of files to create an application. b) ÓÝÝÁ×ÒÝÔËÜÛ . Environment Variables button. A conditional macro (e. ÁÝÎËÒÌ×ÓÛ). go to the Command prompt and type SET to view and set the variables.

2009 Microchip Technology Inc. Sample Applications 13. 2. consider Sample Application 3. use the following: ³½½ïè ó° ïèÚèéîî ½ðïè·Á³±¼ò½ ³·¨»¼ò½ 3.2. For MPLINK linking of files to create an application. use (shown on two lines but type on one): ³°´·²µ ³·¨»¼ò´µ® ñ«ÁÝÎËÒÌ×ÓÛ ½ðïè·Á³±¼ò± ³·¨»¼ò± ñ´ ½æij½½ïèÄ´·¾ ñ³ ³·¨»¼ò³¿° If you want to link for debug mode or PIC18 extended mode.Make sure the executables can be found. as per Table 13-2.foxitsoftware. b) ÓÝÝÁ×ÒÝÔËÜÛ . DS33014K-page 199 . To build an application on the command line: 1.Point to the ½æij½½ïèĸ subdirectory.2 EXAMPLE As an example.Generated by Foxit PDF Creator © Foxit Software http://www. For C code compilation.8 “Conditional Linker Statements”. a) ÐßÌØ . The listed Environment Variables need to be set as specified.com For evaluation only.2. C code mixed boot loader/application. see Section 11.

This template provides oscillator setup. The generic linker scripts are used automatically by the linker to simplify application development.3. program code sections. These definitions are grouped based on debugger or programmer usage. and regular or extended memory usage.Low priority interrupt vector High_Int . The source code templates give you a starting point from which to begin coding. TABLE 13-3: PROGRAM MEMORY MAP – PIC18F8722 Program Memory Address 0x0000 0x0007 0x0008 0x0017 0x0018 0x0019 0x01FFFF 0x200000 0x200007 0x300000 0x30000D 0x3FFFFE 0x3FFFFF 0xF00000 0xF003FF idlocs .High priority interrupt handler Low_Int .foxitsoftware. Or you may modify a linker script and then manually add it on the linker command line or to the project.High priority interrupt vector LOW_INT_VECTOR . GPR sections.Contains relocatable assembly code examples by device The relocatable source code template ïèÚèéîîÌÓÐÑòßÍÓ for the PIC18F8722 may be found in the Ѿ¶»½¬ directory. reset and interrupt handling routines. source code templates may be found at: ÝæÄЮ±¹®¿³ Ú·´»­ÄÓ·½®±½¸·°ÄÓÐßÍÓ Í«·¬»ÄÌ»³°´¿¬» in the following subdirectories: • ݱ¼» .TEMPLATES AND LINKER SCRIPTS In the MPLAB IDE installation.Device ID eedata .com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. assembly source code templates and generic linker script files are provided for most devices supported by MPLAB IDE.http://www.Low priority interrupt handler Main . This first general example will discuss templates and linker scripts.Configuration settings Linker Script Section (Not debug or extended) page . .Configuration bits devid .Main application code DS33014K-page 200 2009 Microchip Technology Inc. and access memory sections.ID locations config . This file defines initialization files. 13. example variable and EEPROM setup.EEPROM data DATA_EEPROM . For MPLAB IDE installed in the default location. 13.1 Locating Templates and Linker Script Files For MPLAB IDE installed in the default location. Program memory sections specified by the template code and linker script are compared below. and a section ³¿·² for application code. the generic linker script files may be found at: ÝæÄЮ±¹®¿³ Ú·´»­ÄÓ·½®±½¸·°ÄÓÐßÍÓ Í«·¬»ÄÔÕÎ The generic linker script file for the PIC18F8722 would be ïèºèéîîÁ¹ò´µ®.ROM code space Template Source Code Section RESET_VECTOR .Contains absolute assembly code examples by device • Ѿ¶»½¬ .Reset vector HI_INT_VECTOR .3 SAMPLE APPLICATION 1 .Data EEPROM CONFIG .

This application is discussed in the MPLAB C Compiler for PIC18 MCUs Getting Started (DS51295).Generated by Foxit PDF Creator © Foxit Software http://www. in the main code portion.foxitsoftware. In general. Modified 18F8722TMPO. Still.2 Modifying Templates and Linker Script Files For this sample application. assembly code is added to the template but the generic linker script is not edited.com For evaluation only. you will modify templates to create your own application code but you should not need to modify the generic linker script file. Sample Applications 13. there are reasons why you might want to customize a linker script.3. a case where you might want to modify the linker script is when you want to use a C code data object that is larger than 256 bytes. DS33014K-page 201 .ASM In the template. add the following udata section: å Ñ­½·´´¿¬±® Í»´»½¬·±²æ ÝÑÒÚ×Ù ÑÍÝ ã ÔÐ åÔÐ åß®®¿§ ª¿®·¿¾´»­ ¿®®¿§ ËÜßÌß ð¨îÚÛ »´»³»²¬ï ÎÛÍ ï »´»³»²¬î ÎÛÍ ï »´»³»²¬í ÎÛÍ ï »´»³»²¬ì ÎÛÍ ï »´»³»²¬ë ÎÛÍ î åöööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö åÊ¿®·¿¾´» ¼»º·²·¬·±²­ Then. such as a large array. In addition. add the following program code: åöööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö åͬ¿®¬ ±º ³¿·² °®±¹®¿³ å ̸» ³¿·² °®±¹®¿³ ½±¼» ·­ °´¿½»¼ ¸»®»ò Ó¿·²æ å ööö ³¿·² ½±¼» ¹±»­ ¸»®» ööö ¾¿²µ­»´ »´»³»²¬ï ³±ª´© ð¨ëë ³±ª©º »´»³»²¬ïôï ³±ªºº »´»³»²¬ïô»´»³»²¬î ®®½º »´»³»²¬îôïôï ³±ªºº »´»³»²¬îôÉÎÛÙ åÍ»´»½¬ »´»³»²¬ï ¾¿²µ åÓ±ª» ´·¬»®¿´ 嬱 »´»³»²¬ï åÓ±ª» »´»³»²¬ï 嬱 »´»³»²¬îô ®·¹¸¬ ­¸·º¬ å»´»³»²¬îô ³±ª» ¬± ÉÎÛÙ åÍ·²½» ®»¹«´¿® ÎßÓ ©¿­ å«­»¼ ·²­¬»¿¼ ±º ß½½»­­ åÎßÓô ½¸¿²¹» °¸§­·½¿´ ¾¿²µ­ ¾¿²µ­»´ »´»³»²¬í åÍ»´»½¬ »´»³»²¬í ¾¿²µ ³±ª©º »´»³»²¬í åÓ±ª» ÉÎÛÙ ¬± »´»³»²¬íô ®®½º »´»³»²¬íôïôï å®·¹¸¬ ­¸·º¬ ¿²¼ ³±ªºº »´»³»²¬íô»´»³»²¬ì å³±ª» ¬± »´»³»²¬ì ®®½º »´»³»²¬ìôïôï åη¹¸¬ ­¸·º¬ »´»³»²¬ì ³±ªºº »´»³»²¬ìô»´»³»²¬ë 忲¼ ³±ª» ¬± »´»³»²¬ë å´±© ¾§¬» ®®½º »´»³»²¬ìôïôï åη¹¸¬ ­¸·º¬ »´»³»²¬ì ³±ªºº »´»³»²¬ìô»´»³»²¬ëõï 忹¿·² ¿²¼ ³±ª» ¬± å»´»³»²¬ë ¸·¹¸ ¾§¬» 2009 Microchip Technology Inc. as shown in the other sample applications. FAQ-10.

3.com Assembler/Linker/Librarian User’s Guide Ô±±° ¹±¬± Ô±±° Generated by Foxit PDF Creator © Foxit Software For evaluation only. to continue development with MPLAB IDE.3 Building the Application To build the application. .http://www. remembering to change »´»³»²¬ë to a 16-bit value (Properties dialog. see Section 13. you could place the element variables in a Watch window to see their values. DS33014K-page 202 2009 Microchip Technology Inc.2 “How to Build the Sample Applications”. åöööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö åÛ²¼ ±º °®±¹®¿³ ÛÒÜ 13.foxitsoftware. Then. Watch Properties tab).

com For evaluation only.On-chip Memory eeprom . ×ÒÌØßÒÜ ÝÑÜÛ. The main function in the C file is placed in the default ÝÑÜÛ section because there is no section directive explicitly assigned.EE Data CONFIG . The file »»°®±³îò¿­³ places interrupt handling code at 0x20000 (external memory. Sample Applications 13.PIC18F8720 Linker Script Section (Not debug or extended) page .Interrupt Handler DATTBL .External Memory idlocs .Configuration Bits devid .Configuration Settings Source Code Section STARTUP PROG .Data Table Program Memory Address 0x000000 0x01FFFF 0x020000 0x1FFFFF 0x200000 0x200007 0x300000 0x30000D 0x3FFFFE 0x3FFFFF 0xF00000 0xF003FF 2009 Microchip Technology Inc.4 SAMPLE APPLICATION 2 – PLACING CODE AND SETTING CONFIG BITS This example is for the PIC18F8720 in extended microcontroller mode. places the code that follows into the ×ÒÌØßÒÜ section. you may wish to reference: • PIC18F8720 Device Data Sheet (DS39609) • MPLAB C18 C Compiler User’s Guide (DS51288) • External Memory Interfacing Techniques for the PIC18F8XXX (AN869) Program memory sections specified by the code and linker script are compared below. The modified linker script file (»»°®±³ò´µ®) maps the ×ÒÌØßÒÜ section to the ÝÑÜÛ region that begins at 0x20000. Additionally.Device ID eedata . The data table is defined in C using the ý°®¿¹³¿ ®±³¼¿¬¿ directive to place the table in a section called ÜßÌÌÞÔ.Generated by Foxit PDF Creator © Foxit Software http://www. The file »»°®±³ïò½ has a 0x1000 element data table in program memory in the same code page with the interrupt handlers. For additional information.Main Application Code INTHAND .foxitsoftware. DS33014K-page 203 .ID Locations config . TABLE 13-4: SA2 PROGRAM MEMORY MAP . Specific sections highlighted in this sample application (SA2) are noted. The modified linker script file maps the ÜßÌÌÞÔ section to the ÝÑÜÛ region that begins at 0x20000.) The assembly code directive. configuration bits are set in C using the ý°®¿¹³¿ ½±²º·¹ directive.

com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. .c ñö »»°®±³ïò½ öñ ý·²½´«¼» ä°ïèºèéîðò¸â ý¼»º·²» ÜßÌßÁÍ×ÆÛ ð¨ïððð ñö Ü¿¬¿ Ì¿¾´» Í»¬«° öñ ý°®¿¹³¿ ®±³¼¿¬¿ ÜßÌÌÞÔ ññ Ы¬ º±´´±©·²¹ ®±³¼¿¬¿ ·²¬± ­»½¬·±² ÜßÌÌÞÔ «²­·¹²»¼ ®±³ ¼¿¬¿ÅÜßÌßÁÍ×ÆÛÃå ý°®¿¹³¿ ®±³¼¿¬¿ ññ Í»¬ ¾¿½µ ¬± ¼»º¿«´¬ ®±³¼¿¬¿ ­»½¬·±² ñö ݱ²º·¹«®¿¬·±² Þ·¬­ Í»¬«° ̸» ý°®¿¹³¿ ½±²º·¹ ¼·®»½¬·ª» ­°»½·º·»­ ¬¸» °®±½»­­±®ó­°»½·º·½ ½±²º·¹«®¿¬·±² ­»¬¬·²¹­ ø·ò»òô ½±²º·¹«®¿¬·±² ¾·¬­÷ ¬± ¾» «­»¼ ¾§ ¬¸» ¿°°´·½¿¬·±²ò Ú±® ³±®» ±² ¬¸·­ ¼·®»½¬·ª»ô ­»» ¬¸» þÓÐÔßÞ Ýïè Ý Ý±³°·´»® Ë­»®ù­ Ù«·¼»þ øÜÍëïîèè÷ò öñ ý°®¿¹³¿ ý°®¿¹³¿ ý°®¿¹³¿ ý°®¿¹³¿ ý°®¿¹³¿ ½±²º·¹ ½±²º·¹ ½±²º·¹ ½±²º·¹ ½±²º·¹ ÑÍÝÍ ã ÑÒô ÑÍÝ ã ÔÐ ññ Û²¿¾´» ÑÍÝ ­©·¬½¸·²¹ ¿²¼ ÔÐ ÐÉÎÌ ã ÑÒ ññ Û²¿¾´» ÐÑÎ ÞÑÎ ã ÑÒô ÞÑÎÊ ã ìî ññ Û²¿¾´» ÞÑÎ ¿¬ ìòîª ÉÜÌ ã ÑÚÚ ññ Ü·­¿¾´» ÉÜÌ ÓÑÜÛ ã ÛÓ ññ Ë­» Û¨¬»²¼»¼ ÓÝË ³±¼» ñö Ó¿·² ¿°°´·½¿¬·±² ½±¼» º±® ¼»º¿«´¬ ÝÑÜÛ ­»½¬·±² öñ ª±·¼ ³¿·²ø ª±·¼ ÷ ¥ ©¸·´»ø ï ÷ ¥ £ ññ »²¼ ©¸·´» £ ññ »²¼ ³¿·² 13.eeprom2.asm å »»°®±³îò¿­³ ´·­¬ °ãïèºèéîð ý·²½´«¼» °ïèºèéîðò·²½ ×ÒÌØßÒÜ ½±¼» å °´¿½» ·²¬»®®«°¬ ¸¿²¼´·²¹ ½±¼» ·² ¸»®» »²¼ DS33014K-page 204 2009 Microchip Technology Inc.foxitsoftware.1 C Source Code .2 Assembler Source Code .eeprom1.4.http://www. 13.4.

In the dialog. you could add the absolute address in code.foxitsoftware. you must tell MPLAB IDE the range of external memory you wish to use.4 Building the Application To build the application. 2. if you need to place additional code in the CODEPAGE eeprom area.eeprom.4. Select Configure>External Memory. Modify the generic linker script as follows to create »»°®±³ò´µ®. Click OK.5 Absolute Method Instead of adding SECTION lines to the linker script..2 “How to Build the Sample Applications”. 2009 Microchip Technology Inc. it is usually easier not to place code absolutely but to allow the linker script to place code for you. if you edit the interrupt handler code.4. to continue development with MPLAB IDE: 1.com For evaluation only.Generated by Foxit PDF Creator © Foxit Software http://www. Sample Applications 13. 13. i.3 Linker Script . Though the configuration bits in code set the microcontroller mode to external.4. you would need to remember to change the address of the additional code. Add EEPROM codepage information: ý×ÚÜÛÚ ÁÜÛÞËÙÝÑÜÛÍÌßÎÌ ÝÑÜÛÐßÙÛ ÒßÓÛã°¿¹» ÝÑÜÛÐßÙÛ ÒßÓÛã¼»¾«¹ ýÛÔÍÛ ÝÑÜÛÐßÙÛ ÒßÓÛã°¿¹» ýÚ× ññÛÛÐÎÑÓ ½±¼»°¿¹» ÝÑÜÛÐßÙÛ ÒßÓÛã»»°®±³ ÝÑÜÛÐßÙÛ ÝÑÜÛÐßÙÛ ÝÑÜÛÐßÙÛ ÝÑÜÛÐßÙÛ ÒßÓÛã·¼´±½­ ÒßÓÛã½±²º·¹ ÒßÓÛã¼»ª·¼ ÒßÓÛã»»¼¿¬¿ ÍÌßÎÌãð¨ð ÍÌßÎÌãÁÜÛÞËÙÝÑÜÛÍÌßÎÌ ÍÌßÎÌãð¨ð ÛÒÜãÁÝÑÜÛÛÒÜ ÛÒÜãÁÝÛÒÜ ÛÒÜãð¨ïÚÚÚÚ ÐÎÑÌÛÝÌÛÜ ÍÌßÎÌãð¨îðððð ÍÌßÎÌãð¨îððððð ÍÌßÎÌãð¨íððððð ÍÌßÎÌãð¨íÚÚÚÚÛ ÍÌßÎÌãð¨Úððððð ÛÒÜãð¨ïÚÚÚÚÚ ÛÒÜãð¨îððððé ÛÒÜãð¨íððððÜ ÛÒÜãð¨íÚÚÚÚÚ ÛÒÜãð¨ÚððíÚÚ ÐÎÑÌÛÝÌÛÜ ÐÎÑÌÛÝÌÛÜ ÐÎÑÌÛÝÌÛÜ ÐÎÑÌÛÝÌÛÜ ÐÎÑÌÛÝÌÛÜ Then add section information for the EEPROM sections: ý×ÚÜÛÚ ÁÝÎËÒÌ×ÓÛ ÍÛÝÌ×ÑÒ ÒßÓÛãÝÑÒÚ×Ù ÎÑÓã½±²º·¹ ÍÛÝÌ×ÑÒ ÒßÓÛã×ÒÌØßÒÜ ÎÑÓã»»°®±³ ÍÛÝÌ×ÑÒ ÒßÓÛãÜßÌÌÞÔ ÎÑÓã»»°®±³ ý×ÚÜÛÚ ÁÜÛÞËÙÜßÌßÍÌßÎÌ ÍÌßÝÕ Í×ÆÛãð¨ïðð ÎßÓã¹°®ïí ýÛÔÍÛ ÍÌßÝÕ Í×ÆÛãð¨ïðð ÎßÓã¹°®ïì ýÚ× ýÚ× ññ ײ¬»®®«°¬ ¸¿²¼´»®­ ññ Ü¿¬¿ ¬¿¾´»­ 13. you would need to know the disassembly code length of the interrupt handler to determine the absolute address at which to place this additional code. ×ÒÌØßÒÜ ½±¼» ð¨îðððð However. DS33014K-page 205 .e.lkr The linker script file »»°®±³ò´µ® is a modified version of the generic linker script file ïèºèéîðÁ¹ò´µ®. Then. Also. Therefore. click “Use External Memory” and enter “0x1FFFFF” as the “Address Range End”. see Section 13. Select Project>Build All to build the application again.

The relocatable application or “user” code is typically transferred to the boot loader through serial communications.1 “C Compiler Memory Map”.foxitsoftware.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. Typically.5. is responsible for downloading and programming relocatable application code into the same target PIC microcontroller.5.5 SAMPLE APPLICATION 3 – USING A BOOT LOADER A boot loader is a special program that. refer to Section 13. such as the PIC18F8722. such as the PIC18F8720 with a limited boot block size. To build the C compiler sample application. Example 3 is a mixed language example using the C compiler application targeted for a microcontroller. 13.1.5. There are three examples showing how to modify the C compiler linker scripts and how to use the ý°®¿¹³¿ ½±¼» directive in the source code for the C compiler boot loader project. See 13. A boot loader written in C code will typically require more program memory than a boot loader written in assembly and therefore requires a microcontroller with a larger boot block region.1 C Compiler Usage This section discusses how to use the MPLAB C Compiler for PIC18 MCUs (the C compiler) when developing bootloader and related application code.3 “Example 2: C Compiler Application”. To better understand how the code corresponds to locations in device program memory.http://www.1. running an MPASM boot loader.1. See 13. such as RS232.5.2 “How to Build the Sample Applications”. DS33014K-page 206 2009 Microchip Technology Inc.4 “Example 3: Mixed Language Boot Loader/Application”. See 13. Example 1 shows how to configure the C compiler linker script and suggests how to use code directives for the C compiler boot loader.1. boot loader code is compiled and linked for a destination in the “boot” section of the target microcontroller's program memory. The “application” code is compiled and linked for a destination inside the user section of program memory. Boot loader and application code written for the C compiler must use the C compiler linker scripts to command the linker to place the compiled C source code into appropriate program memory sections. . see 13. 13.2 “Example 1: C Compiler Boot Loader”. when programmed into the target PIC microcontroller. Example 2 shows the C compiler linker script configuration and suggested code directives for the C compiler application targeted for a microcontroller that is running the C compiler boot loader.5.

5. Boot Loader Linker Script The partial C compiler linker script file shown below demonstrates the modifications required to the generic linker script when building the C compiler boot loader source code files.Generated by Foxit PDF Creator © Foxit Software http://www. program memory sections specified by the code and linker script are compared below. The MPLINK linker will use this configuration to link the compiled source code into the boot program memory region starting at 002Ah. ÝÑÜÛÐßÙÛ ÝÑÜÛÐßÙÛ ÒßÓÛ㪻½¬±®­ ÒßÓÛã¾±±¬ ÍÌßÎÌãð¨ð ÍÌßÎÌãð¨îß ÛÒÜãð¨îç ÛÒÜãð¨éÚÚ ý×ÚÜÛÚ ÁÜÛÞËÙÝÑÜÛÍÌßÎÌ ÝÑÜÛÐßÙÛ ÒßÓÛã°¿¹» ÝÑÜÛÐßÙÛ ÒßÓÛã¼»¾«¹ ýÛÔÍÛ ÝÑÜÛÐßÙÛ ÒßÓÛã°¿¹» ýÚ× ÝÑÜÛÐßÙÛ ÝÑÜÛÐßÙÛ ÝÑÜÛÐßÙÛ ÝÑÜÛÐßÙÛ ÒßÓÛã·¼´±½­ ÒßÓÛã½±²º·¹ ÒßÓÛã¼»ª·¼ ÒßÓÛã»»¼¿¬¿ ÍÌßÎÌãð¨èðð ÍÌßÎÌãÁÜÛÞËÙÝÑÜÛÍÌßÎÌ ÍÌßÎÌãð¨èðð ÛÒÜãÁÝÑÜÛÛÒÜ ÛÒÜãÁÝÛÒÜ ÛÒÜãð¨ïÚÚÚÚ ÐÎÑÌÛÝÌÛÜ ÍÌßÎÌãð¨îððððð ÍÌßÎÌãð¨íððððð ÍÌßÎÌãð¨íÚÚÚÚÛ ÍÌßÎÌãð¨Úððððð ÛÒÜãð¨îððððé ÛÒÜãð¨íððððÜ ÛÒÜãð¨íÚÚÚÚÚ ÛÒÜãð¨ÚððíÚÚ ÐÎÑÌÛÝÌÛÜ ÐÎÑÌÛÝÌÛÜ ÐÎÑÌÛÝÌÛÜ 2009 Microchip Technology Inc.Boot Loader page . For these two examples it is assumed the boot block is configured for 2K bytes and requires modification to the C compiler linker script file in order to accommodate the selected boot block size.PIC18F8722 Linker Script Section (Not debug or extended) vectors . For the first two examples.5. IntL Boot R_vectors. Boot Loader Updated Application Code Program Memory Address 0x000000 0x000029 0x00002A 0x0007FF 0x000800 0x1FFFFF 13. IntH.5. R_IntL.1 “Assembler Memory Map”. uses the PIC18F8720. The vector locations will be specified in the boot loader source code using the appropriate ý°®¿¹³¿ ½±¼» directives. For the corresponding memory map.1 C COMPILER MEMORY MAP The first two C compiler boot loader examples are demonstrated using a PIC18F8722 which offers a configurable boot block size of 2K.foxitsoftware.1. R_IntH. The third example. a mix of an MPASM assembler boot loader and C compiler source code. see Section 13. Interrupts boot . Specific sections highlighted in these sample application (SA3) examples are noted.2 EXAMPLE 1: C COMPILER BOOT LOADER This example shows a section of linker script modified to accommodate the boot loader code.2.Remapped Vectors and User Code Source Code Section Vectors. 4K or 8K bytes.1.com For evaluation only.Reset. Sample Applications 13. DS33014K-page 207 . TABLE 13-5: SA3 PROGRAM MEMORY MAP . The remaining program memory is available for the relocatable application code and data tables.

http://www. . In this example.3 EXAMPLE 2: C COMPILER APPLICATION This example shows a section of linker script modified to accommodate the application code. A “main” function must be included. The linker will use this configuration to link the compiled source code into the °¿¹»ï program memory region above the protected boot loader region. DS33014K-page 208 2009 Microchip Technology Inc. Application Linker Script The boot loader linker script file may be used when building the C compiler application source code files.1. as this is called from the C compiler startup code that is added during link process.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. ý·²½´«¼» ä°ï轨¨¨ò¸â ý¼»º·²» ÎÓÁÎÛÍÛÌÁÊÛÝÌÑÎ ý¼»º·²» ÎÓÁØ×ÙØÁ×ÒÌÛÎÎËÐÌÁÊÛÝÌÑÎ ý¼»º·²» ÎÓÁÔÑÉÁ×ÒÌÛÎÎËÐÌÁÊÛÝÌÑÎ ð¨ðððèðð ññ ¼»º·²» ®»´±½¿¬»¼ ª»½¬±® ¿¼¼®»­­»­ ð¨ðððèðè ð¨ðððèïè ñöö ÊÛÝÌÑÎ ÓßÐÐ×ÒÙ öööööööööööööööööööööööööööööööööööööööööööñ ý°®¿¹³¿ ½±¼» ÁØ×ÙØÁ×ÒÌÛÎÎËÐÌÁÊÛÝÌÑÎ ã ð¨ðððððè ª±·¼ Á¸·¹¸Á×ÍÎ øª±·¼÷ ¥ Á¿­³ ¹±¬± ÎÓÁØ×ÙØÁ×ÒÌÛÎÎËÐÌÁÊÛÝÌÑÎ Á»²¼¿­³ £ ý°®¿¹³¿ ½±¼» ÁÔÑÉÁ×ÒÌÛÎÎËÐÌÁÊÛÝÌÑÎ ã ð¨ððððïè ª±·¼ Á´±©Á×ÍÎ øª±·¼÷ ¥ Á¿­³ ¹±¬± ÎÓÁÔÑÉÁ×ÒÌÛÎÎËÐÌÁÊÛÝÌÑÎ Á»²¼¿­³ £ ñöö ÞÑÑÌ ÔÑßÜÛÎ ÝÑÜÛ ööööööööööööööööööööööööööööööööööööööööööñ ý°®¿¹³¿ ½±¼» ª±·¼ ³¿·²øª±·¼÷ ¥ ññݸ»½µ Þ±±¬´±¿¼ Ó±¼» Û²¬®§ ݱ²¼·¬·±² ·ºøÐÑÎÌÞ¾·¬­òÎÞì ãã ï÷ ññ ׺ ²±¬ °®»­­»¼ô Ë­»® Ó±¼» ¥ Á¿­³ ¹±¬± ÎÓÁÎÛÍÛÌÁÊÛÝÌÑÎ Á»²¼¿­³ £ ññÛ´­» ½±²¬·²«» ©·¬¸ ¾±±¬´±¿¼»® ½±¼» ¸»®» òòò £ ý°®¿¹³¿ ½±¼» «­»® ã ÎÓÁÎÛÍÛÌÁÊÛÝÌÑÎ ññ ̸·­ ¿¼¼®»­­ ¼»º·²»¼ ¿­ ð¨èðð ¿¾±ª» ññ ±® ½¿² ¾» ¼»º·²»¼ ·² ¸»¿¼»® º·´» ñöö ÛÒÜ ÑÚ ÞÑÑÌ ÔÑßÜÛÎ ööööööööööööööööööööööööööööööööööööööööñ 13.foxitsoftware.5. the source code file uses the ý°®¿¹³¿ ½±¼» directive to instruct the linker to place the interrupt vectors at memory locations 0008h and 0018h. Boot Loader Source Code The C compiler boot loader code can be composed of one or more aggregate relocatable C source files that are compiled and linked together during build time.

Generated by Foxit PDF Creator © Foxit Software http://www. the source code file uses the ý°®¿¹³¿ ½±¼» directive to instruct the linker to place the relocated reset and interrupt vectors at the appropriate memory locations. The linker automatically includes this C compiler initialization code provided in file ½ðïè·ò½ and must be accessed by the application code through an “in-line” assembly ¹±¬± instruction shown below. as this is called from the C compiler startup code that is added during the link process.com For evaluation only. In the code snippet shown below. Sample Applications Application Source Code The C compiler application code can be composed of one or more aggregate relocatable C source files that are compiled and linked together during build time. DS33014K-page 209 . ý·²½´«¼» ä°ï轨¨¨ò¸â ñöö ÊÛÝÌÑÎ ÓßÐÐ×ÒÙ öööööööööööööööööööööööööööööööööööööööööööñ »¨¬»®² ª±·¼ Á­¬¿®¬«° øª±·¼÷å ññ Í»» ½ðïè·ò½ ·² §±«® Ýïè ½±³°·´»® ¼·® ý°®¿¹³¿ ½±¼» ÁÎÛÍÛÌÁ×ÒÌÛÎÎËÐÌÁÊÛÝÌÑÎ ã ð¨ðððèð𠪱·¼ Á®»­»¬ øª±·¼÷ ¥ Á¿­³ ¹±¬± Á­¬¿®¬«° Á»²¼¿­³ £ ý°®¿¹³¿ ½±¼» ÁØ×ÙØÁ×ÒÌÛÎÎËÐÌÁÊÛÝÌÑÎ ã ð¨ðððèðè ª±·¼ Á¸·¹¸Á×ÍÎ øª±·¼÷ ¥ å £ ý°®¿¹³¿ ½±¼» ÁÔÑÉÁ×ÒÌÛÎÎËÐÌÁÊÛÝÌÑÎ ã ð¨ðððèïè ª±·¼ Á´±©Á×ÍÎ øª±·¼÷ ¥ å £ ñöö ßÐÐÔ×ÝßÌ×ÑÒ ÝÑÜÛööööööööööööööööööööööööööööööööööööööööööñ ý°®¿¹³¿ ½±¼» ª±·¼ ³¿·²øª±·¼÷ ¥ ©¸·´»øï÷ ¥ å ññ Ó¿·² ¿°°´·½¿¬·±² ½±¼» ¸»®» £ £ ñöö ÛÒÜ ÑÚ ßÐÐÔ×ÝßÌ×ÑÒ öööööööööööööööööööööööööööööööööööööööñ 2009 Microchip Technology Inc.foxitsoftware. A ³¿·² function must be included.

EXAMPLE 3: MIXED LANGUAGE BOOT LOADER/APPLICATION This example shows the linker script. ý×ÚÜÛÚ ÁÝÎËÒÌ×ÓÛ ý×ÚÜÛÚ ÁÛÈÌÛÒÜÛÜÓÑÜÛ Ú×ÔÛÍ ½ðïè·Á»ò± Ú×ÔÛÍ ½´·¾Á»ò´·¾ Ú×ÔÛÍ °ïèºèéîîÁ»ò´·¾ ýÛÔÍÛ Ú×ÔÛÍ ½ðïè·ò± äóó Ò±¬» ¬¸·­ ´·²» ¬± ¾» ·¹²±®»¼ ¾§ ´·²µ»® Ú×ÔÛÍ ½´·¾ò´·¾ Ú×ÔÛÍ °ïèºèéîîò´·¾ ýÚ× ññ ýÚ× ÝÑÜÛÐßÙÛ ÝÑÜÛÐßÙÛ ÒßÓÛ㪻½¬±®­ ÒßÓÛã¾±±¬ ÍÌßÎÌãð¨ð ÍÌßÎÌãð¨îß ÛÒÜãð¨îç ÛÒÜãð¨ïÚÚ ý×ÚÜÛÚ ÁÜÛÞËÙÝÑÜÛÍÌßÎÌ ÝÑÜÛÐßÙÛ ÒßÓÛã°¿¹» ÝÑÜÛÐßÙÛ ÒßÓÛã¼»¾«¹ ýÛÔÍÛ ÝÑÜÛÐßÙÛ ÒßÓÛã°¿¹» ýÚ× ÍÌßÎÌãð¨îðð ÍÌßÎÌãÁÜÛÞËÙÝÑÜÛÍÌßÎÌ ÍÌßÎÌãð¨îðð ÛÒÜãÁÝÑÜÛÛÒÜ ÛÒÜãÁÝÛÒÜ ÛÒÜãð¨ïÚÚÚÚ ÐÎÑÌÛÝÌÛÜ Mixed Language c018i. Instead it will use the modified file in the next section. the ½ðïè·ò½ startup code normally specifies program memory location 0000h as the entry section and is linked into the project by the linker when specified in the MPLAB C18 linker script. the C compiler start-up file ½ðïè·ò± has been remarked out. it is necessary to change the code section Á»²¬®§Á­½² definition in ½ðïè·ò½ file as shown below and to add the ½ðïè·ò½ source file to the project for recompiling and linking. .c Modifications For a typical C compiler application. In this linker script example. and source code modifications needed to accommodate a mixed language application which employs a boot loader.4 Generated by Foxit PDF Creator © Foxit Software For evaluation only. preventing the linker from linking this object file to the project.5. The linker will use this configuration to link the compiled source code into the user program memory region above the protected boot loader.foxitsoftware.1.com Assembler/Linker/Librarian User’s Guide 13. Mixed Language Linker Script The partial C compiler linker script file shown below demonstrates the required modifications when building the mixed assembly boot loader/C code application. ý°®¿¹³¿ ½±¼» Á»²¬®§Á­½²ãð¨ðððîð𠪱·¼ Á»²¬®§ øª±·¼÷ ¥ Á¿­³ ¹±¬± Á­¬¿®¬«° Á»²¼¿­³ £ DS33014K-page 210 2009 Microchip Technology Inc. startup code.http://www. Since the C compiler application code in this example has been relocated to program memory address 0200h because of the boot loader.

2.2. Example 3 incorporates both the assembler boot loader and multiple module relocatable assembler application as a single program memory image.5. In the code snippet shown below. Example 2 shows a multiple module relocatable assembler application. See Section 13. as this is called from the C compiler startup code that is added during the link process.4 “Example 2: Assembler Application Source Code”.Generated by Foxit PDF Creator © Foxit Software http://www. 2009 Microchip Technology Inc.5. The modified linker script file provided in this example is designed to support all three of the following examples. DS33014K-page 211 .3 “Example 1: Assembler Boot Loader Source Code”. A ³¿·² function must be included. See Section 13.5. See Section 13. To better understand how the code corresponds to locations in device program memory.2.2.5.foxitsoftware. Example 1 shows an assembler boot loader. To build the assembler sample application. ý·²½´«¼» ä°ï轨¨¨ò¸â ñöö ÊÛÝÌÑÎ ÓßÐÐ×ÒÙ öööööööööööööööööööööööööööööööööööööööööööñ ý°®¿¹³¿ ½±¼» ÁØ×ÙØÁ×ÒÌÛÎÎËÐÌÁÊÛÝÌÑÎ ã ð¨ðððîðè ª±·¼ Á¸·¹¸Á×ÍÎ øª±·¼÷ ¥ å ññ ×ÍÎ ¹±»­ ¸»®» £ ý°®¿¹³¿ ½±¼» ÁÔÑÉÁ×ÒÌÛÎÎËÐÌÁÊÛÝÌÑÎ ã ð¨ðððîïè ª±·¼ Á´±©Á×ÍÎ øª±·¼÷ ¥ å ññ ×ÍÎ ¹±»­ ¸»®» £ ñöö ßÐÐÔ×ÝßÌ×ÑÒ ÝÑÜÛööööööööööööööööööööööööööööööööööööööööööñ ý°®¿¹³¿ ½±¼» ª±·¼ ³¿·²øª±·¼÷ ¥ ©¸·´»øï÷ ¥ å ññ Ó¿·² ¿°°´·½¿¬·±² ½±¼» ¸»®» £ £ ñöö ÛÒÜ ÑÚ ßÐÐÔ×ÝßÌ×ÑÒ öööööööööööööööööööööööööööööööööööööööñ 13. There are three assembler examples showing suggested linker script modifications and appropriate source code directive usage for a boot loader and application project.2 “Assembler Linker Script”.com For evaluation only.5.2. see Section 13. See Section 13. refer to Section 13.5 “Example 3: Assembler Boot Loader/Application Source Code”.2 Assembler Usage This section discusses how to use the MPASM assembler (the assembler) when developing bootloader and related application code.2 “How to Build the Sample Applications”.5.1 “Assembler Memory Map”. Sample Applications Mixed Language Source Code The C compiler application code can be composed of one or more relocatable C source files that are compiled and linked together during build time. the source code file uses the ý°®¿¹³¿ ½±¼» directive to instruct the linker to place the relocated reset and interrupt vectors at the appropriate memory locations.

. user_code Program Memory Address 0x000000 0x000029 0x00002A 0x0001FF 0x000200 0x1FFFFF 13. This linker script file is designed to accommodate all three boot loader design considerations demonstrated in this chapter. IntH.5. program memory sections specified by the code and linker script are compared below. boot.2. the concepts shown here can be migrated to these other PIC microcontrollers. the linker script file uses modified ÝÑÜÛÐßÙÛ directives to establish these memory regions and uses the ÐÎÑÌÛÝÌÛÜ modifier to prevent the linker from assigning any relocatable code that is not explicitly assigned to these regions. User Code.Reset. which is the first 512 bytes of memory. R_IntH.Remapped Vectors. The remaining program memory. However. IntL Boot R_vectors. Data Tables Source Code Section Vectors. ÝÑÜÛÐßÙÛ ÝÑÜÛÐßÙÛ ÒßÓÛ㪻½¬±®­ ÒßÓÛã¾±±¬ ÍÌßÎÌãð¨ð ÍÌßÎÌãð¨îß ÛÒÜãð¨îç ÛÒÜãð¨ïÚÚ ÐÎÑÌÛÝÌÛÜ ÐÎÑÌÛÝÌÛÜ ý×ÚÜÛÚ ÁÜÛÞËÙÝÑÜÛÍÌßÎÌ ÝÑÜÛÐßÙÛ ÒßÓÛã°¿¹» ÝÑÜÛÐßÙÛ ÒßÓÛã¼»¾«¹ ýÛÔÍÛ ÝÑÜÛÐßÙÛ ÒßÓÛã°¿¹» ýÚ× ÝÑÜÛÐßÙÛ ÝÑÜÛÐßÙÛ ÝÑÜÛÐßÙÛ ÝÑÜÛÐßÙÛ ÒßÓÛã·¼´±½­ ÒßÓÛã½±²º·¹ ÒßÓÛã¼»ª·¼ ÒßÓÛã»»¼¿¬¿ ÍÌßÎÌãð¨îðð ÍÌßÎÌãÁÜÛÞËÙÝÑÜÛÍÌßÎÌ ÍÌßÎÌãð¨îðð ÛÒÜãÁÝÑÜÛÛÒÜ ÛÒÜãÁÝÛÒÜ ÛÒÜãð¨ïÚÚÚÚ ÐÎÑÌÛÝÌÛÜ ÍÌßÎÌãð¨îððððð ÍÌßÎÌãð¨íððððð ÍÌßÎÌãð¨íÚÚÚÚÛ ÍÌßÎÌãð¨Úððððð ÛÒÜãð¨îððððé ÛÒÜãð¨íððððÜ ÛÒÜãð¨íÚÚÚÚÚ ÛÒÜãð¨ÚððíÚÚ ÐÎÑÌÛÝÌÛÜ ÐÎÑÌÛÝÌÛÜ ÐÎÑÌÛÝÌÛÜ DS33014K-page 212 2009 Microchip Technology Inc.http://www.PIC18F8720 Linker Script Section vectors .2. starting at location 0200h. The boot loader typically resides in the “boot block” region of the PIC18F8720's program memory. is available for relocatable application code and data lookup tables. For this example.foxitsoftware.The linker script file for boot loader and application code example projects.lkr .2 ASSEMBLER LINKER SCRIPT To protect the boot block and vector memory regions.5.Boot Loader page . Specific sections highlighted in this sample application (SA3) example are noted. TABLE 13-6: SA3 PROGRAM MEMORY MAP . Interrupts boot_code .1 ASSEMBLER MEMORY MAP Generated by Foxit PDF Creator © Foxit Software For evaluation only. The section of modified generic linker script below shows how the linker can assign the relocatable application code to the user code memory region (°¿¹») that is not protected. The other program memory regions can only be populated if the ÝÑÜÛ directive used in the source files specifies placement of code within these protected memory regions.com Assembler/Linker/Librarian User’s Guide 13. R_IntL. Other PIC18F microcontrollers offer larger boot block regions and will require slightly different linker script modifications than what is represented in this example. from location 0000h to 01FFh.

The ÝÑÜÛ directives used in the boot loader source code instructs the linker to place the reset and interrupt vectors at their appropriate program memory locations for the PIC microcontroller and to place the starting location of the boot loader executable code just above this region starting at location 002Ah.Generated by Foxit PDF Creator © Foxit Software http://www. å ööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö å ïèÚ¾±±¬ò¿­³ å ööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö Ô×ÍÌ ÐãïèÚèéîð ý·²½´«¼» Ðï轨¨¨ò·²½ å ööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö Ê»½¬±®­ ½±¼» ð¨ðððð Êλ­»¬æ ¾®¿ Þ±±¬Áͬ¿®¬ ײ¬Ø Êײ¬Øæ ײ¬Ô Êײ¬Ôæ ½±¼» ¾®¿ ½±¼» ¾®¿ ð¨ðððè ð¨ðîðè ð¨ððïè ð¨ðîïè å λ󳿰 ײ¬»®®«°¬ ª»½¬±® ¬± ¿°°ù­ ½±¼» ­°¿½» å λ󳿰 ײ¬»®®«°¬ ª»½¬±® ¬± ¿°°ù­ ½±¼» ­°¿½» å ööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö Þ±±¬ ½±¼» ð¨ððîß å Þ±±¬ ´±¿¼»® »¨»½«¬¿¾´» ½±¼» ­¬¿®¬­ ¸»®» Þ±±¬Áͬ¿®¬æ å Ô±¹·½ ¬± ¼»¬»®³·²» ·º ¾±±¬´±¿¼»® »¨»½«¬»­ ±® ¾®¿²½¸ ¬± «­»®ù­ ½±¼» å òòò ¾®¿ ð¨ðîîß å Þ®¿²½¸ ¬± «­»®ù­ ¿°°´·½¿¬·±² ½±¼» å òòò å »²¼ ±º ¾±±¬ ´±¿¼»® ½±¼» ­»½¬·±² å ööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö ÛÒÜ 2009 Microchip Technology Inc.This is an example of how the startup portion of a boot loader could be configured when designing and programming only the boot loader code into the target PIC microcontroller.5. the boot loader is a single source file that will not be linked with any other source code at build time. 18Fboot. the boot loader is not linked with any application code so the relocated reset and interrupt vectors. The program memory section names Ê»½¬±®­.com For evaluation only. In this case. 0218h and 022Ah are assumed and therefore are explicitly coded.2. 0208h. Sample Applications 13. ײ¬Ø and ײ¬Ô are used with the ÝÑÜÛ directive to instruct the linker to place the assembled code that follows each directive at the specified program memory location.foxitsoftware.asm . DS33014K-page 213 .3 EXAMPLE 1: ASSEMBLER BOOT LOADER SOURCE CODE In this example.

foxitsoftware.asm .2. . The relocatable reset and interrupt vector locations are defined in ³¿·²ò¿­³ and are assigned to a specific program memory location by the ÝÑÜÛ directive.5. main.http://www. EXAMPLE 2: ASSEMBLER APPLICATION SOURCE CODE In this example the application code is composed of several relocatable source files that are assembled and linked together during build time.com Assembler/Linker/Librarian User’s Guide 13. å ööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö å ³¿·²ò¿­³ å ööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö Ô×ÍÌ ÐãïèÚèéîð ý·²½´«¼» Ðï轨¨¨ò·²½ å ööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö ÎÁª»½¬±®­ ½±¼» ð¨îðð ÎÊλ­»¬æ åλ󳿰°»¼ ÎÛÍÛÌ ª»½¬±® ¾®¿ ³¿·² ÎÁײ¬Ø ½±¼» ð¨îðè åλ󳿰°»¼ Ø×ó°®·±®·¬§ ·²¬»®®«°¬ ª»½¬±® ÎÊײ¬Øæ åØ·¹¸ °®·±®·¬§ ·²¬»®®«°¬ ª»½¬±® ½±¼» ¸»®» åòòò ®»¬º·» ÎÁײ¬Ô ½±¼» ð¨îïè åλ󳿰°»¼ ÔÑÉó°®·±®·¬§ ·²¬»®®«°¬ ª»½¬±® ÎÊײ¬Ôæ åÔ±© °®·±®·¬§ ·²¬»®®«°¬ ª»½¬±® ½±¼» ¸»®» åòòò ®»¬º·» «­»®Á½±¼» ½±¼» ð¨îîß ³¿·²æ å Û²¬®§ ·²¬± ¿°°´·½¿¬·±² ½±¼» ­¬¿®¬­ ¸»®» å òòòò å »²¼ ±º ³¿·² ½±¼» ­»½¬·±² å ööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö ÛÒÜ DS33014K-page 214 2009 Microchip Technology Inc.This is a sample of the startup portion of a main source code file that contains the relocated reset and interrupts and is the main entry point into the application.4 Generated by Foxit PDF Creator © Foxit Software For evaluation only.

Since the boot loader will be assembled and linked with the application source code files.lkr linker script file used in the previous examples is used to link the boot loader and application files together. defined in the application code. å ööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö å ïèÚ¾±±¬Á®ò¿­³ å ööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö Ô×ÍÌ ÐãïèÚèéîð ý·²½´«¼» Ðï轨¨¨ò·²½ å Ü»½´¿®» ´¿¾»´­ «­»¼ ¸»®» ¾«¬ ¼»º·²»¼ ±«¬­·¼» ¬¸·­ ³±¼«´» »¨¬»®² ÎÊλ­»¬ô ÎÊײ¬Øô ÎÊײ¬Ô å ööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö Ê»½¬±®­ ½±¼» ð¨ðððð Êλ­»¬æ ¾®¿ Þ±±¬Áͬ¿®¬ ײ¬Ø Êײ¬Øæ ײ¬Ô Êײ¬Ôæ ½±¼» ¾®¿ ½±¼» ¾®¿ ð¨ðððè ÎÊײ¬Ø ð¨ððïè ÎÊײ¬Ô å λ󳿰 ײ¬»®®«°¬ ª»½¬±® å λ󳿰 ײ¬»®®«°¬ ª»½¬±® å ööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö Þ±±¬ ½±¼» ð¨ððîß å Ü»º·²» »¨°´·½·¬ Þ±±¬´±¿¼»® ´±½¿¬·±² Þ±±¬Áͬ¿®¬æ å Ü»¬»®³·²» ·º ¾±±¬´±¿¼»® ­¸±«´¼ »¨»½«¬» ±® ¾®¿²½¸ ¬± «­»®ù­ ½±¼» å òòòò ¾®¿ ÎÊλ­»¬ å Þ®¿²½¸ ¬± «­»®ù­ ¿°°´·½¿¬·±² ½±¼» å Û´­» Þ±±¬´±¿¼»® »¨»½«¬·±² ­¬¿®¬­ ¸»®» å òòòò å ööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö ÛÒÜ 2009 Microchip Technology Inc. any references to external labels.asm and the ÛÈÌÛÎÒ directive used in the boot loader source file allow the linker to resolve the relocated reset and interrupt vector labels defined in main.5.foxitsoftware. 18Fboot_r. but in the application source code.This sample version of the boot loader allows for relocatable vectors that are defined. For this example. DS33014K-page 215 .5 EXAMPLE 3: ASSEMBLER BOOT LOADER/APPLICATION SOURCE CODE The final example demonstrates the possibility of combining both the boot loader and application code into a single program memory image that can be programmed into a target microcontroller at the same time. To accomplish this. Sample Applications 13. the same boot.2. must be resolved by the linker.asm and referenced in the ïèÚ¾±±¬Á®ò¿­³.com For evaluation only. not in the boot loader. the ÙÔÑÞßÔ directive used in main.Generated by Foxit PDF Creator © Foxit Software http://www.asm .

. main_r.This is a sample version of a main source code file that uses the ÙÔÑÞßÔ directive to make the relocatable reset and interrupt vector labels available to the boot loader.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only.http://www. å ööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö å ³¿·²Á®ò¿­³ å ööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö Ô×ÍÌ ÐãïèÚèéîð ý·²½´«¼» Ðï轨¨¨ò·²½ å Ü»º·²» ´¿¾»´­ ¸»®» ¾«¬ «­»¼ ±«¬­·¼» ¬¸·­ ³±¼«´» ¹´±¾¿´ ÎÊλ­»¬ô ÎÊײ¬Øô ÎÊײ¬Ô å ööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö ÎÁª»½¬±®­ ½±¼» ð¨îðð ÎÊλ­»¬æ åλ󳿰°»¼ ÎÛÍÛÌ ª»½¬±® ¾®¿ ³¿·² ÎÁײ¬Ø ½±¼» ð¨îðè åλ󳿰°»¼ Ø×ó°®·±®·¬§ ·²¬»®®«°¬ ª»½¬±® ÎÊײ¬Øæ åØ·¹¸ °®·±®·¬§ ·²¬»®®«°¬ ª»½¬±® ½±¼» ¸»®» åòòò ®»¬º·» ÎÁײ¬Ô ½±¼» ð¨îïè åλ󳿰°»¼ ÔÑÉó°®·±®·¬§ ·²¬»®®«°¬ ª»½¬±® ÎÊײ¬Ôæ åÔ±© °®·±®·¬§ ·²¬»®®«°¬ ª»½¬±® ½±¼» ¸»®» åòòò ®»¬º·» «­»®Á½±¼» ½±¼» ð¨îîß ³¿·²æ å Û²¬®§ ·²¬± ¿°°´·½¿¬·±² ½±¼» ­¬¿®¬­ ¸»®» å òòòò å »²¼ ±º ³¿·² ½±¼» ­»½¬·±² å ööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööööö ÛÒÜ DS33014K-page 216 2009 Microchip Technology Inc.asm .foxitsoftware.

In addition. 2009 Microchip Technology Inc. Notice that the first 128K bytes of the external memory region is overlapped with the 128K bytes of internal program memory space and therefore cannot be accessed using the external memory bus. The large memory model must be used in this project. The C compiler linker script file for the PIC18F8722 is modified to instruct the linker that a new memory region is available by adding a ÝÑÜÛÐßÙÛ definition as shown below.6.Generated by Foxit PDF Creator © Foxit Software http://www.6 SAMPLE APPLICATION 4 – CONFIGURING EXTERNAL MEMORY Most of the larger pin count PIC microcontrollers have the ability to interface to external 8. ý°®¿¹³¿ ®±³¼¿¬¿ ÍÎßÓÁÞßÍÛ åß­­·¹²­ ¬¸·­ ®±³¼¿¬¿ ­°¿½» ¿¬ ð¨ðîðððð ®±³ º¿® ½¸¿® ­®¿³ÅÃå åÜ»½´¿®» ¿² ¿®®¿§ ¿¬ ­¬¿®¬·²¹ ¿¼¼®»­­ To build the C compiler sample application. refer to Section 13. a new logical ÍÛÝÌ×ÑÒ is created and assigned to the program memory region specified in the associated ÝÑÜÛÐßÙÛ definition.1 C Compiler Usage This section discusses how to use the MPLAB C Compiler for PIC18 MCUs (the C compiler) when developing external memory application code. DS33014K-page 217 . the first 128K bytes of the SRAM are not accessible and therefore the first addressable location of SRAM is 20000h.com For evaluation only. ­®¿³ÅÃ.6. The PIC18F8722. the ®±³ qualifier is required in the declaration of the char array variable. real-time clocks or any device that has multiple configuration or control registers that can be accessed through an 8. for example. this memory region is beyond a 16-bit address range (64Kbyte) and therefore requires the use of the far qualifier in order for C pointers to correctly access this region. has 128K bytes of internal program memory (00000h 1FFFFh). • For the command line. as used in this example (SA4). the ý°®¿¹³¿ ®±³¼¿¬¿ directive instructs the linker to allocate the SRAM's starting address to the memory region specified by the ÍÎßÓÁÞßÍÛ logical section definition. 13. The use of the ÐÎÑÌÛÝÌÛÜ modifier prevents the linker from assigning random relocatable code to this region. not data memory. external program memory space from locations 20000h through 1FFFFFh becomes externally addressable through the EMB created from the I/O pins. when configured for Extended Microcontroller mode.2 “How to Build the Sample Applications”. • For MPLAB IDE. click the MPLAB C18 tab and chose the Category of “Memory Model” from the drop-down list.1 C COMPILER MEMORY MAP The table below shows the memory mapping for the PIC18F8722 when used with the 1Mbyte external SRAM device.or 16-bit data bus. The name ¨­®¿³ is arbitrary and can be any desired name. The use of a linker script file can be extended to other external memory-mapped devices such as programmable I/O peripherals.foxitsoftware. which should match the physical memory address range of the external memory being used. ÍÛÝÌ×ÑÒ ÒßÓÛãÍÎßÓÁÞßÍÛ ÎÑÓ㨭®¿³ In the C compiler application's source code file. But. What is important are the ÍÌßÎÌ and ÛÒÜ addresses. Under “Code Model”.1. at the end of Step 2. use the ó³´ option when compiling. ÝÑÜÛÐßÙÛ ÒßÓÛ㨭®¿³ ÍÌßÎÌãð¨ðîðððð ÛÒÜãð¨ðïÚÚÚÚÚ ÐÎÑÌÛÝÌÛÜ In addition to the new ÝÑÜÛÐßÙÛ. The physical address is provided by the ¨­®¿³ codepage directive at 20000h.or 16-bit data FLASH or SRAM memories through the External Memory Bus (EMB). Since the memory region occupied by the SRAM is program memory. 13. click “Large code mode (>64K)“. Without any additional external memory address decoding. Sample Applications 13.

foxitsoftware. ÝÑÜÛÐßÙÛ ÝÑÜÛÐßÙÛ ÝÑÜÛÐßÙÛ ÝÑÜÛÐßÙÛ ÝÑÜÛÐßÙÛ ÒßÓÛ㨭®¿³ ÒßÓÛã·¼´±½­ ÒßÓÛã½±²º·¹ ÒßÓÛã¼»ª·¼ ÒßÓÛã»»¼¿¬¿ ÍÌßÎÌãð¨ðîðððð ÍÌßÎÌãð¨îððððð ÍÌßÎÌãð¨íððððð ÍÌßÎÌãð¨íÚÚÚÚÛ ÍÌßÎÌãð¨Úððððð ÛÒÜãð¨ïÚÚÚÚÚ ÛÒÜãð¨îððððé ÛÒÜãð¨íððððÜ ÛÒÜãð¨íÚÚÚÚÚ ÛÒÜãð¨ÚððíÚÚ ÐÎÑÌÛÝÌÛÜ ÐÎÑÌÛÝÌÛÜ ÐÎÑÌÛÝÌÛÜ ÐÎÑÌÛÝÌÛÜ ÐÎÑÌÛÝÌÛÜ Then the external memory section is added.Reset. ý×ÚÜÛÚ ÁÝÎËÒÌ×ÓÛ ÍÛÝÌ×ÑÒ ÒßÓÛãÝÑÒÚ×Ù ÎÑÓã½±²º·¹ ÍÛÝÌ×ÑÒ ÒßÓÛãÍÎßÓÁÞßÍÛ ÎÑÓ㨭®¿³ ý×ÚÜÛÚ ÁÜÛÞËÙÜßÌßÍÌßÎÌ ÍÌßÝÕ Í×ÆÛãð¨ïðð ÎßÓã¹°®ïí ýÛÔÍÛ ÍÌßÝÕ Í×ÆÛãð¨ïðð ÎßÓã¹°®ïì ýÚ× ýÚ× 13. remember to enable external memory (Configure>External Memory) to see this extra memory in the Program Memory window.http://www.2 C COMPILER LINKER SCRIPT The sections of modified PIC18F8722 C compiler generic linker script file shown below demonstrates suggested modifications for external memory applications.1.com Assembler/Linker/Librarian User’s Guide TABLE 13-7: SA4 Generated by Foxit PDF Creator © Foxit Software For evaluation only. Interrupt vectors and On-chip Memory xsram .6.3 C COMPILER SOURCE CODE This is a simple code example showing the use of ý°®¿¹³¿ ®±³¼¿¬¿ for declaration of external memory and the use of C pointers for accessing this memory region. If you are using MPLAB IDE to run this example. . First the CODEPAGE statement is added.External Memory SRAM_BASE .6.1.romdata space Source Code Section Program Memory Address 0x000000 0x01FFFF 0x020000 0x0FFFFF 0x100000 0x1FFFFF 13. ý·²½´«¼» ä°ïèÚèéîîò¸â ññ Ó·½®±°®±½»­­±® ³±¼» ó ¿ ³»³±®§ ³±¼» ¬¸¿¬ ­«°°±®¬­ »¨¬»®²¿´ ³»³±®§ò ý°®¿¹³¿ ½±²º·¹ ÓÑÜÛ ã ÓÐ ý°®¿¹³¿ ®±³¼¿¬¿ ÍÎßÓÁÞßÍÛ ®±³ º¿® ½¸¿® ­®¿³ÅÃå ý°®¿¹³¿ ½±¼» ª±·¼ ³¿·²øª±·¼÷ ¥ ®±³ º¿® ½¸¿®ö ¼¿¬¿Ð¬®å ¼¿¬¿Ð¬® ã ­®¿³å ö¼¿¬¿Ð¬®õõ ã ð¨ÝÝå ö¼¿¬¿Ð¬® ã ð¨ëëå £ ññ ß­­·¹²­ ¬¸·­ ®±³¼¿¬¿ ­°¿½» ¿¬ ð¨îðððð ññ Ü»½´¿®» ¿² ¿®®¿§ ¿¬ ­¬¿®¬·²¹ ¿¼¼®»­­ ññ Ý®»¿¬» ¿ þº¿®þ °±·²¬»® ññ ß­­·¹² ¬¸·­ °±·²¬»® ¬± ¬¸» ³»³±®§ ¿®®¿§ ññ É®·¬» ´±© ¾§¬» ±º ïêó¾·¬ ©±®¼ ¬± ÍÎßÓ ññ É®·¬» ¸·¹¸ ¾§¬» ±º ïêó¾·¬ ©±®¼ ¬± ÍÎßÓ DS33014K-page 218 2009 Microchip Technology Inc. PROGRAM MEMORY MAP – PIC18F8722 AND 1 MB SRAM SRAM Address 0x000000 0x01FFFF 0x020000 0x0FFFFF LInker Script Section page .

refer to Section 13. the first 128K bytes of the SRAM are not accessible and therefore the first addressable location of SRAM is 20000h.Main Program SRAM_BASE_ADDRS SRAM_END_ADDRS Program Memory Address 0x000000 0x000029 0x00002A 0x01FFFF 0x020000 0x0FFFFF 0x100000 0x1FFFFF 2009 Microchip Technology Inc.6. which can be used to set up the table pointers prior to a table read or table write operation. as used in this example (SA4). In an assembler application's source file.2 Assembler Usage This section discusses how to use the MPASM assembler (the assembler) when developing external memory application code. ý¼»º·²» ÍÎßÓÁÞßÍÛÁßÜÜÎÍ ð¨îðððð ý¼»º·²» ÍÎßÓÁÛÒÜÁßÜÜÎÍ åÞ¿­» ¿¼¼®­ º±® »¨¬»®²¿´ å³»³±®§ ¼»ª·½» ð¨ïÚÚÚÚÚ åÛ²¼ ¿¼¼®­ ø²±¬ ®»¯«·®»¼÷ Accessing the external program memory through table reads and table writes requires the table pointer register be set up with the appropriate address as shown by the following example. using a simple ý¼»º·²» or »¯« directive provides an easy way to define the SRAM starting address. Without any additional external memory address decoding.Generated by Foxit PDF Creator © Foxit Software http://www.On-chip Memory xsram .com For evaluation only. Interrupts 0x000000 0x01FFFF 0x020000 0x0FFFFF page . Sample Applications 13.Reset.External Memory Source Code Section vectors prog .6. DS33014K-page 219 .foxitsoftware. 13. Notice that the first 128K bytes of the external memory region is overlapped with the 128K bytes of internal program memory space and therefore cannot be accessed using the external memory bus.2 “How to Build the Sample Applications”.1 ASSEMBLER MEMORY MAP The figure below shows the memory mapping for the PIC18F8722 when used with the 1 Mbyte external SRAM device.2. TABLE 13-8: SA4 PROGRAM MEMORY MAP – PIC18F8722 AND 1 MB SRAM SRAM Address LInker Script Section vectors . ³±ª´© ³±ª©º ³±ª´© ³±ª©º ³±ª´© ³±ª©º «°°»® øÍÎßÓÁÞßÍÛÁßÜÜÎÍ÷ ÌÞÔÐÌÎË ¸·¹¸ øÍÎßÓÁÞßÍÛÁßÜÜÎÍ÷ ÌÞÔÐÌÎØ ´±© øÍÎßÓÁÞßÍÛÁßÜÜÎÍ÷ ÌÞÔÐÌÎÔ To build the assembler sample application.

and external memory section is added.com Assembler/Linker/Librarian User’s Guide 13. .2 ASSEMBLER LINKER SCRIPT Generated by Foxit PDF Creator © Foxit Software For evaluation only.http://www. ý×ÚÜÛÚ ÁÝÎËÒÌ×ÓÛ ÍÛÝÌ×ÑÒ ÒßÓÛãÝÑÒÚ×Ù ÎÑÓã½±²º·¹ ÍÛÝÌ×ÑÒ ÒßÓÛãÊÛÝÌÑÎÍ ÎÑÓ㪻½¬±®­ ÍÛÝÌ×ÑÒ ÒßÓÛãÐÎÑÙ ÎÑÓã°¿¹» ÍÛÝÌ×ÑÒ ÒßÓÛãÍÎßÓ ÎÑÓ㨭®¿³ ý×ÚÜÛÚ ÁÜÛÞËÙÜßÌßÍÌßÎÌ ÍÌßÝÕ Í×ÆÛãð¨ïðð ÎßÓã¹°®ïí ýÛÔÍÛ ÍÌßÝÕ Í×ÆÛãð¨ïðð ÎßÓã¹°®ïì ýÚ× ýÚ× DS33014K-page 220 2009 Microchip Technology Inc.6. The modified PIC18F8722 assembler linker script file shown below demonstrates suggested modifications for external memory applications. program.foxitsoftware. First the CODEPAGE statements are added.2. ÝÑÜÛÐßÙÛ ÒßÓÛ㪻½¬±®­ ÍÌßÎÌãð¨ð ÛÒÜãð¨îç ÐÎÑÌÛÝÌÛÜ ý×ÚÜÛÚ ÁÜÛÞËÙÝÑÜÛÍÌßÎÌ ÝÑÜÛÐßÙÛ ÒßÓÛã°¿¹» ÝÑÜÛÐßÙÛ ÒßÓÛã¼»¾«¹ ýÛÔÍÛ ÝÑÜÛÐßÙÛ ÒßÓÛã°¿¹» ýÚ× ÝÑÜÛÐßÙÛ ÝÑÜÛÐßÙÛ ÝÑÜÛÐßÙÛ ÝÑÜÛÐßÙÛ ÝÑÜÛÐßÙÛ ÒßÓÛ㨭®¿³ ÒßÓÛã·¼´±½­ ÒßÓÛã½±²º·¹ ÒßÓÛã¼»ª·¼ ÒßÓÛã»»¼¿¬¿ ÍÌßÎÌãð¨îß ÍÌßÎÌãÁÜÛÞËÙÝÑÜÛÍÌßÎÌ ÍÌßÎÌãð¨îß ÛÒÜãÁÝÑÜÛÛÒÜ ÛÒÜãÁÝÛÒÜ ÛÒÜãð¨ïÚÚÚÚ ÐÎÑÌÛÝÌÛÜ ÍÌßÎÌãð¨ðîðððð ÍÌßÎÌãð¨îððððð ÍÌßÎÌãð¨íððððð ÍÌßÎÌãð¨íÚÚÚÚÛ ÍÌßÎÌãð¨Úððððð ÛÒÜãð¨ïÚÚÚÚÚ ÛÒÜãð¨îððððé ÛÒÜãð¨íððððÜ ÛÒÜãð¨íÚÚÚÚÚ ÛÒÜãð¨ÚððíÚÚ ÐÎÑÌÛÝÌÛÜ ÐÎÑÌÛÝÌÛÜ ÐÎÑÌÛÝÌÛÜ ÐÎÑÌÛÝÌÛÜ ÐÎÑÌÛÝÌÛÜ Then the vectors.

If you are using MPLAB IDE to run this example. DS33014K-page 221 .com For evaluation only.foxitsoftware. ý·²½´«¼» ä°ïèÚèéîîò·²½â å Ó·½®±°®±½»­­±® ³±¼» ó ¿ ³»³±®§ ³±¼» ¬¸¿¬ ­«°°±®¬­ »¨¬»®²¿´ ³»³±®§ò ÝÑÒÚ×Ù ÓÑÜÛ ã ÓÐ ý¼»º·²» ÍÎßÓÁÞßÍÛÁßÜÜÎÍ ð¨îðððð ý¼»º·²» ÍÎßÓÁÛÒÜÁßÜÜÎÍ ð¨ïÚÚÚÚÚ ª»½¬±®­ ½±¼» ¾®¿ ³¿·² °®±¹ ½±¼» ³¿·²æ å Û¨¿³°´» ó ¸±© ¬± ©®·¬» þð¨ëëÝÝþ ¬± º·®­¬ ©±®¼ ´±½¿¬·±² ·² »¨¬»®²¿´ ÍÎßÓ ³»³±®§ ³±ª´© ³±ª©º ³±ª´© ³±ª©º ³±ª´© ³±ª©º «°°»® øÍÎßÓÁÞßÍÛÁßÜÜÎÍ÷ ÌÞÔÐÌÎË ¸·¹¸ øÍÎßÓÁÞßÍÛÁßÜÜÎÍ÷ ÌÞÔÐÌÎØ ´±© øÍÎßÓÁÞßÍÛÁßÜÜÎÍ÷ ÌÞÔÐÌÎÔ å Þ¿­» ¿¼¼®­ º±® »¨¬»®²¿´ ³»³±®§ ¼»ª·½» å Û²¼ ¿¼¼®­ ø²±¬ ®»¯«·®»¼÷ ³±ª´© ð¨ÝÝ ³±ª©º ÌßÞÔßÌ ¬¾´©¬öõ ³±ª´© ³±ª©º ¬¾´©¬ö ÛÒÜ ð¨ëë ÌßÞÔßÌ å É®·¬»­ þð¨ÝÝþ ¬± ¾§¬» ´±½¿¬·±² ð¨ðîððððå å ײ½®»³»²¬­ ¬¿¾´» °±·²¬»® ¬± ²»¨¬ ´±½¿¬·±² å É®·¬» þð¨ëëþ ¬± ¾§¬» ´±½¿¬·±² ð¨ðîðððïå 2009 Microchip Technology Inc.6. Sample Applications 13.2.3 ASSEMBLER SOURCE CODE This is a simple code example showing the definition of the external memory SRAM address at 20000h and how to write a 16-bit value to two consecutive memory locations using the table pointer register and table write instruction.Generated by Foxit PDF Creator © Foxit Software http://www. remember to enable external memory (Configure>External Memory) to see this extra memory in the Program Memory window.

foxitsoftware.http://www. .com Assembler/Linker/Librarian User’s Guide NOTES: Generated by Foxit PDF Creator © Foxit Software For evaluation only. DS33014K-page 222 2009 Microchip Technology Inc.

A CODEPAGE. and is readable. Warnings and Messages Common Problems 14. The lkrpath must be a semicolon delimited list of directories. A linker command filename must end with ò´µ®. or END attribute.com For evaluation only. An object or library filename must end with ò± or ò´·¾ respectively. Check that the file exists. or another attribute is specified which is not valid. Enclose directory names which have embedded spaces in double quotes. Topics covered in this chapter: • • • • • • Linker Parse Errors Linker Errors Linker Warnings COFF File Errors Other Errors. 2009 Microchip Technology Inc. Enclose directory name which have embedded spaces in double quotes. Illegal <libpath> for LIBPATH in 'cmdfile:line'. Illegal <lkrpath> for LKRPATH in 'cmdfile:line'. These messages always appear in the listing file directly above each line in which the error occurred. Warnings and Common Problems 14. Invalid attributes for SECTION in 'cmdfile:line'. ASSEMBLER/LINKER/LIBRARIAN USER’S GUIDE Chapter 14.1 INTRODUCTION Error messages and warning messages are produced by the MPLINK linker. A SECTION directive must have a NAME and either a RAM or ROM attribute. Illegal <filename> for INCLUDE in 'cmdfile:line'.Generated by Foxit PDF Creator © Foxit Software http://www. A linker command file could not be opened. or SHAREBANK directive does not specify a NAME. Illegal <filename> for FILES in 'cmdfile:line'. Common problems and limitations of the linker tool are also listed here. is in the current search path. Invalid attributes for memory in 'cmdfile:line'. START. DATABANK. The libpath must be a semicolon delimited list of directories.2 LINKER PARSE ERRORS MPLINK linker parse errors are listed alphabetically below: Could not open 'cmdfile'.foxitsoftware. Errors. DS33014K-page 223 .

A length of zero will suppress pagination of the listing file. -n switch requires <length>. -k switch requires <pathlist>.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. A semicolon delimited path must be specified. Multiple inclusion of library file 'filename'. Enclose directory names containing embedded spaces with double quotes. An object file has been included multiple times either on the command line or with a FILES directive in a linker command file. For example: óµ òòå½æij§´µ®åþ½æÄ°®±¹®¿³ º·´»­Ä³·½®±½¸·°Ä³°¿­³ ­«·¬»Ä´µ®þ -l switch requires <pathlist>. or another attribute is specified which is not valid. A linker command file can only be included once. The number of source lines per listing file page must be specified. DS33014K-page 224 2009 Microchip Technology Inc. A map filename must be specified. -o switch requires <filename>. Invalid attributes for STACK in 'cmdfile:line'. For example: ó³ ³¿·²ò³¿°. Multiple inclusion of linker command file 'cmdfile'.http://www. . Unrecognized input in 'cmdfile:line'. Refer to the Usage documentation for the list of supported switches. Remove multiple INCLUDE directives to the referenced linker command file.foxitsoftware. For example: ó´ òòå½æij§´·¾åþ½æÄ°®±¹®¿³ º·´»­Ä³·½®±½¸·°Ä³°¿­³ ­«·¬»þ -m switch requires <filename>. An unrecognized command line switch was supplied. A library file has been included multiple times either on the command line or with a FILES directive in a linker command file. All statements in a linker command file must begin with a directive keyword or the comment Delimiter ññ. Multiple inclusion of object file 'filename'. Enclose directory names containing embedded spaces with double quotes. A COFF output filename must be specified. Remove the multiple references. A STACK directive does not specify a SIZE attribute. For example: ó± ³¿·²ò±«¬ Unknown switch: 'cmdline token'. Remove the multiple references. A semicolon delimited path must be specified.

Therefore.foxitsoftware. For 12-bit devices. Could not find file 'filename'.com For Problems Errors. ensure that the library module is included on the command line or in the linker command file using the FILES directive. Configuration settings have been specified for address 0x300001 in more than one object module. If the symbol is defined in a library module. Symbol symName is defined in different locations as different types. Could not find definition of symbol 'symName' in file ‘filename’. Each SECTION directive must have unique NAME attributes. bit 8. Program code sections will only be allocated at word-aligned addresses. is cleared in the CALL instruction or any modify PCL instruction.o' previously found in 'bar. The symbol symName is an external reference. File ‘filename’. Generated by Foxit PDF Creator © Foxit Software 14. performs a call to symbol ‘symName’ which is not in the lower half of a page. Could not resolve symbol 'symName' in file 'filename'. Set configuration bits for a given byte in a single ò½ file. º±±ò½ and ¾¿®ò½) with settings specified from the same configuration byte. A symbol symName is used without being defined in file filename. Could not open map file 'filename' for writing. it is not a read-only file. Conflicting types for symbol ‘symName’.. Remove duplicate definitions. Verify that if filename exists. the program counter (PC). Found in 'foo. The symbol symName is an external reference. or cannot be found in the linker path.http://www.3 LINKER ERRORS MPLINK linker errors are listed alphabetically below: Absolute code section 'secName' must start at a word-aligned address. Duplicate definitions of SECTION 'secName'. MPLINK will give this error message if an absolute code section address is specified that is not word-aligned. No input module defines this symbol. An input object or library file was specified which does not exist. All CODEPAGE and DATABANK directives must have unique NAME attributes. Duplicate definition of memory 'memName'.o' This error is issued when MPLAB C18's ý°®¿¹³¿ ½±²º·¹ directive has been used in two separate ò½ files (e.) 2009 Microchip Technology Inc. Could not resolve section reference ‘symName’ in file 'filename'. Warnings and Commonevaluation only. all subroutine calls or computed jumps are limited to the first 256 locations of any program memory page (512 words long. If the symbol is defined in a library module. section ‘secName’.g. DS33014K-page 225 . ensure that the library module is included on the command line or in the linker command file using the FILES directive. No input module defines this symbol.

Remove the multiple STACK directives. Set configuration bits using either MPASM assembler's ÁÁÝÑÒÚ×Ù directive or MPLAB C18's ý°®¿¹³¿ ½±²º·¹ directive. DS33014K-page 226 2009 Microchip Technology Inc. When using linker scripts. Inconsistent length definitions of SHAREBANK 'memName'.g. A SHAREBANK directive specifies a range of addresses that overlap a previous definition. All CODEPAGE blocks must specify unique memory ranges which do not overlap. ¾¿®ò¿­³) and MPLAB C18's ý°®¿¹³¿ ½±²º·¹ directive is specified in a ò½ file (e.. Internal Coff output file is corrupt. select Project>Build Options.o') cannot be used with either MPLAB C18's #pragma config directive or MPASM's CONFIG directive (found in 'foo. Mixing extended and non-extended mode modules not allowed The linker cannot link a mixture of extended mode modules and non-extended mode modules. º±±ò½). MPASM's __CONFIG directive (found in 'bar. Extended and non-extended memory modes apply to PIC18 devices. and check/uncheck the option “Extended Mode”. Multiple map files declared: 'filename1'. MPASM Assembly tab. When using MPASM to create object file modules. In MPLAB IDE. . Multiple STACK definitions. The ó³ 䳿°º·´»â switch was specified more than once. 'filename2'. Similarly DATABANK and SHAREBANK blocks may not overlap. select Project>Build Options. No input object files specified. Memory 'memName' overlaps memory 'memName'. MPLAB C18 tab. and check/uncheck the option “Extended Mode”. extended memory mode is enabled/disabled on the command line using the ó󻨬»²¼»¼ option.. No input object or library file was specified to the linker. 'filename2'. Multiple output files declared: 'filename1'. those with the suffix Á» apply to extended mode use.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. Overlapping definitions of SHAREBANK 'memName'. When using MPLAB C18 to create object file modules. The ó± 䱫¬º·´»â switch was specified more than once.foxitsoftware. extended memory mode is enabled/disabled on the command line using the ñ§ option. Overlaps are not permitted.g.http://www. A STACK directive occurs more than once in the linker command file or included linker command files. In MPLAB IDE. All SHAREBANK definitions which have the same NAME attribute must be of equal length. The linker cannot write to the COFF file. Enter files to link.o') This error message is issued when MPASM assembler's ÁÁÝÑÒÚ×Ù directive is specified in a ò¿­³ file (e.

http://www. or TOSL registers. A section with the name secName occurs in more than one input file. Section 'secName' length='0xHHHH'. Use only the RAM attribute when defining the section in the linker command file. The error map will show the sections which were allocated prior to the error. More memory must be made available by adding a CODEPAGE. in some files it is marked as either an absolute. TOSH. A section which has not been assigned to a memory in the linker command file can not be allocated. Warnings and Commonevaluation only.foxitsoftware. SHAREBANK. The MOVFF instruction has unpredictable results when its destination is the PCL. Section 'secName' contains initialized rom data and can not have a 'RAM' memory attribute specified in the linker command file. TOSU. Generated by Foxit PDF Creator © Foxit Software {PCL | TOSH | TOSU | TOSL} cannot be used as the destination of a MOVFF or MOVSF instruction. and in some it is not. Section 'secName' can not fit the absolute section. SHAREBANK. A section which has not been assigned to a memory in the linker command file can not be allocated. access. Section 'secName' can not fit the section.com For Problems Errors. DS33014K-page 227 . Use the ó³ 䳿°º·´»â switch to generate an error map file. or the number of input sections must be reduced. or DATABANK directive. Section {absolute|access|overlay|share} types for 'secName' do not match across input files. Section 'romName' can not have a 'RAM' memory attribute specified in the linker command file. Section 'secName' start=0xHHHH. However. More memory must be made available by adding a CODEPAGE. All input modules processor types or families must match. Use only the ROM attribute when defining the section in the linker command file. Use only the ROM attribute when defining the section in the linker command file. The error map will show the sections which were allocated prior to the error. or the number of input sections must be reduced. 2009 Microchip Technology Inc. Use the ó³ 䳿°º·´»â switch to generate an error map file. or DATABANK directive. or by removing the PROTECTED attribute. Each object module and library file specifies a processor type or a processor family. Processor types do not agree across all input files. Use only the ROM attribute when defining the section in the linker command file. or by removing the PROTECTED attribute. Change the section's type in the source files and rebuild the object modules. overlay or shared section. length=0xHHHH. Section 'secName' contains code and can not have a 'RAM' memory attribute specified in the linker command file. MPLINK will not allow the destination of a MOVFF instruction to be replaced with any of these addresses. Section 'secName' contains initialized data and can not have a 'ROM' memory attribute specified in the linker command file.

or SHAREBANK directive for the undefined memory to the linker command file. Section 'secName' has a memory 'memName' which can not fit the absolute section. Add a CODEPAGE. Section 'secName' start=0xHHHH. but a 2’s compliment encoding of the offset to symName wouldn't fit in the limited number of instruction bits used for the target of a branch instruction. Symbol 'symName' is not word-aligned. Use the ó³ 䳿°º·´»â switch to generate an error map file. or the section will overlap another section. Section 'secName' has a memory 'memName'' which is not defined in the linker command file.http://www. Use only the RAM attribute when defining the section in the linker command file. symbol 'symName' out of range of relative branch instruction. Section 'secName' type is non-overlay and absolute but occurs in more than one input file. Relocatable sections with the same name may occur in multiple input files. . its absolute overlay starting address varies between files. The error map will show the sections which were allocated prior to the error. Either remove the multiple absolute sections in the source files or use relocatable sections instead. but the instruction encoding cannot reference addresses that are not word-aligned. or the section will overlap another section. The target of a branch. Section 'secName' length='0xHHHH'. or goto instruction was at an odd address.foxitsoftware. length=0xHHHH. The memory which was assigned to the section in the linker command file either does not have space to fit the section. Starting addresses for absolute overlay section ‘secName’ do not match across all input files. Change the section's address in the source files and rebuild the object modules. A symbol may only be defined in a single input module. An absolute section with the name secName may only occur in a single input file. A section with the name secName occurs in more than one input file. However. A relative branch instruction had symName as its target. It cannot be used as the target of a {branch | call or goto} instruction. call. Use the ó³ 䳿°º·´»â switch to generate an error map file. DATABANK. The memory which was assigned to the section in the linker command file either does not have space to fit the section. Symbol 'symName' has multiple definitions. Section 'secName' contains uninitialized data and can not have a 'ROM' memory attribute specified in the linker command file. Section 'secName' has a memory 'memName' which can not fit the section. DS33014K-page 228 2009 Microchip Technology Inc. The error map will show the sections which were allocated prior to the error.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only.

Undefined DATABANK/SHAREBANK 'memName' for SECTION 'secName'. The _CONFIG_DECL macro (found in 'foo.g.foxitsoftware. ý°®¿¹³¿ ½±²º·¹. The _CONFIG_DECL macro (found in 'foo. ¾¿®ò¿­³). Add a CODEPAGE directive to the linker command file for the undefined memory block.o') This error is issued when MPLAB C18's ÁÝÑÒÚ×ÙÁÜÛÝÔ macro is used in a ò½ file (e.g. º±±ò½) and MPASM assembler's ÁÁÝÑÒÚ×Ù directive is used in a ò¿­³ file (e. 2009 Microchip Technology Inc. The section type for ‘secName’ needs to be defined.. Found in 'foo. Generated by Foxit PDF Creator © Foxit Software The _CONFIG_DECL macro can only be specified in one module.. Add a DATABANK or SHAREBANK directive to the linker command file for the undefined memory block. Undefined DATABANK/SHAREBANK 'memName' for STACK. No input object files specified.. Set configuration bits by using the ÁÝÑÒÚ×ÙÁÜÛÝÔ macro in only one ò½ file.o') cannot be used with either MPLAB C18's #pragma config directive or MPASM's CONFIG directive (found in 'bar. DS33014K-page 229 .. Unknown section type for 'secName' in file 'filename'. A SECTION directive with a RAM attribute refers to a memory block that has not been defined.o') This error is issued when MPLAB C18's ÁÝÑÒÚ×ÙÁÜÛÝÔ macro is used in a ò½ file (e. or ÁÁÝÑÒÚ×Ù directive.o') cannot be used with MPASM's __CONFIG directive (found in 'bar. At least one object module must be specified either on the command line or in the linker command file using the FILES directive. ¾¿®ò¿­³).http://www.g. Set configuration bits by using only one of ÁÝÑÒÚ×ÙÁÜÛÝÔ. TRIS argument is out of range '0xHHHH' not between '0xHHHH' and '0xHHHH'.g. See the Readme file for a list of supported devices. º±±ò½ and ¾¿®ò½). Undefined CODEPAGE 'memName' for SECTION 'secName'.com For Problems Errors. Check the device data sheet to determine acceptable hex values for the TRIS register you are using. Set configuration bits using either the ÁÝÑÒÚ×ÙÁÜÛÝÔ macro from MPLAB C18 or the ÁÁÝÑÒÚ×Ù directive in MPASM assembler.o' previously found in 'bar. Warnings and Commonevaluation only. An input object or library module is not of the proper file type or it may be corrupted. A SECTION directive with a ROM attribute refers to a memory block which has not been defined.g.. º±±ò½) with either MPLAB C18's ý°®¿¹³¿ ½±²º·¹ directive in a second ò½ file (e. A processor was specified that is not currently supported by the linker.. Unsupported processor type in file ‘filename’.o' This error is issued when MPLAB C18's ÁÝÑÒÚ×ÙÁÜÛÝÔ macro is specified in two separate ò½ files (e. ¾¿®ò½) or MPASM assembler's ÁÁÝÑÒÚ×Ù directive in a ò¿­³ file (e.g. Unknown section type for 'secName'.

Coff file 'filename' section['xx'] has an invalid s_offset. Coff file 'filename'. 14. Coff file 'filename' could not write string table length.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. If a fill pattern is specified for a ROM section. '/a' command line option ignored with '/x' /x prevents the generation of a . 14. specifying the format of hex output file with /a is irrelevant. Coff file 'filename' could not read section header. A relocation type was specified that is not currently supported by the linker. Therefore.hex file. section 'secName' line['xx'] has an invalid l_fcnndx. Coff file 'filename' could not read optional file header. this warning will be issued to warn of incomplete patterns. Coff file 'filename' could not write section header. DS33014K-page 230 2009 Microchip Technology Inc. Last value was truncated.lst file. Coff file 'filename' could not read symbol table. Please contact Microchip support if any of these errors are generated. Coff file 'filename' could not read string table.size() != cScnNum. Coff file 'filename' could not read relocation info.5 COFF FILE ERRORS All the COFF errors listed below indicate an internal error in the file's contents.http://www. Coff file 'filename' could not read line numbers. cScnHdr. Coff file 'filename' could not write lineinfo. Therefore.4 LINKER WARNINGS MPLINK linker warnings are listed alphabetically below: Fill pattern for memory 'memName' doesn't divide evenly into unused section locations. . Coff file 'filename' could not write reloc. but the free space in that section isn't evenly divisible by the fill pattern size. Coff file 'filename' does not appear to be a valid COFF file. Coff file 'filename' has relocation entries but an empty symbol table. Coff file 'filename' could not read string table length. Coff file 'filename' could not write string.size(). Coff file 'filename' could not read raw data. specifying the number of lines per listing page with /n is irrelevant. Coff file 'filename' missing optional file header. Coff file 'filename' could not write raw data.foxitsoftware. section 'secName' line['xx'] has an invalid l_srcndx. Coff file 'filename' could not write file header. Coff file 'filename'. Unsupported relocation type. • • • • • • • • • • • • • • • • • • • • • • • • • Coff file 'filename' could not read file header. Coff file 'filename' could not write optional file header. Coff file 'filename' could not write symbol. '/n' command line option ignored with '/w' /w prevents the generation of a . Coff file 'filename'.

Could not find section name 'secName' in string table. 2009 Microchip Technology Inc.3 “Command Line Interface” for control of listing and hex file output.6 OTHER ERRORS. Could not open Coff file 'filename' for reading. Unable to find section name in string table. Coff file 'filename' symbol['xx'] has an invalid n_offset. MPASM assembler directives are not supported in MPLINK linker scripts. none of these properties is appearing in my listing file.e. Could not open Coff file 'filename' for writing.com For Problems Errors. Coff file 'filename' symbol['xx'] has an invalid n_scnum. WARNINGS AND MESSAGES If you are using the linker with any of the utilities. Generated by Foxit PDF Creator © Foxit Software 14.http://www. Could not read archive magic string in library file 'filename'. “Errors and Warnings” 14. Unable to find aux_file name in string table. • MPLIB Librarian .. • • • • • • • • • • • • Coff file 'filename'. MPLIB librarian or you have not used the linker options ñ© or ñ¨.Chapter 17. Warnings and Commonevaluation only. symbol['xx'] has an invalid index. i. then you may need to look in the utility troubleshooting sections for your error. Coff file 'filename'. section 'secName' reloc['xx'] has an invalid r_symndx.foxitsoftware. “Errors” • MP2COD and/or MP2HEX .7 COMMON PROBLEMS Although I set up listing file properties with MPASM assembler directives. Unable to find symbol name in string table. Although MPASM assembler is often used with MPLINK object linker. See Section 10. Could not find symbol name 'symName' in string table. DS33014K-page 231 .Chapter 19.

. DS33014K-page 232 2009 Microchip Technology Inc.foxitsoftware.com Assembler/Linker/Librarian User’s Guide NOTES: Generated by Foxit PDF Creator © Foxit Software For evaluation only.http://www.

foxitsoftware.................Generated by Foxit PDF Creator © Foxit Software http://www............. 235 Chapter 16.......... Errors ................ ASSEMBLER/LINKER/LIBRARIAN USER’S GUIDE Part 3 – MPLIB Object Librarian Chapter 15..............................................com For evaluation only................... DS33014K-page 233 .................................................. Librarian Interfaces ..................... 239 Chapter 17... 241 2009 Microchip Technology Inc............................................................ MPLIB Librarian Overview ..

DS33014K-page 234 2009 Microchip Technology Inc.com Assembler/Linker/Librarian User’s Guide NOTES: Generated by Foxit PDF Creator © Foxit Software For evaluation only.http://www.foxitsoftware. .

Since libraries can group together several related object modules. • Libraries make projects more maintainable.2 WHAT IS MPLIB LIBRARIAN MPLIB object librarian (the librarian) combines object modules generated by the MPASM assembler or the MPLAB C18 C compiler into a single library file. • Libraries help keep code small. 2009 Microchip Technology Inc. Since a linker only uses the required object files contained in a library. There are several reasons for creating library files: • Libraries make linking easier.Generated by Foxit PDF Creator © Foxit Software http://www. If a library is included in a project. the purpose of a library file is usually more understandable than the purpose of its individual object modules. For example. and º´±±®ò±. A library file is simply a collection of object modules that are stored in a single file. Since library files can contain many object files. MPLIB Librarian Overview 15. the purpose of a file named ³¿¬¸ò´·¾ is more apparent than the purpose of °±©»®ò±. Topics covered in this chapter: • • • • • What is MPLIB Librarian How MPLIB Librarian Works How MPLIB Librarian Helps You Librarian Operation Librarian Input/Output Files 15. not all object files which are contained in the library necessarily wind up in the linker's output module.foxitsoftware. • Libraries help to convey the purpose of a group of object modules. the name of a library file can be used instead of the names of many separate object files when linking. DS33014K-page 235 . the addition or removal of calls to that library will not require a change to the link process.1 INTRODUCTION An overview of the MPLIB object librarian and its capabilities is presented. This file may then be inputted into the MPLINK object linker.3 HOW MPLIB LIBRARIAN WORKS A librarian manages the creation and modification of library files. 15.com For evaluation only. ASSEMBLER/LINKER/LIBRARIAN USER’S GUIDE Chapter 15. ½»·´·²¹ò±.

http://www.foxitsoftware.com Assembler/Linker/Librarian User’s Guide

Generated by Foxit PDF Creator © Foxit Software For evaluation only.

15.4

HOW MPLIB LIBRARIAN HELPS YOU
The MPLIB librarian can help you in the following ways: • The librarian makes linking easier because single libraries can be included instead of many smaller files. • The librarian helps keep code maintainable by grouping related modules together. • The librarian commands allow libraries to be created and modules to be added, listed, replaced, deleted, or extracted.

15.5

LIBRARIAN OPERATION
The librarian combines multiple input object modules, generated by the MPASM assembler or MPLAB C18 C compilers, into a single output library (ò´·¾) file. Library files are used in conjunction with the MPLINK linker to produce executable code. FIGURE 15-1: MPLIB™ LIBRARIAN OPERATION
³«´¬ò± ¿ª¹ò± ¿¼¼ò±

Object files

³¿¬¸ò´·¾

Library file

DS33014K-page 236

2009 Microchip Technology Inc.

Generated by Foxit PDF Creator © Foxit Software http://www.foxitsoftware.com For evaluation only.

MPLIB Librarian Overview

15.6

LIBRARIAN INPUT/OUTPUT FILES
The MPLIB librarian combines multiple object files into one library (.lib) file.

Input Files
Object File (.o) Relocatable code produced from source files.

Output Files
Library File (.lib) A collection of object files grouped together for convenience.

15.6.1

Object File (.o)

Object files are the relocatable code produced from source files. The MPLIB librarian combines several object files into a single library file.

15.6.2

Library File (.lib)

A library file may be created from object files by the MPLIB librarian or may be an existing standard library.

2009 Microchip Technology Inc.

DS33014K-page 237

http://www.foxitsoftware.com Assembler/Linker/Librarian User’s Guide
NOTES:

Generated by Foxit PDF Creator © Foxit Software For evaluation only.

DS33014K-page 238

2009 Microchip Technology Inc.

Generated by Foxit PDF Creator © Foxit Software http://www.foxitsoftware.com For evaluation only.

ASSEMBLER/LINKER/LIBRARIAN USER’S GUIDE Chapter 16. Librarian Interfaces
16.1 INTRODUCTION
How to use MPLIB librarian is discussed here. For information on how librarian output can be used with the MPASM assembler and the MPLINK linker, see the documentation for these tools. Topics covered in this chapter: • MPLAB IDE Interface • Command Line Options • Command Line Examples and Tips

16.2

MPLAB IDE INTERFACE
The MPLIB librarian may be used with MPLAB IDE to create a library file from project object files instead of an executable (hex) file. With your project open in MPLAB IDE, select Project>Build Options>Project. In the Build Options dialog, click on the MPASM/C17/C18 Suite tab. Click the radio button next to “Build library target (invoke MPLIB)”. Then click OK. Now when you build your project, you will be building a library file.

2009 Microchip Technology Inc.

DS33014K-page 239

http://www.foxitsoftware.com Assembler/Linker/Librarian User’s Guide

Generated by Foxit PDF Creator © Foxit Software For evaluation only.

16.3

COMMAND LINE OPTIONS
MPLIB librarian is invoked with the following syntax:
³°´·¾ Åñ¯Ã ñ¥½¬¼®¨£ Ô×ÞÎßÎÇ ÅÓÛÓÞÛÎòòòÃ

Options
Option ñ½ ñ¼ ñ¯ ñ® Description Create library Delete member Quiet mode Add/replace member Detail creates a new LIBRARY with the listed MEMBER(s) deletes MEMBER(s) from the LIBRARY; if no MEMBER is specified the LIBRARY is not altered no output is displayed if MEMBER(s) exist in the LIBRARY, then they are replaced, otherwise MEMBER is appended to the end of the LIBRARY prints a table showing the names of the members in the LIBRARY if MEMBER(s) exist in the LIBRARY, then they are extracted. If no MEMBER is specified, all members will be extracted

ñ¬ ñ¨

List members Extract member

16.4

COMMAND LINE EXAMPLES AND TIPS
Example of Use
Suppose you wanted to create a library named ¼­°ò´·¾ from three object modules named ºº¬ò±, º·®ò±, and ··®ò±. The following command line would produce the desired results:
³°´·¾ ñ½ ¼­°ò´·¾ ºº¬ò± º·®ò± ··®ò±

To display the names of the object modules contained in a library file named ¼­°ò´·¾, the following command line would be appropriate:
³°´·¾ ñ¬ ¼­°ò´·¾

Tips
MPLIB librarian creates library files that may contain only a single external definition for any symbol. Therefore, if two object modules define the same external symbol, the librarian will generate an error if both object modules are added to the same library file. To minimize the code and data space which results from linking with a library file, the library's member object modules should be as small as possible. Creating object modules that contain only a single function can significantly reduce code space.

DS33014K-page 240

2009 Microchip Technology Inc.

Could not write archive magic string in library file 'filename'. refer to command line options.1 INTRODUCTION MPLIB librarian detects the following sources of error and reports them. ASSEMBLER/LINKER/LIBRARIAN USER’S GUIDE Chapter 17. Library files must end with ò´·¾. it is not read-only. Topics covered in this chapter: • Librarian Parse Errors • Library File Errors • COFF File Errors 17. Invalid Switch An unsupported switch was specified.foxitsoftware.lib'. Could not open library file 'filename' for writing. All library filenames must end with '. Could not write member header for 'memberName' in library file 'filename'. 17. File 'filename' is not a valid library file.Generated by Foxit PDF Creator © Foxit Software http://www.3 LIBRARY FILE ERRORS Library file processing errors are listed alphabetically below: Could not build member 'memberName' in library file 'filename'.2 LIBRARIAN PARSE ERRORS MPLIB librarian parse errors are listed alphabetically below: Invalid Object Filename All object filenames must end with '. Verify that if filename exists.o'. Errors 17. The file may be corrupted. For a list of supported switches. 2009 Microchip Technology Inc. Could not open library file 'filename' for reading. DS33014K-page 241 . The file may be corrupted. Verify that filename exists and can be read. Library Filename is Required All commands require a library filename.com For evaluation only. The file is not a valid library file or it is corrupted.

http://www. Symbol 'symName' has multiple external definitions. 'memberName' is not a member of library 'filename'. 17. see MPLINK linker Section 14. Library file 'filename' has a missing member object file.foxitsoftware.5 “COFF File Errors”. The file not a valid object file or it may be corrupted.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. DS33014K-page 242 2009 Microchip Technology Inc. memberName can not be extracted or deleted from a library unless it is a member of the library. . A symbol may only be defined once in a library file.4 COFF FILE ERRORS For a list of COFF File Errors.

.foxitsoftware.Generated by Foxit PDF Creator © Foxit Software http://www......................................... Errors and Warnings ......................com For evaluation only.................. ASSEMBLER/LINKER/LIBRARIAN USER’S GUIDE Part 4 – Utilities Chapter 18... Utilities Overview and Usage ...................... DS33014K-page 243 .. 245 Chapter 19.................... 247 2009 Microchip Technology Inc.................

.com Assembler/Linker/Librarian User’s Guide NOTES: Generated by Foxit PDF Creator © Foxit Software For evaluation only.foxitsoftware. DS33014K-page 244 2009 Microchip Technology Inc.http://www.

modifies and extracts files from libraries. See Part 3 – “MPLIB Object Librarian” for more information. DS33014K-page 245 . Topics covered in this chapter: • • • • What are Utilities Utilities Operation mp2hex. debuggers and programmers.exe Utility 18. emulators.com For evaluation only.1 INTRODUCTION An overview of the 8-bit utilities and their capabilities are presented.Generated by Foxit PDF Creator © Foxit Software http://www. The MPLIB object librarian is a utility that was discussed in the previous sections. 18. Utilities Overview and Usage 18. Generates a Hex file from a COF file. FIGURE 18-1: UTILITIES OPERATION °®±¹ò½±º LINKER output file °®±¹ò¸»¨ °®±¹ò´­¬ Utility output files 2009 Microchip Technology Inc.3 UTILITIES OPERATION The utilities MP2HEX and MP2COD work with the MPLINK object linker to generate executable code (ò¸»¨) or a linker listing file (ò´­¬) from the linker COF file.foxitsoftware.exe Utility mp2cod. The Hex file is used by simulators.2 WHAT ARE UTILITIES Utilities are tools available for use with the assembler and/or linker. ASSEMBLER/LINKER/LIBRARIAN USER’S GUIDE Chapter 18. Generates a COD and list file from a COF file. TABLE 18-1: Utility ³°´·¾ò»¨» ³°î¸»¨ò»¨» ³°î½±¼ò»¨» AVAILABLE UTILITIES Description Creates.

EXE UTILITY Use this utility to take the MPLINK linker output COF file and create a COD file and a list file. The MPLINK linker ñ¨ option will result in the linker not using this utility. DS33014K-page 246 2009 Microchip Technology Inc.7. 18.http://www.) The MPLINK linker ñ© option will result in the linker not using this utility.foxitsoftware.lst)”.) A list file generated by this utility is specific to the linker (see Section 9.30”.6 “Listing File (.EXE UTILITY Use this utility to take the MPLINK linker output COF file and create a Hex file.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. A Hex file contains no debug information but may be programmed directly into a device.5. 18.3 “MPASM Assembler Versions before v3.5 MP2COD. A COD file is a legacy debug file that is no longer used (see Section 8.4 MP2HEX. .

or an existing hex file is write-protected. This file will not be present in the list file.com For evaluation only. 2009 Microchip Technology Inc. The hex file was never created due to other errors. If source level debugging for the file is desired. DS33014K-page 247 . 19. use INHX32 format! Your code addresses more than 64 Kbytes of program memory. rebuild the object or library on the current machine.foxitsoftware. Could not open hex file ‘filename’ for writing. • • • • Hex File Errors COFF To COD Conversion Errors COFF To COD Converter Warnings COD File Errors 19. but your selected hex format cannot support this. ASSEMBLER/LINKER/LIBRARIAN USER’S GUIDE Chapter 19. The referenced source file could not be opened.Generated by Foxit PDF Creator © Foxit Software http://www. 19. the COFF file must have either a code or a romdata section. Errors and Warnings 19.2 HEX FILE ERRORS Selected hex format does not support byte addresses above 64kb.1 INTRODUCTION Error messages and warning messages are produced by the 8-bit utilities. Could not open list file 'filename' for writing. These messages always appear in the listing file directly above each line in which the error occurred. The COD file name.4 COFF TO COD CONVERTER WARNINGS Could not open source file 'filename'. Verify that if filename exists and that it is not a read-only file. Coff file 'filename' must contain at least one 'code' or 'romdata' section. has a 63-character limit. This can happen if an input object/library module was built on a machine with a different directory structure. including the path. In order to convert a COFF file to a COD file. Switch to INHX32 format.3 COFF TO COD CONVERSION ERRORS Source file ‘filename’ name exceeds file format maximum of 63 characters.

Cod file 'filename' does not have a proper line info table. Please contact Microchip support if any of these errors are generated. • • • • • • • • • • • • • • Cod file 'filename' does not have a proper debug message table. Cod file 'filename' does not have a properly formed first directory. Cod file 'filename' does not have a proper local vars table. Could not open Cod file ‘filename’ for reading. Cod file 'filename' does not have a proper memory map table.http://www. Cod file 'filename' does not have a proper name table.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. . 19.5 COD FILE ERRORS All the COD file errors listed below indicate an internal error in the file's contents. Cod file 'filename' does not have a proper Index. Cod file 'filename' does not have a proper symbol table.foxitsoftware. Could not write directory in Cod file ‘filename’. Could not write ‘blockname’ block in Cod file ‘filename’. Cod file 'filename' does not have a properly formed linked directory. DS33014K-page 248 2009 Microchip Technology Inc. Could not open Cod file ‘filename’ for writing. Cod file 'filename' does not have a proper long symbol table.

Useful Tables ....... ASSEMBLER/LINKER/LIBRARIAN USER’S GUIDE Part 5 – Appendices Appendix A.....com For evaluation only.. DS33014K-page 249 ................ 251 Appendix B.....................................Generated by Foxit PDF Creator © Foxit Software http://www...... Instruction Sets ............... 267 2009 Microchip Technology Inc.................................foxitsoftware..........................................................

DS33014K-page 250 2009 Microchip Technology Inc.http://www.foxitsoftware. .com Assembler/Linker/Librarian User’s Guide NOTES: Generated by Foxit PDF Creator © Foxit Software For evaluation only.

com For evaluation only. PIC16X5X. Instruction Width 12 Bit 14 Bit 16 Bit Devices Supported PIC10F2XX. Port for TRIS.14-Bit Instruction Width Instruction Set . DS33014K-page 251 .12-Bit Instruction Width Instruction Set . µµµ 12-bit. constant data or label. Instructions listed here are grouped either by instruction width or device number.PIC18 Device Instruction Set .12-Bit/14-Bit Instruction Width Pseudo-Instructions • Key to PIC18 Device Instruction Set . Peripheral register file address (5-bit). MPLINK object linker and MPLIB object librarian. ASSEMBLER/LINKER/LIBRARIAN USER’S GUIDE Appendix A. It is the recommended form of use for compatibility with all Microchip software tools.PIC18 Device Extended Instruction Set A. The assembler will generate code with x = ð. PIC12CE67X. Don’t care (‘ð’ or ‘ï’). 7-bit or 8-bit). Pre-post increment-decrement mode selection. µ 4-bit. FSR or INDF number (0 or 1).1 INTRODUCTION PIC1X MCU instruction sets are used in developing applications with MPASM assembler. See ¼.14-Bit Instruction Width Extended Instruction Set . Literal field.foxitsoftware.Generated by Foxit PDF Creator © Foxit Software http://www. PIC12C5XX. PIC16C505 PIC12C67X. Register Files ¼»­¬ º ² ° ® ¨ Literals µ ³³ 2009 Microchip Technology Inc. µµ 8-bit. Instruction Sets A. PIC12CE5XX. Register file address (5-bit. PIC16X PIC18X Topics covered are: • Key to 12/14-Bit Instruction Width Instruction Sets .2 KEY TO 12/14-BIT INSTRUCTION WIDTH INSTRUCTION SETS Field Description Destination either the WREG register or the specified register file location. PIC12F629/675.

Z. Program Counter Upper Byte Latch. d = ð: store result in WREG d = ï: store result in file register f (default) Table pointer control. Power-down bit. . Bank Select Register. Table Latch (TBLAT) High Byte. Bit values. Watchdog Timer. Program Counter. Program Counter High Byte Latch. Overflow. · ­ ¬ ù ù Named Registers BSR OPTION PCL PCH PCLATH PCLATU PRODH PRODL TBLATH TBLATL TBLPTR WREG Named Bits C. i = ï: increment after instruction execution. t = ï: perform operation on upper byte. DC. Global Interrupt Enable bit(s). i = ð: do not change. N TO PD GIE PC TOS WDT Misc.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only.http://www. Program Counter Low Byte. s = ð: store result in file register f and WREG s = ï: store result in file register f (default) Table byte select. 16-bit Table Pointer (TBLPTRH:TBLPTRL). Field Bits ¾ ¼ Description Bit address within an 8-bit file register (0 to 7). Product of Multiply Low Byte. Used to select the current RAM bank.foxitsoftware. Program Counter High Byte. Negative. ALU Status bits: Carry. Destination select bit. Assigned to. OV. Working register (accumulator). Zero. t = ð: perform operation on lower byte. Product of Multiply High Byte. as opposed to Hex value. Time-out bit. Top-of-Stack. Table Latch (TBLAT) Low Byte. Descriptors ø . Digit Carry. Contents. Points to a Program Memory location. ä â ÷ Named Device Features DS33014K-page 252 2009 Microchip Technology Inc. Register bit field. Destination select bit. OPTION Register.

as well as the number of cycles per instruction.3 12-BIT INSTRUCTION WIDTH INSTRUCTION SET Microchip’s baseline 8-bit microcontroller family uses a 12-bit wide instruction set. The instruction set is grouped into the following categories: byte-oriented file register operations. skip if zero Inclusive OR W and f Move f Move W to f No operation Rotate left f Ý ®»¹·­¬»® º éòòòòòòð WREG + f 0 0 f-1 f-1 f+1 f+1 f f WREG dest dest dest.AND. see the relevant device data sheet. f dest f WREG íîº* ÎÎÚ ºô¼ Rotate right f Ý ®»¹·­¬»® º éòòòòòòð dest dest dest ðߺ* íߺ* ïߺ* ÍËÞÉÚ ÍÉßÐÚ ÈÑÎÉÚ ºô¼ ºô¼ ºô¼ Subtract W from f Swap halves f Exclusive OR W and f f .foxitsoftware. DS33014K-page 253 . All instructions execute in a single instruction cycle unless otherwise noted. Additionally.NOT.XOR. f Function dest dest ßÜÜÉÚ ßÒÜÉÚ ÝÔÎÚ ÝÔÎÉ ÝÑÓÚ ÜÛÝÚ ÜÛÝÚÍÆ ×ÒÝÚ ×ÒÝÚÍÆ ×ÑÎÉÚ ÓÑÊÚ ÓÑÊÉÚ ÒÑÐ ÎÔÚ ºô¼ ºô¼ º . Instructions. skip if zero Increment f Increment f. and core literal and control operations. status bits affected and complete instruction details. f WREG . bit-oriented file register operations.com For evaluation only. Instruction opcode is show in hex by making certain assumptions.OR.6 “12-Bit/14-Bit Instruction Width Pseudo-Instructions”. For more information on the opcode bit values for each instruction. instructions that apply to both 12-bit and 14-bit devices are shown in Section A.WREG f(0:3) f(4:7) WREG . either listed in the key or as a footnote. TABLE A-2: Hex 쾺 뾺 꾺 龺 ÞÝÚ ÞÍÚ ÞÌÚÍÝ ÞÌÚÍÍ 12-BIT BIT-ORIENTED FILE REGISTER OPERATIONS Mnemonic ºô¾ ºô¾ ºô¾ ºô¾ Bit clear f Bit set f Bit test. skip if clear Bit test. f * Assuming default bit value for d. skip if set Description 0 1 f(b) f(b) Function skip if f(b) = 0 skip if f(b) = 1 2009 Microchip Technology Inc.Generated by Foxit PDF Creator © Foxit Software http://www. Instruction Sets A. skip if zero dest WREG . TABLE A-1: Hex ïÛº* ïêº* ðêº ðìð îêº* ðÛº* îÛº* îߺ* íÛº* ïîº* îîº* ðîº ððð íêº* 12-BIT BYTE-ORIENTED FILE REGISTER OPERATIONS Mnemonic Description Add W and f AND W and f Clear f Clear W ºô¼ ºô¼ ºô¼ ºô¼ ºô¼ ºô¼ ºô¼ º ºô¼ Complement f Decrement f Decrement f. skip if zero dest dest. Any unused opcode is executed as a NOP.

f. . Additionally.6 “12-Bit/14-Bit Instruction Width Pseudo-Instructions”. skip if zero Increment f Increment f. For more information on the opcode bit values for each instruction.http://www. as well as the number of cycles per instruction. This instruction set consists of 36 instructions.AND. TABLE A-4: Hex ð鼺 ð뼺 ðïùïùº ð﨨 ð缺 ðí¼º ðÞ¼º ðß¼º ðÚ¼º ð켺 ð輺 ððùïùº ðððð ðܼº 14-BIT BYTE-ORIENTED FILE REGISTER OPERATIONS Mnemonic ßÜÜÉÚ ßÒÜÉÚ ÝÔÎÚ ÝÔÎÉ ÝÑÓÚ ÜÛÝÚ ÜÛÝÚÍÆ ×ÒÝÚ ×ÒÝÚÍÆ ×ÑÎÉÚ ÓÑÊÚ ÓÑÊÉÚ ÒÑÐ ÎÔÚ ºô¼ ºô¼ ºô¼ ºô¼ ºô¼ ºô¼ ºô¼ ºô¼ º ºô¼ ºô¼ º Description Add W and f AND W and f Clear f Clear W Complement f Decrement f Decrement f.foxitsoftware.OR. The instruction set is grouped into the following categories: byte-oriented file register operations. and core literal and control operations. see the relevant device data sheet. skip if 0 d d d W . kk Function WREG PC ßÒÜÔÉ ÝßÔÔ ÝÔÎÉÜÌ ÙÑÌÑ ×ÑÎÔÉ ÓÑÊÔÉ ÑÐÌ×ÑÒ ÎÛÌÔÉ ÍÔÛÛÐ ÌÎ×Í ÈÑÎÔÉ µµ µµ WDT (and Prescaler if assigned) PC(9 bits) WREG WREG OPTION Register PC WREG.XOR. WREG (accumulator).OR. and the working register.AND. f DS33014K-page 254 2009 Microchip Technology Inc. skip if zero Inclusive OR W and f Move f Move W to f No operation Rotate left f Ý ®»¹·­¬»® º éòòòòòòð W+f 0 0 f-1 f-1 f+1 f+1 f W d f f W d d d. The result can be directed either to the file register or the WREG register or to both in the case of some instructions. for example). either listed in the key or as a footnote. TOS kk . OR literal and W Move Literal to W Load OPTION Register Return with literal in W Go into Standby Mode Tristate port r Exclusive OR literal and W kk . WREG WREG WDT.com Assembler/Linker/Librarian User’s Guide TABLE A-3: Hex Ûµµ çµµ ððì ßµµ ܵµ ݵµ ððî èµµ ððí ðð® Úµµ Generated by Foxit PDF Creator © Foxit Software For evaluation only. each a single 14-bit wide word. 12-BIT LITERAL AND CONTROL OPERATIONS Mnemonic Description AND literal and W Call subroutine Clear watchdog timer µµ µµ µµ µµ ® µµ Goto address (k is nine bits) Incl. instructions that apply to both 12-bit and 14-bit devices are shown in Section A.NOT. WREG PC + 1 0 kk kk kk 0 TOS. skip if 0 d d. A few instructions operate solely on a file register (BSF. bit-oriented file register operations. stop oscillator I/O control reg r WREG WREG kk . f Function .4 14-BIT INSTRUCTION WIDTH INSTRUCTION SET Microchip’s midrange 8-bit microcontroller family uses a 14-bit wide instruction set. f W . status bits affected and complete instruction details. Most instructions operate on a file register. WREG A. Instruction opcode is show in hex by making certain assumptions.

f TABLE A-5: Hex 쾺 뾺 꾺 龺 14-BIT BIT-ORIENTED FILE REGISTER OPERATIONS Mnemonic ÞÝÚ ÞÍÚ ÞÌÚÍÝ ÞÌÚÍÍ ºô¾ ºô¾ ºô¾ ºô¾ Bit clear f Bit set f Bit test. stop oscillator WREG WREG I/O control reg r GIE PC kk .Generated by Foxit PDF Creator © Foxit Software http://www. TOS kk .XOR. kk Function WREG WREG PC WDT (and Prescaler if assigned) PC(9 bits) WREG WREG OPTION Register PC. WREG TOS.OR.com For evaluation only. skip if clear Bit test. DS33014K-page 255 . OR literal and W Move Literal to W Load OPTION register Return from Interrupt Return with literal in W Return from subroutine Go into Standby Mode Subtract W from literal Tristate port r Exclusive OR literal and W kk + WREG PC + 1 0 kk kk TOS kk TOS 0 kk .AND.XOR. 1 PC WDT. WREG WREG WREG. Instruction Sets Function ®»¹·­¬»® º TABLE A-4: Hex ðݼº 14-BIT BYTE-ORIENTED FILE REGISTER OPERATIONS (CONTINUED) Mnemonic ÎÎÚ ºô¼ Description Rotate right f Ý éòòòòòòð d f(4:7) d d ð ðÛ¼º ð꼺 ÍËÞÉÚ ÍÉßÐÚ ÈÑÎÉÚ ºô¼ ºô¼ ºô¼ Subtract W from f Swap halves f Exclusive OR W and f f-W f(0:3) W .WREG WREG kk .foxitsoftware. WREG 2009 Microchip Technology Inc. skip if set Description 0 1 f(b) f(b) Function skip if f(b) = 0 skip if f(b) = 1 TABLE A-6: Hex íÛµµ íçµµ îùðùµµµ ððêì îùïùµµµ íèµµ íðµµ ððêî ðððç íìµµ ðððè ððêí íݵµ ððê® íßµµ 14-BIT LITERAL AND CONTROL OPERATIONS Mnemonic ßÜÜÔÉ ßÒÜÔÉ ÝßÔÔ ÝÔÎÉÜÌ ÙÑÌÑ ×ÑÎÔÉ ÓÑÊÔÉ ÑÐÌ×ÑÒ ÎÛÌÚ×Û ÎÛÌÔÉ ÎÛÌËÎÒ ÍÔÛÛÐ ÍËÞÔÉ ÌÎ×Í ÈÑÎÔÉ µµ ® µµ µµ µµµ µµ µµ µµ µµ µµµ Description Add literal to W AND literal and W Call subroutine Clear watchdog timer Goto address (k is nine bits) Incl.

instructions that apply to both 12-bit and 14-bit devices are shown in Section A. Most instructions operate on a file register. bit-oriented skip operations. either listed in the key or as a footnote. The result can be directed either to the file register or the WREG register or to both in the case of some instructions. byte-oriented skip operations. core control operations.5 14-BIT INSTRUCTION WIDTH EXTENDED INSTRUCTION SET Some of Microchip’s midrange 8-bit microcontroller family use a 14-bit wide extended instruction set. Additionally. The instruction set is grouped into the following categories: byte-oriented file register operations. f W . bit-oriented file register operations. .http://www. A. core literal operations. WREG (accumulator). each a single 14-bit wide word.AND. TABLE A-7: Hex ð鼺 íܼº ð뼺 í鼺 14-BIT BYTE-ORIENTED FILE REGISTER OPERATIONS Mnemonic ßÜÜÉÚ ßÜÜÉÚÝ ßÒÜÉÚ ßÍÎÚ ºô¼ ºô¼ ºô¼ ºô¼ Description Add W and f Add with Carry W and f AND W with f Arithmatic Right Shift (1) (1) Function W+f d d d ®»¹·­¬»® º ³­¾ Ý W+f+C W .com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only.6 “12-Bit/14-Bit Instruction Width Pseudo-Instructions”. f. For more information on the opcode bit values for each instruction. (Consult your device data sheet to see if you device uses an extended instruction set.OR. see the relevant device data sheet. f d f ®»¹·­¬»® º Ý éòòòòòòð ðݼº ÎÎÚ ºô¼ Rotate right f Ý ®»¹·­¬»® º éòòòòòòð DS33014K-page 256 2009 Microchip Technology Inc. and the working register. f í뼺 ÔÍÔÚ ºô¼ Logical Left Shift(1) Ý ®»¹·­¬»® º éòòòòòòð ð í꼺 ÔÍÎÚ ºô¼ Logical Right Shift(1) ð ®»¹·­¬»® º éòòòòòòð f W d d d d Ý ðïùïùº ð﨨 ð缺 ðí¼º ðß¼º ð켺 ð輺 ððùïùº ðܼº ÝÔÎÚ ÝÔÎÉ ÝÑÓÚ ÜÛÝÚ ×ÒÝÚ ×ÑÎÉÚ ÓÑÊÚ ÓÑÊÉÚ ÎÔÚ º ºô¼ ºô¼ ºô¼ ºô¼ ºô¼ º ºô¼ Clear f Clear W Complement f Decrement f Increment f Inclusive OR W with f Move f Move W to f Rotate left f 0 0 f-1 f+1 f W .) This instruction set consists of 41 instructions. status bits affected and complete instruction details. as well as the number of cycles per instruction.foxitsoftware. A few instructions operate solely on a file register (BSF. core inherent operations and C-compiler optimized operations.NOT. Instruction opcode is show in hex by making certain assumptions. for example).

1 PC GIE PC PC PC ÞÎß ÞÎÉ ÝßÔÔ ÝßÔÔÉ ÙÑÌÑ ÎÛÌÚ×Û ÎÛÌÔÉ ÎÛÌËÎÒ µµ µµµ Relative branch with W Goto address (k is nine bits) PC(9 bits) WREG. TOS Operation in 14-bit extended instruction set but not 14-bit instruction set.WREG kk . skip if clear Bit test. kkk TOS. f Operation in 14-bit extended instruction set but not 14-bit instruction set. DS33014K-page 257 . skip if zero f-1 f+1 Function d. 2009 Microchip Technology Inc.AND. skip if set skip if f(b) = 0 skip if f(b) = 1 Function ÞÌÚÍÝ ÞÌÚÍÍ ºô¾ ºô¾ TABLE A-11: Hex íÛµµ íçµµ íèµµ ððîµ íïùïùµµ íðµµ íݵµ íßµµ Note 1: 14-BIT LITERAL OPERATIONS Mnemonic Description Add literal to W AND literal and W Incl. skip if zero Increment f. OR literal and W Move literal to BSR(1) Move literal to PCLATH(1) Move Literal to W Subtract W from literal Exclusive OR literal and W kk + WREG kk . Instruction Sets Function TABLE A-7: Hex ð íÞ¼º ðÛ¼º ð꼺 Note 1: 14-BIT BYTE-ORIENTED FILE REGISTER OPERATIONS (CONTINUED) Mnemonic ÍËÞÉÚ ÍËÞÉÚÞ ÍÉßÐÚ ÈÑÎÉÚ ºô¼ ºô¼ ºô¼ ºô¼ Description Subtract W from f Subtract with Borrow W from f Swap halves f Exclusive OR W and f (1) f-W f-W-B f(0:3) d d f(4:7) d d W .com For evaluation only. WREG k kk kk BSR PCLATH WREG WREG WREG kk . TABLE A-8: Hex ðÞ¼º ðÚ¼º 14-BIT BYTE-ORIENTED SKIP OPERATIONS Mnemonic ÜÛÝÚÍÆ ×ÒÝÚÍÆ ºô¼ ºô¼ Description Decrement f. TABLE A-12: Hex íîµµ ðððÞ îùðùµµµ ðððß îùïùµµµ ðððç íìµµ ðððè Note 1: 14-BIT CONTROL OPERATIONS Mnemonic Description Relative branch Call subroutine Call subroutine with W µµµ µµ Return from Interrupt Return with literal in W Return from subroutine (1) (1) (1) Function PC + kk PC + W PC + 1 PC + 1 kk TOS kk TOS PC PC TOS.XOR. WREG Function WREG WREG WREG ßÜÜÔÉ ßÒÜÔÉ ×ÑÎÔÉ ÓÑÊÔÞ ÓÑÊÔÐ ÓÑÊÔÉ ÍËÞÔÉ ÈÑÎÔÉ µµ µµ µµ µ µµ µµ µµ µµ kk . skip if 0 d. WREG Operation in 14-bit extended instruction set but not 14-bit instruction set.OR. W PC.Generated by Foxit PDF Creator © Foxit Software http://www. skip if 0 TABLE A-9: Hex 쾺 뾺 14-BIT BIT-ORIENTED FILE REGISTER OPERATIONS Mnemonic ÞÝÚ ÞÍÚ ºô¾ ºô¾ Bit clear f Bit set f Description 0 1 f(b) f(b) Function TABLE A-10: Hex 꾺 龺 14-BIT BIT-ORIENTED SKIP OPERATIONS Mnemonic Description Bit test.foxitsoftware.XOR.

stop oscillator I/O control reg r ÝÔÎÉÜÌ WREG TOS 0 WREG Go into Standby Mode Operation in 14-bit extended instruction set but not 14-bit instruction set. TABLE A-14: Hex íïùðù²µ ððïùðù³² ððïùðù²³ íÚùðù²µ ððïùïù³² ððïùïù²³ íÚùïù²µ Note 1: 14-BIT C-COMPILER OPTIMIZED OPERATIONS Mnemonic ßÜÜÚÍÎ ÓÑÊ×É ²ô µ ³³ ² ² ³³ µÅ²Ã ³³ ² ² ³³ µÅ²Ã Description Add Literal to FSRn (1) Function FSR(n) + k W FSR(n) Move INDFn to W. with pre/post inc/dec(1) W Move W to INDFn. with pre/post inc/dec(1) INDFn Move INDFn to W. ÓÑÊÉ× INDFn Operation in 14-bit extended instruction set but not 14-bit instruction set. with pre/post inc/dec Move INDFn to W. Indexed Indirect. Move W to INDFn.http://www. . Indexed Indirect.foxitsoftware. 14-BIT INHERENT OPERATIONS Mnemonic Description Clear watchdog timer No operation Load OPTION register Software device reset Tristate port r (1) Function 0 WDT (and Prescaler if assigned) OPTION Register PC WDT. DS33014K-page 258 2009 Microchip Technology Inc. with pre/post inc/dec Move W to INDFn.com Assembler/Linker/Librarian User’s Guide TABLE A-13: Hex ððêì ðððð ððêî ðððï ððêí ððê® Note 1: ÒÑÐ ÑÐÌ×ÑÒ ÎÛÍÛÌ ÍÔÛÛÐ ÌÎ×Í ® Generated by Foxit PDF Creator © Foxit Software For evaluation only.

These pseudo-instructions are alternative mnemonics for standard PIC1X instructions or are macros that generate one or more PIC1X instructions. Instruction Sets A.6 12-BIT/14-BIT INSTRUCTION WIDTH PSEUDO-INSTRUCTIONS The following pseudo-instructions are applicable to both the 12-bit and 14-bit instruction word devices.foxitsoftware. These are documented mainly for historical purposes. Use of these pseudo-instructions is not recommended for new designs.com For evaluation only. DS33014K-page 259 . TABLE A-15: Mnemonic ßÜÜÝÚ ßÜÜÜÝÚ Þ ÞÝ ÞÜÝ ÞÒÝ ÞÒÜÝ ÞÒÆ ÞÆ ÝÔÎÝ ÝÔÎÜÝ ÝÔÎÆ ÔÝßÔÔ µ 12-BIT/14-BIT SPECIAL INSTRUCTION MNEMONICS Description Add Carry to File Add Digit Carry to File Branch Branch on Carry Branch on Digit Carry Branch on No Carry Branch on No Digit Carry Branch on No Zero Branch on Zero Clear Carry Clear Digit Carry Clear Zero Long Call Equivalent Operation(s) ÞÌÚÍÝ ×ÒÝÚ ÞÌÚÍÝ ×ÒÝÚ ÙÑÌÑ ÞÌÚÍÝ ÙÑÌÑ ÞÌÚÍÝ ÙÑÌÑ ÞÌÚÍÍ ÙÑÌÑ ÞÌÚÍÍ ÙÑÌÑ ÞÌÚÍÍ ÙÑÌÑ ÞÌÚÍÝ ÙÑÌÑ ÞÝÚ ÞÝÚ ÞÝÚ ÞÝÚñÞÍÚ ÞÝÚñÞÍÚ ÝßÔÔ ÞÝÚñÞÍÚ ÞÝÚñÞÍÚ ÙÑÌÑ ÓÑÊÚ ÝÑÓÚ ×ÒÝÚ ÞÍÚ ÞÍÚ ÞÍÚ ÞÌÚÍÍ ÞÌÚÍÍ ÞÌÚÍÝ ÞÌÚÍÝ ÞÌÚÍÝ ÞÌÚÍÍ ÞÌÚÍÝ ÜÛÝÚ íôð ºô¼ íôï ºô¼ µ íôð µ íôï µ íôð µ íôï µ íôî µ íôî µ íôð íôï íôî ð¨ðßôí ð¨ðßôì µ ð¨ðßôí ð¨ðßôì µ ºôð ºôï ºô¼ íôð íôï íôî íôð íôï íôð íôï íôî íôî íôð ºô¼ Æ Æ ó ó ó ó ó ó ó ó ó Æ Status Æ Æ ó ó ó ó ó ó ó ó ó ó ºô¼ ºô¼ µ µ µ µ µ µ µ ÔÙÑÌÑ µ Long GOTO ÓÑÊÚÉ ÒÛÙÚ ÍÛÌÝ ÍÛÌÜÝ ÍÛÌÆ ÍÕÐÝ ÍÕÐÜÝ ÍÕÐÒÝ ÍÕÐÒÜÝ ÍÕÐÒÆ ÍÕÐÆ ÍËÞÝÚ º ºô¼ Move File to W Negate File Set Carry Set Digit Carry Set Zero Skip on Carry Skip on Digit Carry Skip on No Carry Skip on No Digit Carry Skip on Non Zero Skip on Zero ºô¼ Subtract Carry from File 2009 Microchip Technology Inc.Generated by Foxit PDF Creator © Foxit Software http://www.

¦ù 7-bit offset value for indirect addressing of register files (source). ºŒ 12-bit (0x000 to 0xFFF). constant data or label. ºù 12-bit (0x000 to 0xFFF). It is the recommended form of use for compatibility with all Microchip software tools. Literal field. Increments/Decrements ² ö öõ öó õö Bits ¿ ¾ ¼ ­ ù ù Named Registers BSR FSR PCL DS33014K-page 260 2009 Microchip Technology Inc. 0. ¦Œ 7-bit offset value for indirect addressing of register files (destination). This is the source address. µµµ 12-bit. File Select Register. . Program Counter Low Byte. as opposed to Hex value. Destination select bit d = ð: store result in WREG d = ï: store result in file register f (default) Fast Call/Return mode select bit s = ð: do not update into/from shadow registers (default) s = ï: certain registers loaded into/from shadow registers (Fast mode) Bit values. 12-BIT/14-BIT SPECIAL INSTRUCTION MNEMONICS (CONTINUED) Description Subtract Digit Carry from File Test File Equivalent Operation(s) ÞÌÚÍÝ ÜÛÝÚ ÓÑÊÚ íôï ºô¼ ºôï Status Æ Æ A. Used to select the current RAM bank.7 KEY TO PIC18 DEVICE INSTRUCTION SET Field Description Destination either the WREG register or the specified register file location.com Assembler/Linker/Librarian User’s Guide TABLE A-15: Mnemonic ÍËÞÜÝÚ ÌÍÌÚ ºô¼ º Generated by Foxit PDF Creator © Foxit Software For evaluation only. 1 or 2 for FSR number. The assembler will generate code with x = ð. See ¼. The mode of the TBLPTR register for the table read and table write instructions. º 8-bit (0x00 to 0xFF). Bank Select Register. The relative address (2’s complement number) for relative branch instructions. Only used with table read (TBLRD) and table write (TBLWT) instructions: No Change to register Post-Increment register Post-Decrement register Pre-Increment register RAM access bit a = ð: RAM location in Access RAM (BSR register is ignored) a = ï: RAM bank is specified by BSR register (default) Bit address within an 8-bit file register (0 to 7). µ 4-bit. Don’t care (‘ð’ or ‘ï’). This is the destination address. Indirect addressing offset. or the direct address for Call/Branch and Return instructions. Register Files ¼»­¬ º ® ¨ ¦ Literals µ Offsets.foxitsoftware.http://www. Register file address. µµ 8-bit.

f. N TO PD PEIE GIE. Program Counter High Byte Latch. DS33014K-page 261 . DC. Master clear device reset. Additionally. and the working register. Product of Multiply Low Byte. OV. Product of Multiply High Byte. Instruction Sets Field PCH PCLATH PCLATU PRODH PRODL STATUS TABLAT TBLPTR WREG Named Bits C. Watchdog Timer. Power-down bit. A few instructions operate solely on a file register (BSF. GIEL/H MCLR PC TOS WDT Misc. Top-of-Stack. extended mode instructions are shown in Section A. Global Interrupt Enable bit(s). each a single 16-bit wide word (2 bytes). Most instructions operate on a file register. bit-oriented file register operations. Instruction opcode is show in hex by making certain assumptions.com For evaluation only. see the relevant device data sheet. literal operations and memory operations. Working register (accumulator). Named Device Features A. Program Counter. Peripheral Interrupt Enable bit. This instruction set consists of 76 instructions. Program Counter High Byte.8 PIC18 DEVICE INSTRUCTION SET Microchip's new high-performance 8-bit microcontroller family uses a 16-bit wide instruction set. Program Counter Upper Byte Latch. Z. ALU Status bits: Carry. for example). Digit Carry. Descriptors ø ä â ÷ Contents. WREG (accumulator). The instruction set is grouped into the following categories: byte-oriented file register operations. For more information on the opcode bit values for each instruction. as well as the number of cycles per instruction.AND.Generated by Foxit PDF Creator © Foxit Software http://www. Description 21-bit Table Pointer (points to a Program Memory location). either listed in the key or as a footnote. Zero. control operations.9 “PIC18 Device Extended Instruction Set”. Negative. TABLE A-16: Hex îéºö îíºö ïéºö êÞºö PIC18 BYTE-ORIENTED REGISTER OPERATIONS Mnemonic Description ADD WREG to f ADD WREG and Carry bit to f AND WREG with f Clear f WREG+f WREG+f+C WREG .foxitsoftware. status bits affected and complete instruction details. The result can be directed either to the file register or the WREG register or to both in the case of some instructions. Time-out bit. Register bit field. f 0 f dest dest dest Function ßÜÜÉÚ ßÜÜÉÚÝ ßÒÜÉÚ ÝÔÎÚ ºô¼ô¿ ºô¼ô¿ ºô¼ô¿ ºô¿ 2009 Microchip Technology Inc. Assigned to. Overflow. Status Register 8-bit Table Latch.

. skip if 0 Decrement f. DS33014K-page 262 2009 Microchip Technology Inc. f * Assuming default bit values for d and a. if f < WREG.http://www.NOT. PC+4 PC PC WREG WREG * f -f f ®»¹·­¬»® º éòòòòòòð ìéºö ÎÔÒÝÚ ºô¼ô¿ Rotate left f (no carry) ®»¹·­¬»® º éòòòòòòð ííºö ÎÎÝÚ ºô¼ô¿ Rotate right f through Carry Ý ®»¹·­¬»® º éòòòòòòð ìíºö ÎÎÒÝÚ ºô¼ô¿ Rotate right f (no carry) ®»¹·­¬»® º éòòòòòòð êçºö ëéºö ëÚºö ëÞºö íÞºö êéºö ïÞºö ÍÛÌÚ ÍËÞÚÉÞ ÍËÞÉÚ ÍËÞÉÚÞ ÍÉßÐÚ ÌÍÌÚÍÆ ÈÑÎÉÚ ºô¿ ºô¼ô¿ ºô¼ô¿ ºô¼ô¿ ºô¼ô¿ ºô¿ ºô¼ô¿ Set f Subtract f from WREG with Borrow Subtract WREG from f Subtract WREG from f with Borrow Swap nibbles of f Test f. if dest=0.foxitsoftware. skip if f=WREG .OR. skip if f < f–WREG.XOR. f f f' dest f” f PRODH:PRODL dest 0. PIC18 BYTE-ORIENTED REGISTER OPERATIONS (CONTINUED) Mnemonic Description Complement f Compare f with WREG. PC+4 f+1 PC else PC+2 f+1 dest. skip if 0 Increment f. f<7:4> PC. PC+4 WREG else PC+2 PC Decrement f Decrement f.com Assembler/Linker/Librarian User’s Guide TABLE A-16: Hex ïÚºö êíºö êëºö êïºö ðéºö îÚºö ìÚºö îÞºö íÚºö ìÞºö ïíºö ëíºö ݺù ÚºŒ êÚºö ðíºö êܺö íéºö Generated by Foxit PDF Creator © Foxit Software For evaluation only. skip if not 0 Inclusive OR WREG with f Move f Move f' to fd” (second word) Move WREG to f Multiply WREG with f Negate f Rotate left f through Carry Ý f–1 dest f–1 dest. PC+4 WREG else PC+2 PC Compare f with WREG. PC+4 else PC+2 PC ÝÑÓÚ ÝÐÚÍÛÏ ÝÐÚÍÙÌ ÝÐÚÍÔÌ ÜÛÝÚ ÜÛÝÚÍÆ ÜÝÚÍÒÆ ×ÒÝÚ ×ÒÝÚÍÆ ×ÒÚÍÒÆ ×ÑÎÉÚ ÓÑÊÚ ÓÑÊÚÚ ÓÑÊÉÚ ÓËÔÉÚ ÒÛÙÚ ÎÔÝÚ ºô¼ô¿ ºô¿ ºô¿ ºô¿ ºô¼ô¿ ºô¼ô¿ ºô¼ô¿ ºô¼ô¿ ºô¼ô¿ ºô¼ô¿ ºô¼ô¿ ºô¼ô¿ ºùôºŒ ºô¿ ºô¿ ºô¿ ºô¼ô¿ Compare f with WREG. if dest else PC+2 PC f+1 dest 0. if dest=0. PC+4 else PC+2 PC f–1 dest. if f=0. skip if not 0 Increment f Increment f. f dest PC PC PC Function f–WREG. else PC+2 dest WREG . skip if f > f–WREG. if f=WREG. PC+4 PC PC dest. if dest else PC+2 PC WREG . if f > WREG. skip if 0 Exclusive OR WREG with f 0xFF f dest dest dest dest<3:0> PC WREG–f–C f–WREG f–WREG–C f<3:0> PC+4 dest<7:4>.

else WREG<3:0> if WREG<7:4> >9 or C=1. else PC+2 if N=0. 0 WDT postscaler. WREGs WREG. else PC+2 if OV=0. WREG<3:0>. PD TO. STATUSs STATUS.Generated by Foxit PDF Creator © Foxit Software http://www. PC+4 f<b> f<b> * Assuming b = 0 and default bit value for a. PC+2+2*n PC. if s=1. STATUS STATUSs. else PC+2 PC+2+2*n PC if Z=1. else WREG<7:4> WREG<7:4>. WREG<7:4>+6 WREG<7:4>. 1 GIE/GIEH or PEIE/GIEL. skip if clear Bit test f.else PC+2 PC if C=0.1 BSRs ÝÔÎÉÜÌ ÜßÉ Clear Watchdog Timer Decimal Adjust WREG if WREG<3:0> >9 or DC=1. BSR 0 1 WDT. skip if set Bit Toggle f Description 0 1 f<b> f<b> PC PC. STATUSs STATUS. TABLE A-18: Hex Ûî² Ûê² Ûí² Ûé² Ûë² Ûï² Ûì² Üùðù² Ûð² Ûݵµö Úµµµ ðððì ðððé ÞÝ ÞÒ ÞÒÝ ÞÒÒ ÞÒÑÊ ÞÒÆ ÞÑÊ ÞÎß ÞÆ ÝßÔÔ PIC18 CONTROL OPERATIONS Mnemonic ² ² ² ² ² ² ² ² ² ²ô­ Description Branch if Carry Branch if Negative Branch if Not Carry Branch if Not Negative Branch if Not Overflow Branch if Not Zero Branch if Overflow Branch Unconditionally Branch if Zero Call Subroutine 1st word 2nd word if C=1. Instruction Sets Function TABLE A-17: Hex çïºö èïºö Þïºö ßïºö éïºö ÞÝÚ ÞÍÚ ÞÌÚÍÝ ÞÌÚÍÍ ÞÌÙ PIC18 BIT-ORIENTED REGISTER OPERATIONS Mnemonic ºô¾ô¿ ºô¾ô¿ ºô¾ô¿ ºô¾ô¿ ºô¾ô¿ Bit Clear f Bit Set f Bit test f. n PC<20:1> ÛÚµµ Úµµµ ðððð Ú¨¨¨ ðððê ðððë Üùïù² ððÚÚ ððïðö ÙÑÌÑ ÒÑÐ ÒÑÐ ÐÑÐ ÐËÍØ ÎÝßÔÔ ÎÛÍÛÌ ÎÛÌÚ×Û ² Go to address No Operation No Operation 1st word 2nd word No Operation No Operation (2-word instructions) TOS-1 PC +2 PC+2 TOS TOS TOS. BSRs BSR. 0 WDT postscaler.com For evaluation only. n PC<20:1>. else PC+2 PC PC PC PC PC PC PC if N=1. PC+2+2*n PC Pop top of return stack (TOS) Push top of return stack (TOS) ² ­ Relative Call Software device reset Return from interrupt (and enable interrupts) Return from subroutine Same as MCLR reset TOS PC. PCLATU/PCLATH are unchanged 0 1 WDT. DS33014K-page 263 . else PC+2 PC+4 TOS. TO. 0 PD ððïîö ÎÛÌËÎÒ ­ ðððí ÍÔÛÛÐ Enter SLEEP Mode * Assuming default bit value for s.foxitsoftware. 2009 Microchip Technology Inc. PC+2+2*n PC. PC+2+2*n PC. else PC+2 if Z=0. PC+2+2*n PC. WREG WREGs. PC+2+2*n PC. else PC+2 if f<b>=1. PC+2+2*n Function PC. else PC+2 if OV=1. PC+2+2*n PC. if s=1. PC+4 PC. BSRs BSR. WREGs WREG. PC+2+2*n PC. PCLATU/PCLATH unchngd. if s=1. WREG<3:0>+6 WREG<3:0>. else PC+2 PC if f<b>=0. TOS PC.

OR. kk WREG . kk TABLE A-20: Hex ðððè ðððç ðððß ðððÞ ðððÝ ðððÜ ðððÛ ðððÚ PIC18 MEMORY OPERATIONS Description Table Read Table Read with post-increment Table Read with post-decrement Table Read with pre-increment Table Write Table Write with post-increment Table Write with post-decrement Table Write with pre-increment Function Prog Mem (TBLPTR) TABLAT Prog Mem (TBLPTR) TABLAT TBLPTR TBLPTR +1 Prog Mem (TBLPTR) TABLAT TBLPTR -1 TBLPTR TBLPTR +1 TBLPTR TABLAT Prog Mem (TBLPTR) TABLAT Prog Mem(TBLPTR) TABLAT Prog Mem(TBLPTR) TBLPTR TBLPTR +1 TABLAT Prog Mem(TBLPTR) TBLPTR -1 TBLPTR TBLPTR +1 TBLPTR TABLAT Prog Mem(TBLPTR) Mnemonic ÌÞÔÎÜö ÌÞÔÎÜöõ ÌÞÔÎÜöó ÌÞÔÎÜõö ÌÞÔÉÌö ÌÞÔÉÌöõ ÌÞÔÉÌöó ÌÞÔÉÌõö DS33014K-page 264 2009 Microchip Technology Inc. kk kk kk kk kk FSRr BSR WREG PRODH:PRODL WREG WREG WREG Function WREG WREG WREG WREG * kk kk–WREG WREG .com Assembler/Linker/Librarian User’s Guide TABLE A-19: Hex ðÚµµ ðÞµµ ðçµµ ÛÛ®µ Úðµµ ðïðµ ðÛµµ ðܵµ ðݵµ ðèµµ ðßµµ ßÜÜÔÉ ßÒÜÔÉ ×ÑÎÔÉ ÔÚÍÎ ÓÑÊÔÞ ÓÑÊÔÉ ÓËÔÔÉ ÎÛÌÔÉ ÍËÞÔÉ ÈÑÎÔÉ Generated by Foxit PDF Creator © Foxit Software For evaluation only. .AND.foxitsoftware. PIC18 LITERAL OPERATIONS Mnemonic µµ µµ µµ ®ôµµ µ µµ µµ µµ µµ µµ Description Add literal to WREG AND literal with WREG Inclusive OR literal with WREG Move literal (12 bit) 2nd word to FSRr 1st word Move literal to BSR<3:0> Move literal to WREG Multiply literal with WREG Return with literal in WREG Subtract WREG from literal Exclusive OR literal with WREG WREG+kk WREG .http://www.XOR.

9 PIC18 DEVICE EXTENDED INSTRUCTION SET Some PIC18 devices have an extended mode of operation for use with the MPLAB C18 compiler. (TOS) PC PCU ßÜÜÚÍÎ ßÜÜËÔÒÕ ÝßÔÔÉ ÓÑÊÍÚ ÓÑÊÍÍ ÐËÍØÔ ÍËÞÚÍÎ ÍËÞËÔÒÕ ºôµ µ TOS. as well as the number of cycles per instruction. f” (destination)2nd word Move z’ (source) to 1st word. For more on extended mode. TABLE A-21: Hex Û躵 Ûèݵ ððïì ÛÞŽðŽ¦ Úººº Ûގ Ú¨¦¦ Ûßµµ Û纵 Ûçݵ PIC18 EXTENDED INSTRUCTIONS Mnemonic Description Add literal to FSR Add literal to FSR2 and return Call subroutine using WREG ¦ŽôºŒ ¦Žô¦Œ µ ºôµ µ Move z’ (source) to 1st word. either listed in the key or as a footnote. However. This mode will change the operation of some instructions listed in Section A. Instruction Sets A. For more information on the opcode bit values for each instruction. (TOS) PC 2009 Microchip Technology Inc.Generated by Foxit PDF Creator © Foxit Software http://www. Instruction opcode is shown in hex by making certain assumptions. the extended mode is set using a special device configuration bit. (PC + 2) (PCLATH) PCH. decrement FSR2 Subtract literal from FSR Subtract literal from FSR2 and return FSR(f)+k FSR2+k Function FSR(f) FSR2. FSR2-1 FSR2 FSR(f-k) FSR2-k FSR(f) FSR2. (PCLATU) ((FSR2)+z’) ((FSR2)+z’) f” ((FSR2)+z”) k FSR2). z” (destination)2nd word Store literal at FSR2. status bits affected and complete instruction details. see the MPLAB C18 C Compiler User’s Guide (DS51288) and your device data sheet.com For evaluation only. see the relevant device data sheet. you should not need to use the extended instruction set. In general.foxitsoftware. DS33014K-page 265 .8 “PIC18 Device Instruction Set” and add the instructions listed in this section. (W) PCL. if needed.

http://www. DS33014K-page 266 2009 Microchip Technology Inc.com Assembler/Linker/Librarian User’s Guide NOTES: Generated by Foxit PDF Creator © Foxit Software For evaluation only. .foxitsoftware.

< = > ? 4 @ A B C D E F G H I J K L M N O 5 P Q R S T U V W X Y Z [ \ ] ^ _ 6 ` a b c d e f g h i j k l m n o 7 p q r s t u v w x y z { | } ~ DEL 2009 Microchip Technology Inc.Generated by Foxit PDF Creator © Foxit Software http://www.2 ASCII CHARACTER SET Most Significant Nibble HEX 0 1 2 3 4 5 6 7 8 9 A B C D E F 0 NUL SOH STX ETX EOT ENQ ACK Bell BS HT LF VT FF CR SO SI 1 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US 2 Space ! " # $ % & ' ( ) * + . DS33014K-page 267 . The tables are: • ASCII Character Set • Hexadecimal to Decimal Conversion B.com For evaluation only. Useful Tables B.foxitsoftware.1 INTRODUCTION Some useful tables are included for reference here. – . / 3 0 1 2 3 4 5 6 7 8 9 : . ASSEMBLER/LINKER/LIBRARIAN USER’S GUIDE Appendix B.

B. Add the numbers together High Byte HEX 1000 0 1 2 3 4 5 6 7 8 9 A B C D E F Dec 0 4096 8192 12288 16384 20480 24576 28672 32768 36864 40960 45056 49152 53248 57344 61440 HEX 100 0 1 2 3 4 5 6 7 8 9 A B C D E F Dec 0 256 512 768 1024 1280 1536 1792 2048 2304 2560 2816 3072 3328 3584 3840 HEX 10 0 1 2 3 4 5 6 7 8 9 A B C D E F Low Byte Dec 0 16 32 48 64 80 96 112 128 144 160 176 192 208 224 240 HEX 1 0 1 2 3 4 5 6 7 8 9 A B C D E F Dec 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 For example. For each HEX digit. HEX A38F converts to 41871 as follows: HEX 1000’s Digit ìðçêð HEX 100’s Digit éêè HEX 10’s Digit ïîè HEX 1’s Digit ïë Result ìïèéï Ü»½·³¿´ DS33014K-page 268 2009 Microchip Technology Inc.3 HEXADECIMAL TO DECIMAL CONVERSION This appendix describes how to convert hexadecimal to decimal. .foxitsoftware. find the associated decimal value.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only.http://www.

Archiver A tool that creates and manipulates libraries. …. Alphanumeric Alphanumeric characters are comprised of alphabetic characters and decimal digits (0. Assembler A language tool that translates assembly language source code into machine code. DS33014K-page 269 . Assembly Language A programming language that describes binary machine code in a symbolic form. Hardware An event whose execution will cause a halt. Access Memory (PIC18 Only) Special registers on PIC18 devices that allow access regardless of the setting of the bank select register (BSR). B. Alphabetic Character Alphabetic characters are those characters that are letters of the arabic alphabet (a. b. Breakpoint. Z).Generated by Foxit PDF Creator © Foxit Software http://www. and then using the archiver to combine the object files into one library file. Software 2009 Microchip Technology Inc. 9).1. Breakpoint. ANSI American National Standards Institute is an organization responsible for formulating and approving standards in the United States. A. Application A set of software and hardware that may be controlled by a PIC microcontroller. It includes upper and lower case letters. z. Address Value that identifies a location in memory.foxitsoftware. Archive A collection of relocatable object modules. …. Asynchronous Stimulus Data generated to simulate external inputs to a simulator device. ….com For evaluation only. digits. ASCII American Standard Code for Information Interchange is a character set encoding that uses 7 binary digits to represent each character. ASSEMBLER/LINKER/LIBRARIAN USER’S GUIDE Glossary Absolute Section A section with a fixed (absolute) address that cannot be changed by the linker. symbols and control characters. A library can be linked with object modules and other libraries to create executable code. It is created by assembling multiple source files to object files.

Configuration Bits Special-purpose bits programmed to set PIC1X microcontroller modes of operation. Microchip dsPIC DSC devices. Digital Signal Controller A microcontroller device with digital signal processing capability. and a rich set of operators. Calibration Memory A special function register or registers used to hold values for calibration of a PIC1X microcontroller on-board RC oscillator or other device peripherals. COFF Common Object File Format.e. the first file listed is the location of the definition. Cross Reference File A file that references a table of symbols and a list of files that references the symbol. Directives Statements in source code that provide control of the language tool’s operation. A configuration bit may or may not be preprogrammed..foxitsoftware. by meaningful names. Device Programmer A tool used to program electrically programmable semiconductor devices such as microcontrollers.http://www. An address where execution of the firmware will halt. data memory (RAM) is comprised of general purpose registers (GPRs) and special function registers (SFRs). Data Memory On Microchip MCU and DSC devices. Control Directives Directives in assembly language code that cause code to be included or omitted based on the assembly-time value of a specified expression. modern control flow and data structures. C A general-purpose programming language which features economy of expression. i. that is. If the symbol is defined. Build Compile and link all the source files for an application. Some devices also have EEPROM data memory. The remaining files contain references to the symbol. Data Directives Data directives are those that control the assembler’s allocation of program or data memory and provide a way to refer to data items symbolically. Download DS33014K-page 270 2009 Microchip Technology Inc. . Compiler A program that translates a source file written in a high-level language into machine code. An object file of this format contains machine code. Command Line Interface A means of communication between a program and its user based solely on textual input and output. debugging and other information. Usually achieved by a special break instruction.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only.

2009 Microchip Technology Inc. EPROM Erasable Programmable Read Only Memory. EEPROM Electrically Erasable Programmable Read Only Memory.com For evaluation only. Environment . breakpoints and interrupts. DSC See Digital Signal Controller. Export Send data out of the MPLAB IDE in a standardized format. This folder can be transferred to a SD/MMC card.foxitsoftware. processor module. and time stamp. and MPLAB IDE software. EEPROM retains its contents even when power is turned off. ELF/DWARF provide better debugging of optimized code than COFF. Emulation The process of executing software loaded into emulation memory as if it were firmware residing on a microcontroller device. Emulator System The MPLAB ICE 2000 and 4000 emulator systems include the pod. External Label A label that has external linkage. R/W). cables. pass count. such as an emulator. on-chip program memory as well as external memory is available. External Linkage A function or variable has external linkage if it can be referenced from outside the module in which it is defined.MPLAB PM3 A folder containing files on how to program a device. device adapter. cycle type (fetch. Glossary Download is the process of sending data from a host to another device.Generated by Foxit PDF Creator © Foxit Software http://www. Data is written or erased one byte at a time. A special type of PROM that can be erased electrically. data. programmer or target board. Debugging and other information is specified in with DWARF. Environment .IDE The particular layout of the desktop for application development. Events are used to describe triggers. Emulator Hardware that performs emulation. A programmable read-only memory that can be erased usually by exposure to ultraviolet radiation. Execution automatically switches to external if the program memory address is greater than the internal memory space of the PIC17 or PIC18 device. external input. DS33014K-page 271 . Extended Microcontroller Mode In extended microcontroller mode. Emulation Memory Program memory contained within the emulator. Event A description of a bus cycle which may include address. An object file of this format contains machine code.

MPLAB ICE 2000 and 4000 are Microchip’s in-circuit emulators. Filter Determine by selection what data is included/excluded in a trace display or data file. this prefetched instruction is explicitly ignored. File Registers On-chip data memory. ICE In-Circuit Emulator. A symbol for an identifier which has external linkage. causing a forced NOP cycle. External RAM Off-chip Read/Write memory. However. Hex code is contained in a hex file. A forced NOP cycle is the second cycle of a two-cycle instruction. Executing Halt is the same as stopping at a breakpoint. Halt A stop of program execution. ICD In-Circuit Debugger. High Level Language A language for writing programs that is further removed from the processor than assembly. This may be a reference or a definition. The portion of device data memory (RAM) available for general use. . FNOP Forced No Operation.foxitsoftware. External Input Line An external input signal logic probe line (TRIGIN) for setting an event based upon external signals. IDE DS33014K-page 272 2009 Microchip Technology Inc. it prefetches the next instruction in the physical address space while it is executing the current instruction.com Assembler/Linker/Librarian User’s Guide External Symbol Generated by Foxit PDF Creator © Foxit Software For evaluation only. Any external symbol references which do not have a corresponding definition cause a linker error to be reported. MPLAB ICD 2 is Microchip’s in-circuit debugger. Since the PIC microcontroller architecture is pipelined. if the current instruction changes the program counter. Hex Code Executable instructions stored in a hexadecimal format code. including general purpose registers (GPRs) and special function registers (SFRs). Hex File An ASCII file containing hexadecimal addresses and values (hex code) suitable for programming a device. Flash A type of EEPROM where data is written or erased in blocks instead of bytes. GPR General Purpose Register.http://www. External Symbol Resolution A process performed by the linker in which external symbol definitions from all input modules are collected in an attempt to resolve all external symbol references.

Instructions A sequence of bits that tells a central processing unit to perform a particular operation and can contain data to be used in the operation. They define linker options and describe available memory on the target platform. 2009 Microchip Technology Inc.foxitsoftware. Librarian See Archiver. including computing and communications. Linker A language tool that combines object files and libraries to create executable code. Instruction Set The collection of machine language instructions that a particular processor understands. IRQ See Interrupt Request. Interrupt Handler A routine that processes special code when an interrupt occurs. Glossary Integrated Development Environment. Interrupt Request An event which causes the processor to temporarily suspend normal instruction execution and to start executing an interrupt handler routine. ISR See Interrupt Service Routine. Import Bring data into the MPLAB IDE from an outside source. DS33014K-page 273 .Generated by Foxit PDF Creator © Foxit Software http://www. resolving references from one module to another. Linker Script Files Linker script files are the command files of a linker. International Organization for Standardization An organization that sets standards in many businesses and technologies. MPLAB IDE is Microchip’s integrated development environment. Interrupt A signal to the CPU that suspends the execution of a running application and transfers control to an Interrupt Service Routine (ISR) so that the event may be processed. ISO See International Organization for Standardization. such as from a hex file.com For evaluation only. Some processors have several interrupt request events allowing different priority interrupts. Library See Archive. Internal Linkage A function or variable has internal linkage if it can not be accessed from outside the module in which it is defined. Interrupt Service Routine User-generated code that is entered when an interrupt occurs. The location of the code in program memory will usually depend on the type of interrupt that has occurred.

Logic Probes Up to 14 logic probes can be connected to some Microchip emulators. only internal execution is allowed.com Assembler/Linker/Librarian User’s Guide Listing Directives Generated by Foxit PDF Creator © Foxit Software For evaluation only. Microprocessor Mode DS33014K-page 274 2009 Microchip Technology Inc. The collection of all possible instructions for a particular processor is known as its “instruction set”. A program in binary machine code consists of a sequence of machine instructions (possibly interspersed with data). the symbols and labels that are declared as local are no longer accessible after the ENDM macro is encountered. A message will not stop operation. An instruction that represents a sequence of instructions in abbreviated form. I/O ports and timers. In other words. or macro encountered in a source file. +5V. Message Text displayed to alert you to potential problems in language tool operation. pagination and other listing control. trigger output signal. The logic probes provide external trace inputs. designed to be usable by a processor without being translated. Machine Code The representation of a computer program that is actually read and interpreted by the processor. An abbreviation for microcontroller. Machine Language A set of instructions for a specific central processing unit. These labels are particular to a given instance of a macro’s instantiation. In microcontroller mode. Listing File A listing file is an ASCII text file that shows the machine code generated for each C source statement. RAM. Macro Macroinstruction. They allow the specification of titles. Thus. Macro Directives Directives that control the execution and data allocation within macro body definitions. Microcontroller A highly integrated chip that contains a CPU. program memory.http://www. Also uC. only the on-chip program memory is available in microcontroller mode. assembly instruction. MCU Microcontroller Unit. Local Label A local label is one that is defined inside a macro with the LOCAL directive.foxitsoftware. assembler directive. . re-compiling only those source files that have changed since the last complete compilation. and a common ground. Microcontroller Mode One of the possible program memory configurations of PIC17 and PIC18 microcontrollers. Listing directives are those directives that control the assembler listing file format. Make Project A command that rebuilds an application.

MPLAB ICE 2000 supports PIC1X MCUs. cables. Will obsolete PRO MATE II. MPLAB LIB30 MPLAB LIB30 archiver/librarian is an object librarian for use with COFF object modules created using either MPLAB ASM30 or MPLAB C30 C compiler. The entire program memory is mapped externally. A complete system consists of a module. DS33014K-page 275 . KeeLoq devices and Microchip memory devices. MPLAB SIM Microchip’s simulator that works with MPLAB IDE in support of PIC MCU and dsPIC DSC devices. MPLAB ICD 2 Microchip’s in-circuit debugger that works with MPLAB IDE. MPLAB LINK30 MPLAB LINK30 is an object linker for the Microchip MPLAB ASM30 assembler and the Microchip MPLAB C30 C compiler. MPLINK Object Linker 2009 Microchip Technology Inc. MPLIB Object Librarian MPLIB librarian is an object librarian for use with COFF object modules created using either MPASM assembler or MPLAB C1X C compilers. In microprocessor mode. MPASM Assembler Microchip Technology’s relocatable macro assembler for PIC1X microcontroller devices. MPLAB C30 Microchip’s C compiler for dsPIC30F digital signal controller devices. header. Glossary One of the possible program memory configurations of PIC17 and PIC18 microcontrollers.Generated by Foxit PDF Creator © Foxit Software http://www. MPLAB PM3 A device programmer from Microchip. MPLAB C1X Refers to both the MPLAB C17 and MPLAB C18 C compilers from Microchip. Can be used with MPLAB IDE or stand-alone. demo board.com For evaluation only. MPLAB IDE Microchip’s Integrated Development Environment. the on-chip program memory is not used. and MPLAB IDE Software. processor module.foxitsoftware. cables. MPLAB ICE 4000 supports PIC18F MCUs and dsPIC30F DSCs. The ICD supports Flash devices with built-in debug circuitry. Mnemonics Text instructions that can be translated directly into machine code. The main component of each ICD is the module. MPLAB ICE 2000/4000 Microchip’s in-circuit emulators that works with MPLAB IDE. MPLAB ASM30 Microchip’s relocatable macro assembler for dsPIC30F digital signal controller devices. and MPLAB IDE Software. Also referred to as Opcodes. A complete system consists of a pod. Programs PIC18 microcontrollers and dsPIC digital signal controllers. MPLAB C17 is the C compiler for PIC17 devices and MPLAB C18 is the C compiler for PIC18 devices. The main component of each ICE is the pod.

http://www.. to produce a complete executable program. the event is satisfied. Nesting Depth The maximum level to which macros can include other macros. MPLINK linker is an object linker for the Microchip MPASM assembler and the Microchip MPLAB C17 or C18 C compilers. Object Code The machine code generated by an assembler or compiler. It may be immediately executable or it may be relocatable. Refers to files and windows available to be selected from MPLAB IDE main pull down menus. and to any sequential event in the complex trigger dialog. only windowed devices are erasable. An instruction that has no effect when executed except to advance the program counter. You can assign the Pass Counter to break and trace logic. Pass Counter A counter that decrements each time an event (such as the execution of an instruction at a particular address) occurs. OTP One Time Programmable. . MRU Most Recently Used. though it does not have to be. When the pass count value reaches zero. Non Real-Time Refers to the processor at a breakpoint or executing single step instructions or MPLAB IDE being run in simulator mode. Opcodes Operational Codes. Object File A file containing machine code and possibly debug information. or where all program memory may be supplied by the Emulator. MPLINK linker also may be used with the Microchip MPLIB librarian.g. Each operator has an assigned precedence that is used to determine order of evaluation. e. DS33014K-page 276 2009 Microchip Technology Inc. NOP No Operation.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only. EPROM devices that are not in windowed packages.foxitsoftware. Off-Chip Memory Off-chip memory refers to the memory selection option for the PIC17 or PIC18 device where memory may reside on the target board. that are used when forming well-defined expressions. Node MPLAB IDE project component. Operators Symbols. like the plus sign ‘+’ and the minus sign ‘-’. libraries. requiring linking with other object files. See Mnemonics. MPLINK linker is designed to be used with MPLAB IDE. Object File Directives Directives that are used only when creating an object file. Non-Volatile Storage A storage device whose contents are preserved when its power is off. Since EPROM needs ultraviolet light to erase its memory.

14-. Qualifier An address or an address range used by the Pass Counter or as an event before another operation in a complex trigger. Pod. the memory in the emulator or simulator containing the downloaded target application firmware. Memory in which information can be accessed in any order. 28-. and trace/breakpoint logic. PC Host Any IBM or compatible personal computer running a supported Windows operating system.com For evaluation only. Project A set of source files and instructions to build the object and executable code for an application. Power-on-Reset Emulation A software randomization process that writes random values in data RAM areas to simulate uninitialized values in RAM upon initial power application. Radix The number base. Can be used with MPLAB IDE or stand-alone. event and cycle timers. Prototype System A term referring to a user's target application. Programs 8-. PICSTART Plus A developmental device programmer from Microchip. Emulator The external emulator box that contains emulation memory. DS33014K-page 277 . PRO MATE II A device programmer from Microchip. RAM Random Access Memory (Data Memory). or decimal. and 40-pin PIC1X microcontrollers. Programs most PIC1X microcontrollers as well as most memory and Keeloq devices. 2009 Microchip Technology Inc.Generated by Foxit PDF Creator © Foxit Software http://www. trace memory. used in specifying an address. Program Memory The memory area in a device where instructions are stored. or target board. PIC1X MCUs refer to 8-bit PIC10/12/16/18 devices. a summary listing of executed stimulus by register. Certain PIC MCU devices have a PWM peripheral. Must be used with MPLAB IDE Software. PWM Signals Pulse Width Modulation Signals. Profile For MPLAB SIM simulator. PIC MCUs PIC microcontrollers (MCUs) refer to all Microchip microcontroller families. Glossary PC Personal Computer or Program Counter. Program Counter The location that contains the address of the instruction that is currently executing. hex. Also.foxitsoftware. Raw Data The binary representation of code or data associated with a section. excluding 16-bit PIC24 devices.

it is easy to get caught in an infinite loop where there will be no exit from the recursion. In the simulator real-time simply means execution of the microcontroller instructions as fast as they can be simulated by the host CPU. one instruction at a time. Shell The MPASM assembler shell is a prompted input interface to the macro assembler. When released from the halt state in the emulator or MPLAB ICD mode. allowing it to run the application code and change or respond to I/O in real time. a particular setup for stimulus control. After each instruction. the source data address and value and the destination data address appear when the Opcodes is actually executed. the real-time trace buffer of MPLAB ICE is enabled and constantly captures all selected cycles. Scenario For MPLAB SIM simulator. Skid When a hardware breakpoint is used to halt the processor. You can also single step C compiler source code. can call itself. Therefore. MPLAB IDE will execute all assembly level instructions generated by the line of the high level C statement.foxitsoftware. ROM Read Only Memory (Program Memory). MPLAB IDE updates register windows. the processor executes in real-time until a valid breakpoint causes a halt. Memory that cannot be modified. The number of captured cycles from one piece of information to another for a single instruction execution is referred to as the skew. For example. Simulator A software program that models the operation of devices.com Assembler/Linker/Librarian User’s Guide Real-Time Generated by Foxit PDF Creator © Foxit Software For evaluation only. Recursion The concept that a function or macro. one or more additional instructions may be executed before the processor halts. SFR See Special Function Registers. and status displays so you can analyze and debug instruction execution. Run The command that releases the emulator from halt. the processor runs in real-time mode and behaves exactly as the normal chip would behave. The number of extra instructions executed after the intended breakpoint is referred to as the skid. watch variables.http://www. Source Code DS33014K-page 278 2009 Microchip Technology Inc. Great care should be taken when writing recursive macros. but instead of executing single instructions. . Single Step This command steps though code. In real-time mode. The trace buffer captures the information that is on the bus at one instance. and all break logic is enabled. one trace buffer entry will contain execution information for three instructions. or until the user halts the emulator. Skew The information associated with the execution of an instruction appears on the processor bus at different times. having been defined. the executed Opcodes appears on the bus as a fetch during the execution of the previous instruction. In the emulator or MPLAB ICD. and the destination data value appears when the next instruction is executed.

foxitsoftware. Software Memory used by an application for storing return addresses. function parameters. Select Halt to regain control of program execution. Stack. clocked and register.e. This command executes the code in the subrountine and then stops execution at the return address to the subroutine. development mode and device. Stopwatch A counter for measuring execution cycles.. Source code is written in some formal programming language which can be translated into or machine code or executed by an interpreter. Program memory you can Read/Write on the target board that does not need refreshing frequently. If for some reason the subroutine gets into an endless loop or does not return properly.com For evaluation only. This memory is typically managed by the compiler when developing code in a high-level language.Generated by Foxit PDF Creator © Foxit Software http://www. and local variables. Glossary The form in which a computer program is written by the programmer. Status Bar The Status Bar is located on the bottom of the MPLAB IDE window and indicates such current information as cursor position. Step Into This command is the same as Single Step. This command executes the rest of the code in the subroutine and then stops execution at the return address to the subroutine. Special Function Registers The portion of data memory (RAM) dedicated to registers that control I/O processor functions. Step Out Step Out allows you to step out of a subroutine which you are currently stepping through. Source File An ASCII text file containing source code. DS33014K-page 279 . the next breakpoint will never be reached. synchronous (pin). data generated to exercise the response of simulation to external signals. Stimulus Input to the simulator. Stack. i. Step Into (as opposed to Step Over) follows a CALL instruction into a subroutine. Hardware Locations in PIC microcontroller where the return address is stored when a function call is made. Step Over Step Over allows you to step over subroutines. Often the data is put into the form of a list of actions in a text file. Symbol 2009 Microchip Technology Inc. Static RAM or SRAM Static Random Access Memory. Stimulus may be asynchronous. When stepping over a CALL instruction. the next breakpoint will be set at the instruction after the CALL. I/O status. and active tool bar. timers or other modes or peripherals.

Trace memory is sometimes called the trace buffer. A symbol is a general purpose mechanism for describing the various pieces which comprise a program.” “Maximize. ·²¬ ³§Ê¿®å defines a variable which will reside in an uninitialized data section. Uninitialized Data Data which is defined without an initial value. such as an emulator or programmer. section names. . function names and assembly labels. Warning An alert that is provided to warn you of a situation that would cause physical damage to a device. to the host PC or from the target board to the emulator. Trace An emulator or simulator function that logs program execution. file names. These pieces include function names.” Target Refers to user hardware. and is independent of the trace and breakpoint settings. Clicking on this control usually pops up a menu that has the items “Minimize. Target Processor The microcontroller device on the target application board. etc. variable names. In C. Watch Variable A variable that you may monitor during a debugging session in a watch window. DS33014K-page 280 2009 Microchip Technology Inc.” and “Close. Template Lines of text that you build for inserting into your files at a later time. Tool Bar A row or column of icons that you can click on to execute MPLAB IDE functions. The emulator logs program execution into its trace buffer which is uploaded to MPLAB IDE’s trace window. Any number of trigger output points can be set.foxitsoftware. Symbols in MPLAB IDE refer mainly to variable names.http://www. software file. or equipment. The value of a symbol after linking is its value in memory. Target Board The circuitry and programmable device that makes up the target application. struct/enum/union tag names. Trace Memory Trace memory contained within the emulator. The MPLAB Editor stores templates in template files. Upload The Upload function transfers data from a tool. System Window Control The system window control is located in the upper left corner of windows and some dialogs. Target Application Software residing on the target board. Trigger Output Trigger output refers to an emulator output signal that can be generated at any address or address range.com Assembler/Linker/Librarian User’s Guide Generated by Foxit PDF Creator © Foxit Software For evaluation only.

WDT See Watchdog Timer. DS33014K-page 281 . The WDT is enabled or disabled and set up using configuration bits. 2009 Microchip Technology Inc. a setup for generation of SCL stimulus. Watchdog Timer A timer on a PIC microcontroller that resets the processor after a selectable length of time. Workbook For MPLAB SIM stimulator.com For evaluation only.foxitsoftware.Generated by Foxit PDF Creator © Foxit Software http://www. Glossary Watch Window Watch windows contain a list of watch variables that are updated at each breakpoint.

.com Assembler/Linker/Librarian User’s Guide NOTES: Generated by Foxit PDF Creator © Foxit Software For evaluation only. DS33014K-page 282 2009 Microchip Technology Inc.http://www.foxitsoftware.

........................................................................................................................................................................... 55 code_pack.......................... 24 Access Section Overlayed ............................................................................. 267 B badram .......................................................... 46 __badrom .................................................. 145...................................... 192 Stack ................ 71 fi .... 240 /t ............................ 46 badrom ................................... 46 ACCESSBANK .. 96 _CRUNTIME ................................................................................................................................ 196 C Caveats............... 192 AND................. 167 code ...........................................................90.................... 69 Boot Loader....................................................................................................... 240 Linker ..... 52 COD file................................................................................................................................................... 47 __config ......................................................... Generating................................................................hex .................................................................. 147......................................................................... 13 Build Project Command Line.............................................. 188 _DEBUGDATASTART ................85................................. 146 Code Section............... 196 ..............................................................................................Generated by Foxit PDF Creator © Foxit Software http://www....................................... 141 #undefine .................................................................... 54....................................................... Indirect ................... 183 cblock ............................................ 145.................................................................. 127 Code Section..........................asm ............................ ASSEMBLER/LINKER/LIBRARIAN USER’S GUIDE Index Symbols __badram .......................12......... Librarian /c .................................... 116 $ ....................................................... Packed................................ 88 ifndef .. 188 _EXTENDEDMODE.................................................................................54.... 188 _DEBUGCODESTART ................................................................. 146 CODEPAGE.... 127 Blank Listing Lines ...................... 52................................................. 12 /o ............................................................................lib .. DS33014K-page 283 ................. 147 2009 Microchip Technology Inc. 12 .................................... 179 Command Line Options.................................................................................foxitsoftware..................................... 149 Defining Module ..................... 55 Code..................................................................................................................... 148 #define .................................... Absolute.............................................................. 188 _DEBUGDATALEN................................................................................ 12 COFF Object Module File ........... 188 _mplink.......... 240 /r..........................................cof ......................... 14............................ 142............................................ 146 Library Routine................. 174 Command Line Interface Assembler .................................................................................................................. 174 .......................................................... 25................... 231 Compiler ......................................... 240 Comments.................................................... 186 Accessing Labels From Other Modules .............................................................12....... 142......................................................... Relocatable.......................................................................................................................................... 12 ........................55.. logical ........ 28 Common Problems Linker ....................... 40 Bit Assignments ... 70 if ...... 147 Calling File ........................................................................lkr .............. 12 ........................................... 148 Code..............................183............. 240 /d ............................................ 48 banksel. 35 Librarian .............................50............... 41 Arithmatic Operators ...........exe .... 68 endif .................. 44 else ................................................ 198 MPLAB IDE.............. 147 bankisel .................... 240 /q .................................... 86 ifdef ..................... 206 Build Options....................................................................................................... 50 Bank Selecting. 192 Relocatable....................................................................................................................o .................. 188 _DEBUG ............ 47 Bank Selecting .................................. 146 Allocation Absolute................................ 57 A Absolute Code................................................... 15 Conditional Assembly Directives ........................ 118 Conditional Linker Statements ........... 240 /x ...... 65 #include..............................................128................ 146 __fuses ..................................................... 95 __maxrom ............................................................. 12 ................. 12 ............................ 142.......... 149 Referencing Module................................................................................................... Linker Script ....................... 24................ 89 while....................................................................................................................... 109 Block of Constants ................................................................................... 146 __maxram ........... 55 __idlocs ........................................................................... 40 ASCII Character Set ..............................................................c .............................................................................................. 46 access_ovr..... 48 Banking ......... 70 endw ........ 185.............com For evaluation only.................................................... 188 _DEBUGCODELEN .................................................... 187 config................... 186 COF File ...

............... 61 db ........................................................................................................... 203 EEPROM Data Byte .......................................................................................................... 62 de ................................................................................................................................................................... 194 DATABANK ................................. 59 Data Byte ..................................................................................................................................... 116 constant .................................................................... 46 __badrom .......................... 80 res .............................. 66.................. 68 data ...................................................................................................................................................... 113 Shared Uninitialized ....... 37................ 44 #define ................................ 115 Uninitialized................................ 43 Directives......... 108................................................................ 52 config ....................51...................................................................................................................... 247 Librarian Parse............. 123................ 123 constant.................................................................................................................55....... 241 Linker ....................... 116 Directives... 225 Linker Parse .......................................... 67 dw ........................................ 111 Initialized ............................................................................................ 58 Define................................................................... 59 data ......................... 44 __badram ........................................................................................................................................ 72 errorlevel ............................................................... 183................................................... 67 dw ..... 53 code ....................... 65 else............................. 65 Delete a Substitution Label ................. 82 Initialized Access . 72 Error File......................................................................... Application #define .................................................................................................................. 55 __idlocs .................................. 130 da ............... 27 Directives................................................................................................................................................................................................................................................. 71 Control Directives .... 62 de ....... Initialized.. 94............................................................................................................. 119 equ ........................... 153 else........... 71 error.......... 38 Examples..... 105 set .. 181 Decrement ................................................... 53 endif ............... 50 banksel .................................................. 1 dt ....................................... 130 bankisel ...................................... 110 Data....................... 54......................................................................................................................... 85 __maxram ............................................................................................. 90 #undefine ..................................... 64 dt ...................................................................... 60 Customer Notification Service ......................... 230 COFF to COD Converter..................................................................................... 198........ 223 Escape Sequences .............. 6 Customer Support ...................... 95 __maxrom .................................... 199 equ ................. 182 Documentation Conventions .................................................. 41 define............ 99 processor ............................ 49......................................................... 69 endc......................................................................................................................................................................... 84 Overlayed Uninitialized ............................. 118................................. 55 __fuses ......................... 37............................... 67 dtm ............................................. 67 dtm .. 58 Constant Compare .............. 154 Constants Block Of ............. 132 endw........................................................................................................................................ Assembler................................. 69 fill............................... 87 end ............................... 132 cblock ...................................................... Debug Command Line............... 74 D da ..............foxitsoftware......................................................................................................................... 108 variable ......................................................................................................................................................................... 186 db ..................... 69 equ ......................................................................................................... 155 errorlevel ................................................................................................ 60 db ............................ 71 org ........ 64 Word ... 57 da ........... 4 Layout ..... 122 endc ...... 104 radix ........... 70 endm .................................................................... Linker ................................................................................ 106 Data Section Access Uninitialized .. 96 cblock .................................................................................................................................................................................................................................................................................................................................. 134 #include .......................... 64 Eight-by-Eight Multiply......... 63 de .................................................................................................. 130.......................... 52. 52.............................. 146 constant.................................................... 69 endif............................................................................................................................ 62 EEPROM Byte ............................................................... 122 #undefine ......... 71 Environment Variables ............................................................................................. 117 Create Numeric and Text Data.................... 70 endw ........................................................................... 73 Errors Assembler ...............................com Assembler/Linker/Librarian User’s Guide Configuration Bits ......... 64 DS33014K-page 284 2009 Microchip Technology Inc......... 30.. 155 COFF ......................................................................................................... 66................................ 87 endm ........................................ 123 error........................................................................................................................................................... 60 Data Directives ....................................................................... 59 data ........................................................ 58 end ...................................... 65 #include.http://www..................................................................................................... 68 endc .. 68 E EEPROM ..................................................... 69 Declare........ 189 MPLAB IDE ..................... 57............. 47 __config ................................................. 68 end .................. 7 Generated by Foxit PDF Creator © Foxit Software For evaluation only.......................................................... .................

68 else ....................................................................Generated by Foxit PDF Creator © Foxit Software http://www......................... 66 #include .. 106 set ........................... 87 ifdef ................ 64 dt ................... 70 File Error ................................... 174 Hexadecimal to Decimal Conversion .................................................................................................................................................83............ 12 Execute If Symbol Defined .................................................................................................................................................................................................................................................................. 110............ 72 errorlevel ................................................................................................................... 92 local ... 109 title .................................................................................................... 93 macro .............88........... 109 G Generic Linker Script Example....... 106.. 203 extern ........................................................................... 200 global................................................................................. 85 __maxram ...................................... 104 processor ................... 48 banksel ............ 80 global ............................... 123 radix ........ 86 else ............................................................................................................................... 155 Listing................................................................................... 108 space ...........com For evaluation only........................................................................................... 112 udata_ovr.. 82.... 69 end .............................. 146 External Label ..................................................................... 67 dw ............................. DS33014K-page 285 .............................................................................. 89 exitm.. 81 global ................ 56 __idlocs.......................................................... 98 messg .............118.................. Simple __badram........................... 123......... 75 expand ..................... 85 if .......... 112 udata_ovr ................................................... 105 res ............................ 119 Executable Files ..................................... 104 radix ............. 97 org............................................................................... 143 I ID Locations ................. 47 __maxrom ...... 90 2009 Microchip Technology Inc............................................................................................................. 88 IFDEF/ELSE/FI in Linker Scripts ...................................................... 48 __config ............................................. 92 macro ....................... 76 extern ........................ 110 udata_acs ................12................................................. 82 Extended Microcontroller Mode ..........................foxitsoftware..............................103........................... 30............. 91 #undefine ......108.............................................. 136 udata_acs ........................................................................................... 136 set .................... 87 ifdef .................................................................... 84 idlocs ..................... 146 idata ...... 76 extern ........................................................................................................................ 268 high . 134.................................................................. 89 list ............................ 68 end ....... 126....................................... 69 endm ........ 48 #define ............................................. 115 variable ...................................................................................................................... 70 equ ............... 145 idata_acs... 97 org.................................... 130 udata....... 74 exitm ....................90............. 55 config ........... 88 Execute If Symbol Not Defined ......... 90 Include Additional Source File......................................................................... 134....................................... 82 H Header Files.................................................................... 119 Examples....................................................................................... 54 code_pack ..................................................................... 78..................................................................................................... 99 pagesel .................................................................. 117 bankisel............................................................................................... 113 udata_shr ..................................................................................99.................................................................................................................................... 110 udata ............................... 88 ifndef .......................... 78 fill ......... 100 pagesel ...... 102................................................................................... 58 data ..................................80........................................................................................................................................................................................... 132 messg ................................................ 82 idata ... 117 while.......................... 50 cblock.............................. 140 F fi ....... 45 FILES ...................................... 134 local ....... 72 error ................................................................................................ 105 res ....................................................................................................................... 134... 78............................................................................................. 77........................................................... 46...................................................................... 123..................................................................................... 63 de .................. 94.......................................... 77 Export a Label ....... 89 INCLUDE ........ 109 subtitle..................................................................... 189 Generic Linker Scripts ..................................................... 89 list .................................................................. 78 fill ............................................ 53 code ............................................................... 183 include ................................................................................................................................. 40........................... 187 ifndef ..........................................................................................................................105.......................................................... 60 db ..................................... 80 Final Frontier ......... 115 variable ............. 70 ifdef ............................................................ 47 __badrom........................................................................................................................................................................ 83 if ................................................................................................................... 141 Hex Files .... 130 while.................94................ 136 idata ..................................... 78 External Memory ............................................................................. 114 udata_shr ........ 85............................................................................................... 85 if ......................................................................... 182 fill........................................................................................................................... Index exitm ..............................

...................... 96 maxram ....................................................................................................... 183 Message............ 98 nolist ... 78 global................................... 94 noexpand ........................................................................ 46 bankisel ............................................................................................................................................. 174................................ 237 Library Path ........................ 101 Generated by Foxit PDF Creator © Foxit Software For evaluation only.......................................... 102 DS33014K-page 286 2009 Microchip Technology Inc............. 181 Debug Tool ....... 173 Instruction Operands ...................................................... 186 low ...........................exe .......... 94 Macro Directives................................ 26 Librarian ................................. 77 No Expansion.................................................................................................................... 110 Listing File ......................................... 16 mplib.................... 32.................................................................. 174................................................. 99........................................................................... 72 errorlevel ......28...................................... 198.............................. 75...................................................... 95 Maximum ROM Location................................................................................................................................ 45 access_ovr ............................................... 23................ 27 mp2cod Utility.......................................... 45 error ................ 82 idata_acs.................................................. 235 MPLIB Object Librarian .............................................. 9 N noexpand........................ 98 NOT............................ 197 Maximum RAM Location ............................................................................................................................................................................exe ........................................................................................................................... 73 list.......................................... Microchip.................... 98 Macro Language ... 50 code ................................................................................................................................................................ 246 MPASM Assembler ............................................................. 75 Expand .......................................12.............................................................. 95 maxrom ................................................................................................ 75 expand ........................com Assembler/Linker/Librarian User’s Guide Include File ............. 106 Memory Regions ... 174........ 151 Macro Syntax ....... 129 PIC18 Example ...................................................12.. 14 MPLAB C18 Tab ... 12............... 187 main.................................................. 191 Linker Scripts ..... 109 title ............foxitsoftware.......... 16 mplink... 13 MPASM/C17/C18 Suite Tab .............. 196........................................... 70 exitm ............................................. 27 LIBPATH ..exe ..........................................................http://www....................................................................... 40................................................................................... 151 Macros............................................................... 260 Internet Address. 171 MPLINK Object Linker ...................................................................................................... 174 LKRPATH............... 92 macro ................................................................................................................................................. 81............................. 9.................... .. 91 Listing Directives ................ 27 Macros in Linker Scripts ............................. 45 Defined...................... 254 PIC18 Device .................................................................................................. 9 MPLINK Linker Overview .................... logical......................... 12........................................ 181 Standard .............................. 176........................ 181 list ................................................................................ 142 Instruction Sets .... 196.................................... 15 MPLINK LinkerTab ..................... 13 MPASM Assembler Overview ................................ 98 page ...................................................................... 143 local ................................ 259 14-Bit Core ........ 109 subtitle.......................................... 182 local ............................................. 167 Linker Processing......... 101 space ....................... 55 extern .............. 96 Mnemonics ....................................... 253.......................................... 152 endm ...... 80 Reserve............................................................... 81............................................................................................................................................................................................... 54 code_pack............................................................................................................................................................................ 98 Text Substitution .... 246 mp2hex Utiltiy............................ 251 12-Bit Core ......................................................... 39 Map File....................................................................................... 165 messg.......................... 96 MCC_INCLUDE .................................. 199 Memory Fill...... 33 MPLAB C18 C Compiler.................................... 182 Library File ................................................................................................... L Labels..... 84 pagesel...............................................exe ............................................................................... 237 Object File Directives ...................................................................................................................................................................................................................................................... 194 Input/Output Files Assembler .. 70 Exit .......... 16 MPLIB Librarian Overview............ 167 mpasmwin............................................... 259 12-Bit/14-Bit Cores............................................................................................. 152 Usage................................................. 237 Linker .......................................................................................... 41 Initialized Data......... 77 O Object File ................ 197 Limitations Assembler ......................................... 6 Interrupt Handling PIC16 Example ... 153 End... 28 Increment ............................................... 12............ 45................... 124..................................................................... 92 Logical Sections ... 96 nolist....... 82 idata ..... 16 MPLAB C17 Tab .................. 23 mpasm............................................ 48 banksel .......................................... 15 MPLAB IDE Build Options Dialog MPASM Assembler Tab.......................................... 96 Messages Assembler ............... 40 M Macro Code Examples.......................................................................... 152 macro ................... 91 messg ..........................................................

....... 115.............. 58 Symbols............ 39 radix ... 145 udata_ovr .................................................................................... 92 W Warnings Assembler .......... 113 udata_shr .................................... 105 Radix................................ Define .................................................. 183 U udata .................................. 48 Source Code .......................................................................................... 200 Text Strings ........................... 109 2009 Microchip Technology Inc........................................................................................................ 195 Scripts......................... 141 res ......................................................................................................... 41 org ...................................................................... 101 Page Eject.. 138 Delay Techniques ...................... Set ... Set .................. 59 subtitle..................... 181 Search Order....................... 116 Unimplemented RAM ................................. 111............ 104 Processor.......183....................................... 26 space ....................................................................... 109 Stack ........................................ 34 S Sample Applications.................................................... 40 OR........................................................................................... 32 Relocatable Code............ 147 PATH ............................................ 115 Object Files.......................................................... Index pageselw.......... 247 Linker ......................... Linker .. 99 SHAREBANK ...... 110.... 245 R Radix ........... Precompiled ................................... 110 Troubleshooting ..................................................198.................................................... 28 Operators........................................................................... 37 Text Substitution Label............... Arithmatic ................................................. 186 Standard Linker Scripts................................. 118 White Space.......................................................................com For evaluation only................................................................................................ 113............................. 140 title...................... 101 Page Selection ................................. 99 Symbol Constant................ Generating....... 65 Tips and Tricks Bit Shifting Using Carry Bit........................................................................... 91. 186 set ................... 11 PROTECTED .................................................. 162 COFF to COD Converter ........ Assembly........ Linker............................................183......... 47 upper ....... 110 udata_acs ............ 6 while ................................... Microchip ....... 142 Projects .......................................................................................... 183 Reading............................................. 123 RAM Allocation ............................................................ 186 Simple .............................................................................................................. 103 Paging ............................. 138 Swap File Register with W ...............................................127.................. 139 Conditional Bit Set/Clear................ DS33014K-page 287 ....................................................................................................................................................... logical ............................................................... 5 Register Assignments ........ 25 Relocatable Objects ............................. 148 Operands .......................................... 143 Utilities Overview and Usage ................................................. 40.............. 46 Unimplemented ROM.............................................. 145 udata_acs......... 117 Define. 103 udata................................ Recommended ............. 137 Optimizing Destinations ............................................................................. 103 pagesel ......................... 139 Using External Memory..................... 147 pageselw ............................ 191 processor ........ 102 Page Selection ............................. 199 Processing.......... 108 Set Program Origin ................................................................................... 90 SECTION ............. 145 RAM Memory Regions..................................... 186 STACK SIZE ....................................... 108 Local .................. Include Files ...........................................................................WREG ............................foxitsoftware............ In Expressions ............................................ Defining ........ 131 Web Site....................... Assembler .................... 155 P page ............................................................................... 26 Windows Shell Interface.................................... 185 V Variable Declare.......................... 106 Reserved Section Names.............. 91.......... Defining................................102................. 105...........................................................................................................................................................................Generated by Foxit PDF Creator © Foxit Software http://www.... 39 ROM Memory Regions........................................ 230 Watch Window ............... 127 relocatable ................... 39 Reserved Words............................. 12 Source Code File.47........................................... Assembler ......... 12 Object Module.................................. Linker ................................. 40 T Table..................................................................................................................... 123 Program Memory ............................................... 111 udata_ovr.................... 145 undefine ......... 181 Store Strings in Program Memory.................................................................... 145 udata_shr ............................................................................................................................................................... 104................ Generating ....................... 67 Templates .......................

MA Tel: 774-760-0087 Fax: 774-760-0088 Chicago Itasca. AZ 85224-6199 Tel: 480-792-7200 Fax: 480-792-7277 Technical Support: http://support.Penang Tel: 60-4-227-8870 Fax: 60-4-227-4068 Philippines .Xiamen Tel: 86-592-2388138 Fax: 86-592-2388130 China . IL Tel: 630-285-0071 Fax: 630-285-0075 Cleveland Independence. CA Tel: 949-462-9523 Fax: 949-462-9608 Santa Clara Santa Clara.Manila Tel: 63-2-634-9065 Fax: 63-2-634-9069 Singapore Tel: 65-6334-8870 Fax: 65-6334-8850 Taiwan . The Gateway Harbour City. CA Tel: 408-961-6444 Fax: 408-961-6445 Toronto Mississauga.Generated by Foxit PDF Creator © Foxit Software http://www.Madrid Tel: 34-91-708-08-90 Fax: 34-91-708-08-91 UK .Seoul Tel: 82-2-554-7200 Fax: 82-2-558-5932 or 82-2-558-5934 Malaysia . Chandler.Shenyang Tel: 86-24-2334-2829 Fax: 86-24-2334-2393 China . Ontario.Yokohama Tel: 81-45-471.Daegu Tel: 82-53-744-4301 Fax: 82-53-744-4302 Korea . Kowloon Hong Kong Tel: 852-2401-1200 Fax: 852-2401-3431 Australia .Shenzhen Tel: 86-755-8203-2660 Fax: 86-755-8203-1760 China .Hsin Chu Tel: 886-3-6578-300 Fax: 886-3-6578-370 Taiwan .microchip.com Atlanta Duluth.com Web Address: www.Kaohsiung Tel: 886-7-536-4818 Fax: 886-7-536-4803 Taiwan .Xian Tel: 86-29-8833-7252 Fax: 86-29-8833-7256 China .Nanjing Tel: 86-25-8473-2460 Fax: 86-25-8473-2470 China . GA Tel: 678-957-9614 Fax: 678-957-1455 Boston Westborough.Qingdao Tel: 86-532-8502-7355 Fax: 86-532-8502-7205 China .Wokingham Tel: 44-118-921-5869 Fax: 44-118-921-5820 03/26/09 DS33014K-page 288 2009 Microchip Technology Inc. .Pune Tel: 91-20-2566-1512 Fax: 91-20-2566-1513 Japan .microchip.Bangalore Tel: 91-80-3090-4444 Fax: 91-80-3090-4080 India .foxitsoftware.Munich Tel: 49-89-627-144-0 Fax: 49-89-627-144-44 Italy .New Delhi Tel: 91-11-4160-8631 Fax: 91-11-4160-8632 India .Taipei Tel: 886-2-2500-6610 Fax: 886-2-2508-0102 Thailand .Milan Tel: 39-0331-742611 Fax: 39-0331-466781 Netherlands . TX Tel: 972-818-7423 Fax: 972-818-2924 Detroit Farmington Hills.Hong Kong SAR Tel: 852-2401-1200 Fax: 852-2401-3431 China . IN Tel: 765-864-8360 Fax: 765-864-8387 Los Angeles Mission Viejo. OH Tel: 216-447-0464 Fax: 216-447-0643 Dallas Addison.Bangkok Tel: 66-2-694-1351 Fax: 66-2-694-1350 EUROPE Austria . Canada Tel: 905-673-0699 Fax: 905-673-6509 ASIA/PACIFIC Asia Pacific Office Suites 3707-14.Beijing Tel: 86-10-8528-2100 Fax: 86-10-8528-2104 China .Chengdu Tel: 86-28-8665-5511 Fax: 86-28-8665-7889 China .Paris Tel: 33-1-69-53-63-20 Fax: 33-1-69-30-90-79 Germany .Drunen Tel: 31-416-690399 Fax: 31-416-690340 Spain .Shanghai Tel: 86-21-5407-5533 Fax: 86-21-5407-5066 China .6166 Fax: 81-45-471-6122 Korea .Zhuhai Tel: 86-756-3210040 Fax: 86-756-3210049 ASIA/PACIFIC India . 37th Floor Tower 6.Sydney Tel: 61-2-9868-6733 Fax: 61-2-9868-6755 China .Wuhan Tel: 86-27-5980-5300 Fax: 86-27-5980-5118 China .Kuala Lumpur Tel: 60-3-6201-9857 Fax: 60-3-6201-9859 Malaysia . WORLDWIDE SALES AND SERVICE AMERICAS Corporate Office 2355 West Chandler Blvd. MI Tel: 248-538-2250 Fax: 248-538-2260 Kokomo Kokomo.com For evaluation only.Wels Tel: 43-7242-2244-39 Fax: 43-7242-2244-393 Denmark .Copenhagen Tel: 45-4450-2828 Fax: 45-4485-2829 France .

Sign up to vote on this title
UsefulNot useful