MPASM User S Guide PDF
MPASM User S Guide PDF
MPASM User S Guide PDF
USER'S GUIDE
with MPLINK and MPLIB
Information contained in this publication regarding device applications and the like is intended by way of suggestion
only. No representation or warranty is given and no liability is assumed by Microchip Technology Incorporated with
respect to the accuracy or use of such information. Use of Microchips products as critical components in life support
systems is not authorized except with express written approval by Microchip.
1999 Microchip Technology Incorporated. All rights reserved.
The Microchip logo, name, PIC, PICmicro, PICMASTER, PICSTART, and PRO MATE are registered rademarks of
Microchip Technology Incorporated in the U.S.A. and other countries. MPLAB, and Smart Serial are trademarks of
Microchip Technology in the U.S.A. and other countries.
All product/company trademarks mentioned herein are the property of their respective companies.
DS33014G
DS33014G
DS33014G-page iii
Introduction ...................................................................................11
1.2
Highlights ......................................................................................11
1.3
1.4
1.5
1.6
Introduction ...................................................................................13
2.2
Highlights ......................................................................................13
2.3
Installation .....................................................................................13
2.4
2.5
Introduction ...................................................................................21
3.2
Highlights ......................................................................................21
3.3
3.4
Introduction ...................................................................................27
4.2
Highlights ......................................................................................27
4.3
4.4
4.5
4.6
4.7
DS33014G-page iv
5.1
Introduction ...................................................................................35
5.2
Highlights ......................................................................................35
Table of Contents
5.3
5.4
5.5
5.6
5.7
5.8
5.9
DS33014G-page v
DS33014G-page vi
Table of Contents
Chapter 6. Using MPASM to Create Relocatable Objects
6.1
Introduction ................................................................................... 73
6.2
Highlights ...................................................................................... 73
6.3
6.4
6.5
6.6
6.7
6.8
6.9
Introduction ................................................................................... 83
7.2
Highlights ...................................................................................... 83
7.3
7.4
7.5
7.6
7.7
Introduction ................................................................................... 89
8.2
Highlights ...................................................................................... 89
8.3
8.4
8.5
High/Low/Upper ............................................................................ 93
8.6
DS33014G-page vii
DS33014G-page viii
9.1
Introduction ...................................................................................95
9.2
Highlights ......................................................................................95
9.3
Table of Contents
Part 2 MPLINK
Chapter 1. MPLINK Preview
1.1
Introduction ................................................................................... 99
1.2
Highlights ...................................................................................... 99
1.3
1.4
1.5
1.6
1.7
2.2
2.3
2.4
2.5
3.2
3.3
4.2
4.3
4.4
4.5
4.6
5.2
5.3
DS33014G-page ix
5.5
5.6
5.7
5.8
Introduction .................................................................................127
6.2
Highlights ....................................................................................127
6.3
6.4
6.5
6.6
Highlights ....................................................................................131
7.2
Overview .....................................................................................131
7.3
7.4
Highlights ....................................................................................137
8.2
Overview .....................................................................................137
8.3
8.4
8.5
DS33014G-page x
9.1
Highlights ....................................................................................145
9.2
Overview .....................................................................................145
9.3
9.4
Table of Contents
Chapter 10. Sample Application 4
10.1 Highlights .................................................................................... 151
10.2 Overview ..................................................................................... 151
10.3 Building the Application .............................................................. 153
10.4 Source Code ............................................................................... 154
DS33014G-page xi
Introduction .................................................................................163
1.2
Highlights ....................................................................................163
1.3
1.4
1.5
Introduction .................................................................................165
2.2
Highlights ....................................................................................165
2.3
Installation ...................................................................................165
2.4
DS33014G-page xii
3.1
Introduction .................................................................................167
3.2
Highlights ....................................................................................167
3.3
3.4
3.5
Tips .............................................................................................168
Table of Contents
Appendices
Appendix A. Hex File Formats
A.1
A.2
A.3
A.4
A.5
B.2
B.3
B.4
B.5
B.6
B.7
B.8
B.9
............................................................... 195
C.2
C.3
C.4
C.5
D.2
D.3
D.4
DS33014G-page xiii
D.6
D.7
D.8
D.9
Introduction .................................................................................215
E.2
Highlights ....................................................................................215
E.3
E.4
E.5
Glossary
Introduction ............................................................................................217
Highlights ...............................................................................................217
Terms .....................................................................................................217
DS33014G-page xiv
Highlights
The information you will garner from this chapter:
About This Guide
Warranty Registration
Recommended Reading
The Microchip Internet Web Site
Development Systems Customer Notification Service
Customer Support
DS33014G-page 1
DS33014G-page 2
General Information
Appendices
Appendix A: Hex File Formats provides a description of the different
hex file formats that may be used.
Appendix B: Quick Reference lists PICmicro device instruction sets,
hexadecimal to decimal conversions, and ASCII Character Set.
Appendix C: MPASM Errors/Warnings/Messages contains a
descriptive list of the errors, warnings, and messages generated by
MPASM.
Appendix D: MPLINK Errors/Warnings contains a descriptive list of
the errors and warnings generated by MPLINK.
Appendix E: MPLIB Errors contains a descriptive list of the errors
generated by MPLIB.
Glossary A glossary of terms used in this guide.
Index Cross-reference listing of terms, features, and sections of this
document.
Worldwide Sales and Service gives the address, telephone and fax
number for Microchip Technology Inc. Sales and Service locations
throughout the world.
Represents
Examples
Code
Courier Font
#define ENIGMA
<label>, <exp>
Square Brackets: [ ]
Optional Arguments
MPASMWIN
[main.asm]
errorlevel
{ 0 | 1 }
filename
Ellipses: ...
list
[list_option
, ...,
list_option]
0xnnnn
DS33014G-page 3
Represents
Examples
Interface
Underlined, Italics Text Defines a menu selection from File > Save
with Right Arrow
the menu bar.
In-text Bold Characters Designates a button
OK, Cancel
<TAB>, <ESC>
Documents
Italic characters
Referenced books.
MPLAB Users
Guide
Updates
All documentation becomes dated, and this users guide is no exception.
Since MPASM, MPLINK, MPLIB, and other Microchip tools are constantly
evolving to meet customer needs, some actual dialogs and/or tool
descriptions may differ from those in this document. Please refer to our web
site to obtain the latest documentation available.
Warranty Registration
Please complete the enclosed Warranty Registration Card and mail it
promptly. Sending in your Warranty Registration Card entitles you to receive
new product updates. Interim software releases are available at the Microchip
web site.
Recommended Reading
This users guide describes how to use MPASM, MPLINK, and MPLIB. The
user may also find the data sheets for specific microcontroller devices
informative in developing firmware.
README.ASM, README.LKR
For the latest information on using MPASM and MPLINK, read the README
files (ASCII text files) included with the MPASM software. The README files
contain update information that may not be included in this document.
MPLAB Users Guide (DS51025)
Comprehensive guide that describes installation and features of Microchips
MPLAB Integrated Development Environment, as well as the editor and
simulator functions in the MPLAB environment.
DS33014G-page 4
General Information
Technical Library CD-ROM (DS00161)
This CD-ROM contains comprehensive data sheets for Microchip PICmicro
devices available at the time of print. To obtain this disk, contact the nearest
Microchip Sales and Service location (see back page) or download individual
data sheet files from the Microchip web site (http://www.microchip.com).
Embedded Control Handbook Vol.1 & 2 (DS00092 & DS00167)
These handbooks contain a wealth of information about microcontroller
applications. To obtain these documents, contact the nearest Microchip Sales
and Service location (see back page).
The application notes described in these manuals are also obtainable from
Microchip Sales and Service locations or from the Microchip web site
(http://www.microchip.com).
Microsoft Windows Manuals
This manual assumes that users are familiar with Microsoft Windows
operating system. Many excellent references exist for this software program,
and should be consulted for general operation of Windows.
DS33014G-page 5
DS33014G-page 6
General Information
Compilers
The latest information on Microchip C compilers, Linkers, and Assemblers.
These include MPLAB-C17, MPLAB-C18, MPLINK, MPASM as well as the
Librarian, MPLIB for MPLINK.
To SUBSCRIBE to this list, send a message to:
listserv@mail.microchip.com
with the following as the body:
subscribe compilers yourname
Emulators
The latest information on Microchip In-Circuit Emulators. These include
MPLAB-ICE and PICMASTER.
To SUBSCRIBE to this list, send a message to:
listserv@mail.microchip.com
with the following as the body:
subscribe emulators yourname
Programmers
The latest information on Microchip PICmicro device programmers. These
include PRO MATE II and PICSTART Plus.
To SUBSCRIBE to this list, send a message to:
listserv@mail.microchip.com
with the following as the body:
subscribe programmers yourname
MPLAB
The latest information on Microchip MPLAB, the Windows Integrated
Development Environment for development systems tools. This list is focused
on MPLAB, MPLAB-SIM, MPLABs Project Manager and general editing and
debugging features. For specific information on MPLAB compilers, linkers,
and assemblers, subscribe to the COMPILERS list. For specific information
on MPLAB emulators, subscribe to the EMULATORS list. For specific
information on MPLAB device programmers, please subscribe to the
PROGRAMMERS list.
To SUBSCRIBE to this list, send a message to:
listserv@mail.microchip.com
with the following as the body:
subscribe mplab yourname
DS33014G-page 7
Customer Support
Users of Microchip products can receive assistance through several channels:
Distributor or Representative
Local Sales Office
Field Application Engineer (FAE)
Corporate Applications Engineer (CAE)
Hot line
Customers should call their distributor, representative, or field application
engineer (FAE) for support. Local sales offices are also available to help
customers. See the back cover for a listing of sales offices and locations.
Corporate applications engineers (CAEs) may be contacted at
(602) 786-7627.
In addition, there is a Systems Information and Upgrade Line. This line
provides system users a listing of the latest versions of all of Microchip's
development systems software products. Plus, this line provides information
on how customers can receive any currently available upgrade kits.
The Hot Line Numbers are:
1-800-755-2345 for U.S. and most of Canada, and
1-602-786-7302 for the rest of the world.
DS33014G-page 8
Part 1 MPASM
Chapter 1. MPASM Preview ..................................................................11
Chapter 2. MPASM Installation and Getting Started .......................13
Chapter 3. Using MPASM with DOS .....................................................21
Chapter 4. Using MPASM with Windows and MPLAB .......................27
Chapter 5. Directive Language .............................................................35
Chapter 6. Using MPASM to Create Relocatable Objects ..................73
Chapter 7. Macro Language .................................................................83
Chapter 8. Expression Syntax and Operation ....................................89
Chapter 9. Example Initialization Code ...............................................95
DS33014G-page 9
DS33014G-page 10
Introduction
This chapter will give you an preview of MPASM and its capabilities.
1.2
Highlights
Topics covered in this chapter:
What MPASM Is
What MPASM Does
Migration Path
Compatibility Issues
1.3
What MPASM Is
MPASM is a DOS or Windows-based PC application that provides a platform
for developing assembly language code for Microchips PICmicro
microcontroller (MCU) families. Generically, MPASM will refer to the entire
development platform including the macro assembler and utility functions.
Use of the Microchip MPASM Universal Assembler requires an IBM PC/AT
or compatible computer, running MS-DOS V5.0 or greater, or Microsoft
Windows 95/98/NT.
MPASM supports all PICmicro, memory, and secure data products from
Microchip.
1.4
DS33014G-page 11
Migration Path
Since MPASM is a universal assembler for all PICmicro devices, an
application developed for the PIC16C54 can be easily translated into a
program for the PIC16C71. This would require changing the instruction
mnemonics that are not the same between the machines (assuming that
register and peripheral usage were similar). The rest of the directive and
macro language will be the same.
1.6
Compatibility Issues
MPASM is compatible with all Microchip development systems currently in
production. This includes MPLAB-SIM (PICmicro MCU discrete-event
simulator), MPLAB-ICE (PICmicro MCU Universal In-Circuit Emulator),
PRO MATE (the Microchip Universal Programmer), and PICSTART Plus (the
Microchip low-cost development programmer).
MPASM supports a clean and consistent method of specifying radix (see
Chapter 5). You are encouraged to develop new code using the methods
described within this document, even though certain older syntaxes may be
supported for compatibility reasons.
DS33014G-page 12
2.1
Introduction
This chapter provides instructions for installation of MPASM on your system,
and an overview of the assembler (MPASM).
2.2
Highlights
Topics covered in this chapter:
Installation
Overview of Assembler
Assembler Input/Output Files
2.3
Installation
There are three versions of MPASM:
a DOS version, MPASM.EXE, for DOS 5.0 or greater
a DOS-Extender version, MPASM_DP.EXE
a Windows 3.x/95/98/NT version, MPASMWIN.EXE (Recommended)
MPASM.EXE has a command line interface. MPASM.EXE may be used with
DOS or a DOS window in Windows 3.x/95/98/NT. You can use it with MPLAB,
though MPASMWIN.EXE is recommended.
MPASM_DP.EXE has a DOS shell interface. MPASM_DP.EXE may be used
with DOS or a DOS window in Windows 3.x. You can use it with MPLAB
running under Windows 3.x, though MPASMWIN.EXE is recommended.
MPASMWIN.EXE has a Windows shell interface. MPASMWIN.EXE may be used
with Windows 3.x/95/98/NT. You can use this version with MPLAB
(recommended) or stand-alone.
If you are going to use MPLAB with MPASM, you do not need to install the
assembler and supporting files separately. When MPLAB is installed, MPASM
is also installed. To find out how to install MPLAB, please refer to the MPLAB
Users Guide. You may obtain the MPLAB software and users guide either
from the Microchip Technical Library CD or from our website.
If you are not going to use MPLAB with MPASM, you can obtain the
assembler and supporting files separately either from the Microchip Technical
Library CD or from our website. MPASM will be in a zip file. To install:
Create a directory in which to place the files
Unzip the MPASM files using either WinZip or PKZIP
DS33014G-page 13
MPASM
Overview of Assembler
MPASM can be used in two ways:
To generate absolute code that can be executed directly by a microcontroller.
To generate object code that can be linked with other separately assembled or compiled modules.
Absolute code is the default output from MPASM. This process is shown in
Figure 2.1.
When a source file is assembled in this manner, all values used in the source
file must be defined within that source file, or in files that have been explicitly
included. If assembly proceeds without errors, a HEX file will be generated,
containing the executable machine code for the target device. This file can
then be used in conjunction with a device programmer to program the
microcontroller.
CODE.ASM
MPASM
CODE.HEX
Programmer
CPU
DS33014G-page 14
UNIT1.ASM
MPLIB
MPASM
UNIT1.O
UNIT2.ASM
MPASM
MPLIB
UNITS.LIB
UNIT2.O
UNIT3.ASM
MPASM
MPLIB
UNIT3.O
Figure 2.2:
UNITS.LIB
MAIN.ASM
MPASM
MPLINK
MAIN.HEX
Programmer
CPU
MAIN.O
MORE.ASM
MPASM
MORE.O
Figure 2.3:
DS33014G-page 15
2.5.1
Extension
Purpose
.ASM
.LST
.ERR
.HEX
.HXL/
.HXH
.COD
Output extension for the symbol and debug file. This file may
be output from MPASM or MPLINK:
<source_name>.COD
.O
DS33014G-page 16
Example 2.1:
;
; Sample MPASM Source Code.
;
list
p=16c54
Dest
equ
H0B
Start
org
goto
H01FF
Start
org
H0000
movlw
movwf
bcf
goto
H0A
Dest
Dest, 3
Start
end
2.5.1.1
Labels
A label must start in column 1. It may be followed by a colon (:), space, tab or
the end of line.
Labels must begin with an alpha character or an under bar (_) and may
contain alphanumeric characters, the under bar and the question mark.
Labels may be up to 32 characters long. By default they are case sensitive,
but case sensitivity may be overridden by a command line option. If a colon is
used when defining a label, it is treated as a label operator and not part of the
label itself.
2.5.1.2
Mnemonics
2.5.1.3
Operands
DS33014G-page 17
MPASM
Whitespace or a colon must separate the label and the mnemonic, and the
mnemonic and the operand(s). Multiple operands must be separated by a
comma. For example:
Comments
DS33014G-page 18
0000000B
01FF
01FF 0A00
0000
0000 0C0A
0001 002B
0002 0A00
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
MPASM
2.5.2
MANUAL.ASM
5-30-1997
15:31:05
PAGE
;
; Sample MPASM Source Code. For illustration only.
;
list p=16c54
Dest equ H0B
org H01FF
goto Start
org H0000
Start movlw H0A
movwf Dest
goto Start
end
MANUAL.ASM
SYMBOL TABLE
LABEL
5-30-1997
15:31:05
PAGE
VALUE
Dest
Start
__16C54
0000000B
00000000
00000001
'-' = Unused)
0
0 reported,
0 reported,
4
508
0 suppressed
0 suppressed
DS33014G-page 19
2.5.3
For example:
Error[113] C:\PROG.ASM 7 : Symbol not previously defined (start)
2.5.4
2.5.5
2.5.6
DS33014G-page 20
Introduction
This chapter is dedicated to describing the versions of MPASM for DOS
(MPASM.EXE and MPASM_DP.EXE). The DOS version (MPASM.EXE) is run
from a command line or a DOS shell in DOS or a DOS window in Windows.
The extended DOS (MPASM_DP.EXE) version is run in the same manner but
can be used when the DOS version runs out of memory.
3.2
Highlights
Topics covered in this chapter:
Command Line Interface
DOS Shell Interface
3.3
[<filename>]
or
MPASM_DP [/<Option>[ /<Option>...]]
[<filename>]
Where
/<Option> refers to one of the command line options
<filename> is the file being assembled
For example, if test.asm exists in the current directory, it can be assembled
with following command:
MPASM /e /l test
The assembler defaults (noted below) can be overridden with options:
/<option>
/<option>+
/<option>/<option><filename>
DS33014G-page 21
DS33014G-page 22
Option
Default
Description
N/A
INHX8M
On
None
Define symbol:
/dDebug /dMax=5 /dString=abc
On
N/A
On
On
Off
None
Off
Hex
Off
DS33014G-page 23
MPASM
3.4.1
Source File
Type the name of your source file. The name can include a DOS path
and wild cards. If you use wild cards (one of * or ?), a list of all matching
files is displayed for you to select from. To automatically enter *.ASM in this
field, press <TAB>.
3.4.2
Processor Type
If you do not specify the processor in your source file, use this field to select
the processor. Enter the field by using the arrow keys, then toggle through the
processors by pressing <RET>.
3.4.3
Error File
An error file (<sourcename>.ERR) is created by default. To turn the error file
off, use the <> to move to the YES and press <RET> to change it to NO. The
error filename can be changed by pressing the <TAB> key to move to the
shaded area and typing a new name. Wild cards are not allowed in the error
filename.
DS33014G-page 24
3.4.5
Listing File
A listing file (<sourcename>.LST) is created by default. To turn the listing file
off, use the <> to move to the YES and press <RET> to change it to NO. The
listing filename can be changed by pressing the <TAB> key to move to the
shaded area and typing a new name. Wild cards are not allowed in the listing
filename.
3.4.6
3.4.7
DS33014G-page 25
MPASM
3.4.4
DS33014G-page 26
4.1
Introduction
This chapter is dedicated to describing the version of MPASM for Windows
(MPASMWIN.EXE). This version may be run stand-alone as a Windows shell,
or within MPLAB.
4.2
Highlights
Topics covered in this chapter:
Windows Shell Interface
MPLAB Projects and MPASM
Setting Up MPLAB to use MPASM
Generating Output Files
MPLAB/MPASM Troubleshooting
4.3
DS33014G-page 27
MPASM
Option
DS33014G-page 28
Usage
Radix
Warning Level
Hex Output
Generated Files
Case Sensitivity
Macro Expansion
Processor
Tab Size
Extra Options
Project Files
Target Node
.HEX
Source Node
.ASM
Language Tools
MPASM
Properties
DS33014G-page 29
MPASM
4.4
DS33014G-page 30
DS33014G-page 31
MPASM
2. In the Node Properties dialog, select MPASM as the Language Tool and,
if desired, set other assembler options.
4.6
4.7
MPLAB/MPASM Troubleshooting
If have experienced problems, check the following:
Select Project>Install Language Tool... and check that MPASM points to
MPASMWIN.EXE in the MPLAB installation directory and that the Windowed
option is selected. Alternatively, MPASM can point to MPASM.EXE, but the
Command-line option should be selected.
DS33014G-page 32
DS33014G-page 33
DS33014G-page 34
Introduction
This chapter describes the MPASM directive language.
Directives are assembler commands that appear in the source code but are
not translated directly into opcodes. They are used to control the assembler:
its input, output, and data allocation.
Many of the assembler directives have alternate names and formats. These
may exist to provide backward compatibility with previous assemblers from
Microchip and to be compatible with individual programming practices. If
portable code is desired, it is recommended that programs be written using
the specifications contained within this document.
5.2
Highlights
There are five basic types of directives provided by MPASM:
Control Directives Control directives permit sections of conditionally
assembled code.
Data Directives Data Directives are those that control the allocation of
memory and provide a way to refer to data items symbolically, that is, by
meaningful names.
Listing Directives Listing Directives are those directives that control
the MPASM listing file format. They allow the specification of titles, pagination, and other listing control.
Macro Directives These directives control the execution and data allocation within macro body definitions.
Object File Directives These directives are used only when creating
an object file.
5.3
Directive Summary
Table 5.1 contains a summary of directives supported by MPASM. The
remainder of this chapter is dedicated to providing a detailed description of
the directives supported by MPASM. Each definition will show:
Syntax
Description
Example
DS33014G-page 35
Description
Syntax
_ _BADRAM
BANKISEL
bankisel <label>
BANKSEL
banksel <label>
CBLOCK
CODE
_ _CONFIG
CONSTANT
constant <label>[=<expr>,...,<label>[=<expr>]
DA
DATA
DB
[<label>] db <expr>[,<expr>,...,<expr>]
[<label>] db "<text_string>"[,"<text_string>",...]
DE
[<label>] de <expr>[,<expr>,...,<expr>]
[<label>] de "<text_string>"[,"<text_string>",...]
#DEFINE
DT
Define Table
[<label>] dt <expr>[,<expr>,...,<expr>]
[<label>] dt "<text_string>"[,"<text_string>",...]
DW
[<label>] dw <expr>[,<expr>,...,<expr>]
[<label>] dw "<text_string>"[,"<text_string>",...]
ELSE
else
END
end
ENDC
endc
ENDIF
endif
ENDM
endm
ENDW
endw
EQU
Define an Assembly
Constant
<label>
ERROR
error "<text_string>"
DS33014G-page 36
[<expr>]
equ <expr>
Directive Language
MPASM
Description
Syntax
EXITM
exitm
EXPAND
expand
EXTERN
FILL
Fill Memory
[<label>] fill
GLOBAL
IDATA
_ _IDLOCS
Specify ID locations
_ _idlocs <expr>
IF
Begin Conditionally
Assembled Code Block
if
IFDEF
IFNDEF
ifndef <label>
#INCLUDE
include
LIST
Listing Options
list
LOCAL
local
MACRO
<label>
_ _MAXRAM
_ _maxram <expr>
MESSG
messg "<message_text>"
NOEXPAND
noexpand
NOLIST
nolist
ORG
<label>
PAGE
page
PAGESEL
pagesel <label>
PROCESSOR
processor <processsor_type>
RADIX
radix
RES
Reserve Memory
[<label>]
SET
Define an Assembler
Variable
<label>
SPACE
space
SUBTITLE
subtitle
<expr>, <count>
<expr>
<label>
<<include_file>> |"<include_file>"
[<list_option>,...,<list_option>]
<label>[,<label>]
macro
org
[<arg>,...,<arg>]
<expr>
<default_radix>
res
set
<mem_units>
<expr>
<expr>
"<sub_text>"
DS33014G-page 37
Description
Syntax
TITLE
title
UDATA
UDATA_ACS
UDATA_OVR
Begins overlayed
uninitialized data section
UDATA_SHR
#UNDEFINE
#undefine <label>
VARIABLE
variable <label>[=<expr>,...,<label>[=<expr>] ]
WHILE
while <expr>
DS33014G-page 38
"<title_text>"
Directive Language
_ _BADRAM Identify Unimplemented RAM
5.4.1
Syntax
_ _badram
5.4.2
<expr>[-<expr>][, <expr>[-<expr>]]
Description
The _ _MAXRAM and _ _BADRAM directives together flag accesses to
unimplemented registers. _ _BADRAM defines the locations of invalid RAM
addresses. This directive is designed for use with the _ _MAXRAM directive. A
_ _MAXRAM directive must proceed any _ _BADRAM directive. Each <expr>
must be less than or equal to the value specified by _ _MAXRAM. Once the
_ _MAXRAM directive is used, strict RAM address checking is enabled, using
the RAM map specified by _ _BADRAM. To specify a range of invalid
locations, use the syntax <minloc> - <maxloc>.
5.4.3
Example
See the example for _ _MAXRAM.
5.4.4
See Also
_ _MAXRAM
5.5
Syntax
bankisel <label>
5.5.2
Description
For use when generating an object file. This directive is an instruction to the
linker to generate the appropriate bank selecting code for an indirect access
of the address specified by <label>. Only one <label> should be specified.
No operations can be performed on <label>. <label> must have been
previously defined.
The linker will generate the appropriate bank selecting code. For 14-bit core
devices, the appropriate bit set/clear instruction on the IRP bit in the STATUS
register will be generated. For the 16-bit core devices, MOVLB or MOVLR will
be generated. If the user can completely specify the indirect address without
these instructions, no code will be generated.
For more information, refer to Chapter 6.
DS33014G-page 39
MPASM
5.4
Example
movlw
movwf
bankisel
...
movwf
5.5.4
INDF
See Also
BANKSEL
5.6
Var1
FSR
Var1
PAGESEL
Syntax
banksel <label>
5.6.2
Description
For use when generating an object file. This directive is an instruction to the
linker to generate bank selecting code to set the bank to the bank containing
the designated <label>. Only one <label> should be specified. No
operations can be performed on <label>. <label> must have been
previously defined.
The linker will generate the appropriate bank selecting code. For 12-bit core
devices, the appropriate bit set/clear instructions on the FSR will be
generated. For 14-bit devices, bit set/clear instructions on the STATUS
register will be generated. For the 16-bit core devices, MOVLB or MOVLR will
be generated. For the enhanced 16-bit core devices, MOVLB will be
generated. If the device contains only one bank of RAM, no instructions will
be generated.
For more information, refer to Chapter 6.
5.6.3
Example
banksel
movwf
5.6.4
See Also
BANKISEL
DS33014G-page 40
Var1
Var1
PAGESEL
Directive Language
MPASM
5.7
Syntax
cblock [<expr>]
<label>[:<increment>][,<label>[:<increment>]]
endc
5.7.2
Description
Define a list of named constants. Each <label> is assigned a value of one
higher than the previous <label>. The purpose of this directive is to assign
address offsets to many labels. The list of names end when an ENDC directive
is encountered.
<expr> indicates the starting value for the first name in the block. If no
expression is found, the first name will receive a value one higher than the
final name in the previous CBLOCK. If the first CBLOCK in the source file has no
<expr>, assigned values start with zero.
If <increment> is specified, then the next <label> is assigned the value of
<increment> higher than the previous <label>.
Multiple names may be given on a line, separated by commas.
cblock is useful for defining constants in program and data memory.
5.7.3
Example
cblock 0x20
; name_1 will be
; assigned 20
name_1, name_2 ; name_2, 21 and so on
name_3, name_4 ; name_4 is assigned 23.
endc
cblock 0x30
TwoByteVar: 0, TwoByteHigh, TwoByteLow
Queue: QUEUE_SIZE
QueueHead, QueueTail
Double1:2, Double2:2
endc
5.7.4
See Also
ENDC
5.8
Syntax
[<label>]
code
[<ROM address>]
DS33014G-page 41
Description
For use when generating an object file. Declares the beginning of a section of
program code. If <label> is not specified, the section is named .code. The
starting address is initialized to the specified address or will be assigned at link
time if no address is specified.
Note:
Two sections in the same source file may not have the same name.
5.8.3
Example
RESET
5.8.4
H01FF
START
See Also
EXTERN
5.9
code
goto
GLOBAL
IDATA
UDATA
UDATA_ACS
UDATA_OVR
UDATA_SHR
Syntax
_ _config <expr> OR _ _config <addr>, <expr>
5.9.2
Description
Sets the processors configuration bits to the value described by <expr>. For
PIC18CXX devices, the address of a valid configuration byte must also be
specified by <addr>. Refer to the PICmicro Microcontroller Data Book for a
description of the configuration bits for each processor.
Before this directive is used, the processor must be declared through the
command line, the LIST directive, or the PROCESSOR directive. If this directive is
used with the PIC17CXX family, the hex file output format must be set to INHX32
through the command line or the LIST directive.
5.9.3
Example
list p=17c42,f=INHX32
_ _config HFFFF
;Default configuration bits
5.9.4
See Also
_ _IDLOCS
DS33014G-page 42
LIST
PROCESSOR
Directive Language
MPASM
Syntax
constant <label>=<expr> [...,<label>=<expr>]
5.10.2
Description
Creates symbols for use in MPASM expressions. Constants may not be reset
after having once been initialized, and the expression must be fully resolvable
at the time of the assignment. This is the principal difference between
symbols declared as CONSTANT and those declared as VARIABLE, or created
by the SET directive. Otherwise, constants and variables may be used
interchangeably in expressions.
5.10.3
Example
variable RecLength=64
; Set Default
;
RecLength
constant BufLength=512
; Init BufLength
.
; RecLength may
.
; be reset later
.
; in RecLength=128
.
;
constant MaxMem=RecLength+BufLength ;CalcMaxMem
5.10.4
See Also
SET
VARIABLE
DS33014G-page 43
Syntax
[<label>] da <expr> [, <expr2>, ..., <exprn>]
5.11.2
Description
Generates a packed 14-bit number representing two 7-bit ASCII characters.
This is useful for storing strings in memory for the PICmicro Flash ROM
devices.
5.11.3
Examples
da "abcdef"
will put 30E2 31E4 32E6 3380 into program memory
da "12345678" ,0
will put 18B2 19B4 1AB6 0000 into program memory
da 0xFFFF
will put 0x3FFF into program memory
Syntax
[<label>] data <expr>,[,<expr>,...,<expr>]
[<label>] data "<text_string>"[,"<text_string>",...]
5.12.2
Description
Initialize one or more words of program memory with data. The data may be in
the form of constants, relocatable or external labels, or expressions of any of
the above. The data may also consist of ASCII character strings,
<text_string>, enclosed in single quotes for one character or double
quotes for strings. Single character items are placed into the low byte of the
word, while strings are packed two to a word. If an odd number of characters
are given in a string, the final byte is zero. On all families except the
PIC18CXX, the first character is in the most significant byte of the word. On
the PIC18CXX, the first character is in the least significant byte of the word.
When generating an object file, this directive can also be used to declare
initialized data values. Refer to the IDATA directive for more information.
DS33014G-page 44
Directive Language
Example
data
data
data
data
data
5.12.4
MPASM
5.12.3
reloc_label+10
1,2,ext_label
"testing 1,2,3"
N
start_of_program
;
;
;
;
;
constants
constants, externals
text string
single character
relocatable label
See Also
DB
DE
DT
DW
IDATA
Syntax
[<label>] db <expr>[,<expr>,...,<expr>]
5.13.2
Description
Reserve program memory words with packed 8-bit values. Multiple
expressions continue to fill bytes consecutively until the end of expressions.
Should there be an odd number of expressions, the last byte will be zero.
When generating an object file, this directive can also be used to declare
initialized data values. Refer to the IDATA directive for more information.
5.13.3
Example
db t, 0x0f, e, 0x0f, s, 0x0f, t, \n
5.13.4
See Also
DATA
DE
DT
DW
IDATA
Syntax
[<label>] de <expr> [, <expr>, ..., <expr>]
5.14.2
Description
Reserve memory words with 8-bit data. Each <expr> must evaluate to an
8-bit value. The upper bits of the program word are zeroes. Each character in
a string is stored in a separate word.
Although designed for initializing EEPROM data on the PIC16C8X, the
directive can be used at any location for any processor.
DS33014G-page 45
Example
org H2100
; Initialize EEPROM Data
de "My Program, v1.0", 0
5.14.4
See Also
DATA
DB
DT
DW
Syntax
#define <name> [<string>]
5.15.2
Description
This directive defines a text substitution string. Wherever <name> is
encountered in the assembly code, <string> will be substituted.
Using the directive with no <string> causes a definition of <name> to be
noted internally and may be tested for using the IFDEF directive.
This directive emulates the ANSI C standard for #define. Symbols defined
with this method are not available for viewing using MPLAB.
5.15.3
Example
#define
#define
#define
length
20
control 0x19,7
position(X,Y,Z) (Y-(2 * Z +X))
:
:
test_label dw position(1, length, 512)
bsf control
; set bit 7 in f19
5.15.4
See Also
#UNDEFINE
DS33014G-page 46
IFDEF
IFNDEF
Directive Language
MPASM
Syntax
[<label>] dt <expr> [, <expr>, ..., <expr>]
5.16.2
Description
Generates a series of RETLW instructions, one instruction for each <expr>.
Each <expr> must be an 8-bit value. Each character in a string is stored in
its own RETLW instruction.
5.16.3
Example
dt
dt
5.16.4
"A Message", 0
FirstValue, SecondValue, EndOfValues
See Also
DATA
DB
DE
DW
Syntax
[<label>] dw <expr>[,<expr>,...,<expr>]
5.17.2
Description
Reserve program memory words for data, initializing that space to specific
values. For PIC18CXX devices, DW functions like DB. Values are stored into
successive memory locations and the location counter is incremented by one.
Expressions may be literal strings and are stored as described in the DATA
directive.
When generating an object file, this directive can also be used to declare
initialized data values. Refer to the IDATA directive for more information.
5.17.3
Example
dw 39, "diagnostic 39", (d_list*2+d_offset)
dw diagbase-1
5.17.4
See Also
DATA
DB
IDATA
DS33014G-page 47
Syntax
else
5.18.2
Description
Used in conjunction with an IF directive to provide an alternative path of
assembly code should the IF evaluate to false. ELSE may be used inside a
regular program block or macro.
5.18.3
Example
speed macro rate
if rate < 50
dw slow
else
dw fast
endif
endm
5.18.4
See Also
ENDIF
IF
Syntax
end
5.19.2
Description
Indicates the end of the program.
5.19.3
Example
list p=17c42
:
; executable code
:
;
end
; end of instructions
DS33014G-page 48
Directive Language
5.20.1
Syntax
endc
5.20.2
Description
ENDC terminates the end of a CBLOCK list. It must be supplied to terminate the
list.
5.20.3
See Also
CBLOCK
Syntax
endif
5.21.2
Description
This directive marks the end of a conditional assembly block. ENDIF may be
used inside a regular program block or macro.
5.21.3
See Also
ELSE
IF
Syntax
endm
5.22.2
Description
Terminates a macro definition begun with MACRO.
5.22.3
Example
make_table macro arg1, arg2
dw arg1, 0 ; null terminate table name
res arg2
; reserve storage
endm
DS33014G-page 49
MPASM
See Also
MACRO
EXITM
Syntax
endw
5.23.2
Description
ENDW terminates a WHILE loop. As long as the condition specified by the
WHILE directive remains true, the source code between the WHILE directive
and the ENDW directive will be repeatedly expanded in the assembly source
code stream. This directive may be used inside a regular program block or
macro.
5.23.3
Example
See the example for WHILE
5.23.4
See Also
WHILE
Syntax
<label> equ <expr>
5.24.2
Description
The value of <expr> is assigned to <label>.
5.24.3
Example
four equ 4 ; assigned the numeric value of 4
; to label four
5.24.4
See Also
SET
DS33014G-page 50
Directive Language
MPASM
Syntax
error "<text_string>"
5.25.2
Description
<text_string> is printed in a format identical to any MPASM error
message. <text_string> may be from 1 to 80 characters.
5.25.3
Example
error_checking macro arg1
if arg1 >= 55 ; if arg is out of range
error "error_checking-01 arg out of range"
endif
endm
5.25.4
See Also
MESSG
Syntax
errorlevel {0|1|2|+<msgnum>|-<msgnum>} [, ...]
5.26.2
Description
Sets the types of messages that are printed in the listing file and error file.
Setting
0
1
2
-<msgnum>
+<msgnum>
Affect
Messages, warnings, and errors printed
Warnings and errors printed
Errors printed
Inhibits printing of message <msgnum>
Enables printing of message <msgnum>
5.26.3
Example
errorlevel 1, -202
DS33014G-page 51
See Also
LIST
Syntax
exitm
5.27.2
Description
Force immediate return from macro expansion during assembly. The effect is
the same as if an ENDM directive had been encountered.
5.27.3
Example
test macro filereg
if filereg == 1 ; check for valid file
exitm
else
error "bad file assignment"
endif
endm
5.27.4
See Also
ENDM
MACRO
Syntax
expand
5.28.2
Description
Expand all macros in the listing file. This directive is roughly equivalent to the
/m MPASM command line option, but may be disabled by the occurrence of a
subsequent NOEXPAND.
5.28.3
See Also
MACRO
DS33014G-page 52
NOEXPAND
Directive Language
5.29.1
Syntax
extern
5.29.2
<label> [, <label>...]
Description
For use when generating an object file. Declares symbol names that may be
used in the current module but are defined as global in a different module.
The EXTERN statement must be included before the <label> is used. At
least one label must be specified on the line. If <label> is defined in the
current module, MPASM will generate a duplicate label error.
For more information, refer to Chapter 6.
5.29.3
Example
extern
...
call
5.29.4
Function
Function
See Also
GLOBAL
IDATA
TEXT
UDATA
UDATA_ACS
UDATA_OVR
UDATA_SHR
Syntax
[<label>] fill <expr>,<count>
5.30.2
Description
Generates <count> occurrences of the program word or byte (PIC18CXX
devices), <expr>. If bounded by parentheses, <expr> can be an assembler
instruction.
5.30.3
Example
fill 0x1009, 5 ; fill with a constant
fill (GOTO RESET_VECTOR), NEXT_BLOCK-$
5.30.4
See Also
DATA
DW
ORG
DS33014G-page 53
MPASM
Syntax
global
5.31.2
<label>
[, <label>...]
Description
For use when generating an object file. Declares symbol names that are
defined in the current module and should be available to other modules. The
GLOBAL statement must be after the <label> is defined. At least one label
must be specified on the line.
For more information, refer to Chapter 6.
5.31.3
Example
udata
res
1
res
1
global Var1, Var2
code
Var1
Var2
AddThree
global AddThree
addlw 3
return
5.31.4
See Also
EXTERN
IDATA
TEXT
UDATA
UDATA_ACS
UDATA_OVR
UDATA_SHR
Syntax
[<label>]
5.32.2
idata
[<RAM address>]
Description
For use when generating an object file. Declares the beginning of a section of
initialized data. If <label> is not specified, the section is named .idata. The
starting address is initialized to the specified address or will be assigned at
link time if no address is specified. No code can be generated in this segment.
DS33014G-page 54
Directive Language
The RES, DB and DW directives may be used to reserve space for variables.
RES will generate an initial value of zero. DB will initialize successive bytes of
RAM. DW will initialize successive bytes of RAM, one word at a time, in lowbyte/high-byte order.
For more information, refer to Chapter 6.
5.32.3
Example
LimitL
LimitH
Gain
Flags
String
5.32.4
idata
dw
0
dw D300
dw D5
db 0
db Hi there!
See Also
EXTERN
GLOBAL
TEXT
UDATA
UDATA_ACS
UDATA_OVR
UDATA_SHR
Syntax
_ _idlocs <expr> or _ _idlocs <expr1>, <expr2>
5.33.2
Description
For PIC12CXX, PIC14000, and PIC16CXX devices, _ _idlocs sets the four
ID locations to the hexadecimal value of <expr>. For PIC18CXX devices,
_ _ idlocs sets the two-byte device ID <expr1> to the hexadecimal value of
<expr2>. This directive is not valid for the PIC17CXX family.
For example, if <expr> evaluates to 1AF, the first (lowest address) ID location
is zero, the second is one, the third is ten, and the fourth is fifteen.
Before this directive is used, the processor must be declared through the
command line, the LIST directive, or the PROCESSOR directive.
5.33.3
Example
_ _idlocs H1234
5.33.4
See Also
LIST
PROCESSOR
_ _CONFIG
DS33014G-page 55
MPASM
The linker will generate a look-up table entry for each byte specified in an idata
section. The user must then link or include the appropriate initialization code.
See Chapter 9 for examples of initialization codes for various PICmicro families.
Note that this directive is not available for 12-bit core devices.
Syntax
if <expr>
5.34.2
Description
Begin execution of a conditional assembly block. If <expr> evaluates to true,
the code immediately following the IF will assemble. Otherwise, subsequent
code is skipped until an ELSE directive or an ENDIF directive is encountered.
An expression that evaluates to zero is considered logically FALSE. An
expression that evaluates to any other value is considered logically TRUE. The
IF and WHILE directives operate on the logical value of an expression. A
relational TRUE expression is guaranteed to return a nonzero value, FALSE a
value of zero.
5.34.3
Example
if version == 100; check current version
movlw 0x0a
movwf io_1
else
movlw 0x01a
movwf io_2
endif
5.34.4
See Also
ELSE
ENDIF
Syntax
ifdef <label>
5.35.2
Description
If <label> has been previously defined, usually by issuing a #DEFINE
directive or by setting the value on the MPASM command line, the conditional
path is taken. Assembly will continue until a matching ELSE or ENDIF
directive is encountered.
DS33014G-page 56
Directive Language
Example
#define testing 1
; set testing "on"
:
:
ifdef
testing
<execute test code> ; this path would
endif
; be executed.
5.35.4
See Also
#DEFINE
ELSE
ENDIF
IFNDEF
#UNDEFINE
Syntax
ifndef <label>
5.36.2
Description
If <label> has not been previously defined, or has been undefined by
issuing an #UNDEFINE directive, then the code following the directive will be
assembled. Assembly will be enabled or disabled until the next matching
ELSE or ENDIF directive is encountered.
5.36.3
Example
#define
testing1
:
:
#undefine testing1
ifndef testing
:
:
endif
end
5.36.4
;
;
;
;
;
;
;
end of source
See Also
#DEFINE
; set testing on
ELSE
ENDIF
IFDEF
INE
#UNDEF
DS33014G-page 57
MPASM
5.35.3
Syntax
include <<include_file>>
include "<include_file>"
5.37.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 six levels of nesting are permitted.
<include_file> may 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
executable directory.
5.37.3
Example
include "c:\sys\sysdefs.inc" ; system defs
include <regs.h>
; register defs
Syntax
list [<list_option>, ..., <list_option>]
5.38.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 the following
list options can be supplied to control the assembly process or format the
listing file:
Table 5.2: List Directive Options
Option
DS33014G-page 58
Default
Description
b=nnn
c=nnn
132
f=<format>
INHX8M
free
FIXED
fixed
FIXED
mm={ON|OFF}
On
Directive Language
MPASM
Description
n=nnn
60
p=<type>
None
r=<radix>
hex
st={ON|OFF}
On
t={ON|OFF}
Off
w={0|1|2}
x={ON|OFF}
On
Note:
5.38.3
Default
Example
list p=17c42, f=INHX32, r=DEC
5.38.4
See Also
ERRORLEVEL
EXPAND
NOEXPAND
NOLIST
PROCESSOR
RADIX
Syntax
local <label>[,<label>...]
5.39.2
Description
Declares that the specified data elements are to be considered in local
context to the macro. <label> 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.
5.39.3
Example
<main code segment>
:
:
len
equ 10
size equ 20
;
;
;
test macro size
;
local len, label ;
len
set size
;
label res len
;
len
set len-20
;
endm
;
global version
note that a local variable
may now be created and modified
local len and label
modify local len
reserve buffer
end macro
DS33014G-page 59
See Also
ENDM
MACRO
Syntax
<label> macro [<arg>, ..., <arg>]
5.40.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.
A macro can call another macro, or may call itself recursively.
Please refer to Chapter 5, Macro Language for more information.
5.40.3
Example
Read macro
movlw
movwf
movlw
movwf
movlw
call
endm
5.40.4
See Also
ELSE
ENDIF
ENDM
EXITM
IF
LOCAL
Syntax
_ _maxram
5.41.2
<expr>
Description
The _ _MAXRAM and _ _BADRAM directives together flag accesses to
unimplemented registers. _ _MAXRAM defines the absolute maximum valid
RAM address and initializes the map of valid RAM addresses to all addresses
valid at and below <expr>. <expr> must be greater than or equal to the
maximum page 0 RAM address and less than 1000H. This directive is
DS33014G-page 60
Directive Language
_ _MAXRAM can be used more than once in a source file. Each use redefines
the maximum valid RAM address and resets the RAM map to all locations.
5.41.3
Example
list p=16c622
_ _maxram H0BF
_ _badram H07-H09, H0D-H1E
_ _badram H87-H89, H8D, H8F-H9E
movwf
H07 ; Generates invalid RAM warning
movwf
H87 ; Generates invalid RAM warning
;
and truncation message
5.41.4
See Also
_ _BADRAM
Syntax
messg "<message_text>"
5.42.2
Description
Causes an informational message to be printed in the listing file. The
message text can be up to 80 characters. Issuing a MESSG directive does not
set any error return codes.
5.42.3
Example
mssg_macro macro
messg "mssg_macro-001 invoked without argument"
endm
5.42.4
See Also
ERROR
DS33014G-page 61
MPASM
designed for use with the _ _BADRAM directive. Once the _ _MAXRAM
directive is used, strict RAM address checking is enabled, using the RAM map
specified by _ _BADRAM.
Syntax
noexpand
5.43.2
Description
Turns off macro expansion in the listing file.
5.43.3
See Also
EXPAND
Syntax
nolist
5.44.2
Description
Turn off listing file output.
5.44.3
See Also
LIST
Syntax
[<label>] org <expr>
5.45.2
Description
Set the program origin for subsequent code at the address defined in
<expr>. If <label> is specified, it will be given the value of the <expr>. If
no ORG is specified, code generation will begin at address zero.
For PIC18CXX devices, only even <expr> values are allowed.
This directive may not be used when generating an object file.
DS33014G-page 62
Directive Language
MPASM
5.45.3
Example
int_1 org 0x20
; Vector 20 code goes here
int_2 org int_1+0x10
; Vector 30 code goes here
5.45.4
See Also
FILL
RES
Syntax
page
5.46.2
Description
Inserts a page eject into the listing file.
5.46.3
See Also
LIST
SUBTITLE
TITLE
Syntax
pagesel
5.47.2
<label>
Description
For use when generating an object file. An instruction to the linker to generate
page selecting code to set the page bits to the page containing the designated
<label>. Only one <label> should be specified. No operations can be
performed on <label>. <label> must have been previously defined.
The linker will generate the appropriate page selecting code. For 12-bit core
devices, the appropriate bit set/clear instructions on the STATUS register will
be generated. For 14-bit and 16-bit core devices, MOVLW and MOVWF
instructions will be generated to modify the PCLATH. If the device contains
only one page of program memory, no code will be generated.
For PIC18CXX devices, this command will do nothing.
For more information, refer to Chapter 6.
DS33014G-page 63
Example
pagesel
goto
....
pagesel
call
5.47.4
GotoDest
GotoDest
CallDest
CallDest
See Also
BANKISEL
BANKSEL
Syntax
processor <processor_type>
5.48.2
Description
Sets the processor type to <processor_type>.
5.48.3
Example
processor 16C54
5.48.4
See Also
LIST
Syntax
radix <default_radix>
5.49.2
Description
Sets the default radix for data expressions. The default radix is hex. Valid
radix values are: hex, dec, or oct.
5.49.3
Example
radix dec
5.49.4
See Also
LIST
DS33014G-page 64
Directive Language
MPASM
Syntax
[<label>] res <mem_units>
5.50.2
Description
Causes the memory location pointer to be advanced from its current location
by the value specified in <mem_units>. In non-relocatable code, <label> is
assumed to be a program memory address. In relocatable code (using
MPLINK), res can also be used to reserve data storage.
Address locations are defined in words for 12-, 14- and 16-bit PICmicros, and
bytes for enhanced 16-bit PICmicros.
5.50.3
Example
buffer res 64 ; reserve 64 address locations of storage
5.50.4
See Also
FILL
ORG
Syntax
<label> set <expr>
5.51.2
Description
<label> is assigned the value of the valid MPASM expression specified by
<expr>. The SET directive is functionally equivalent to the EQU directive
except that SET values may be subsequently altered by other SET directives.
5.51.3
Example
area
width
length
area
length
5.51.4
0
0x12
0x14
length * width
length + 1
See Also
EQU
set
set
set
set
set
VARIABLE
DS33014G-page 65
Syntax
space <expr>
5.52.2
Description
Insert <expr> number of blank lines into the listing file.
5.52.3
Example
space 3 ;Inserts three blank lines
5.52.4
See Also
LIST
Syntax
subtitle "<sub_text>"
5.53.2
Description
<sub_text> is an ASCII string enclosed in double quotes, 60 characters or
less in length. This directive establishes a second program header line for use
as a subtitle in the listing output.
5.53.3
Example
subtitle "diagnostic section"
5.53.4
See Also
TITLE
Syntax
title "<title_text>"
DS33014G-page 66
Directive Language
Description
<title_text> is a printable ASCII string enclosed in double quotes. It must
be 60 characters or less. This directive establishes the text to be used in the top
line of each page in the listing file.
5.54.3
Example
title "operational code, rev 5.0"
5.54.4
See Also
LIST
SUBTITLE
Syntax
[<label>]
5.55.2
udata
[<RAM address>]
Description
For use when generating an object file. Declares the beginning of a section of
uninitialized data. If <label> is not specified, the section is named .udata.
The starting address is initialized to the specified address or will be assigned at
link time if no address is specified. No code can be generated in this segment.
The RES directive should be used to reserve space for data.
Note:
Two sections in the same source file may not have the same name.
5.55.3
Example
udata
Var1
res 1
Double res 2
5.55.4
See Also
EXTERN
GLOBAL
IDATA
UDATA_ACS
UDATA_OVR
UDATA_SHR
TEXT
DS33014G-page 67
MPASM
5.54.2
Syntax
[<label>]
5.56.2
udata_acs
[<RAM address>]
Description
For use when generating an object file. Declares the beginning of a section of
access uninitialized data. If <label> is not specified, the section is
named .udata_acs. The starting address is initialized to the specified
address or will be assigned at link time if no address is specified. This
directive is used to declare variables that are allocated in access RAM of
PIC18CXX devices. No code can be generated in this segment. The RES
directive should be used to reserve space for data.
Note:
Two sections in the same source file may not have the same name.
5.56.3
Example
udata
Var1
res 1
Double res 2
5.56.4
See Also
EXTERN
GLOBAL
IDATA
UDATA
UDATA_OVR
UDATA_SHR
TEXT
Syntax
[<label>]
5.57.2
udata_ovr
[<RAM address>]
Description
For use when generating an object file. Declares the beginning of a section of
overlayed uninitialized data. If <label> is not specified, the section is
named .udata_ovr. The starting address is initialized to the specified
address or will be assigned at link time if no address is specified. The space
declared by this section is overlayed by all other udata_ovr sections of the
DS33014G-page 68
Directive Language
Note:
This is the exception to the rule that two sections in the same
source file may not have the same name.
5.57.3
Example
Temps
Temp1
Temp2
Temp3
Temps
LongTemp1
udata_ovr
res 1
res 1
res 1
udata_ovr
res 2 ; this
; same
LongTemp2 res 2 ; this
; same
5.57.4
See Also
EXTERN
GLOBAL
IDATA
UDATA
UDATA_ACS
UDATA_SHR
TEXT
Syntax
[<label>]
5.58.2
udata_shr
[<RAM address>]
Description
For use when generating an object file. Declares the beginning of a section of
shared uninitialized data. If <label> is not specified, the section is
named .udata_shr. The starting address is initialized to the specified
address or will be assigned at link time if no address is specified. This
directive is used to declare variables that are allocated in RAM that is shared
across all RAM banks (i.e. unbanked RAM). No code can be generated in this
segment. The RES directive should be used to reserve space for data.
Note:
Two sections in the same source file may not have the same name.
DS33014G-page 69
MPASM
Example
Temps
Temp1
Temp2
Temp3
5.58.4
udata_shr
res 1
res 1
res 1
See Also
EXTERN
GLOBAL
IDATA
UDATA
UDATA_ACS
UDATA_OVR
TEXT
Syntax
#undefine <label>
5.59.2
Description
<label> is an identifier previously defined with the #DEFINE directive. It
must be a valid MPASM label. The symbol named is removed from the symbol
table.
5.59.3
Example
#define
length 20
:
:
#undefine length
5.59.4
See Also
#DEFINE IFDEF INCLUDE IFNDEF
Syntax
variable <label>[=<expr>][,<label>[=<expr>]...]
5.60.2
Description
Creates symbols for use in MPASM expressions. Variables and constants
may be used interchangeably in expressions.
The VARIABLE directive creates a symbol that is functionally equivalent to
those created by the SET directive. The difference is that the VARIABLE
directive does not require that symbols be initialized when they are declared.
DS33014G-page 70
Directive Language
5.60.3
Example
Please refer to the example given for the CONSTANT directive.
5.60.4
See Also
CONSTANT
SET
Syntax
while <expr>
:
:
endw
5.61.2
Description
The lines between the WHILE and the ENDW are assembled as long as
<expr> evaluates to TRUE. An expression that evaluates to zero is
considered logically FALSE. An expression that evaluates to any other value is
considered logically TRUE. A relational TRUE expression is guaranteed to
return a non-zero value; FALSE a value of zero. A WHILE loop can contain at
most 100 lines and be repeated a maximum of 256 times.
5.61.3
Example
test_mac macro count
variable i
i = 0
while i < count
movlw i
i += 1
endw
endm
start
test_mac 5
end
5.61.4
See Also
ENDW
IF
DS33014G-page 71
MPASM
Note that variable values cannot be updated within an operand. You must
place variable assignments, increments, and decrements on separate lines.
DS33014G-page 72
6.1
Introduction
Since the introduction of MPASM v2.00 and MPLINK v1.00, users have had
the ability to generate and link precompiled object modules. Writing source
code that will be assembled to an object module is slightly different from
generating executable code directly to a hex file. MPASM routines designed
for absolute address assembly will require minor modifications to compile
correctly into relocatable object modules.
6.2
Highlights
Topics covered in this chapter:
Header Files
Program Memory
Instruction Operands
RAM Allocation
Configuration Bits and ID Locations
Accessing Labels from Other Modules
Paging and Banking Issues
Unavailable Directives
Generating the Object Module
Code Examples
6.3
Header Files
The Microchip supplied standard header files (e.g., p17c756.inc) should be
used when generating object modules. These header files define the special
function registers for the target processor.
DS33014G-page 73
MPASM
Program Memory
Program memory code must be preceded by a CODE section declaration.
6.4.1
Absolute Code:
Start
6.4.2
CLRW
OPTION
:
Relocatable Code:
CODE
Start CLRW
OPTION
:
If more than one CODE section is defined in a source file, each section must
have a unique name. If the name is not specified, it will be given the default
name .code.
Each program memory section must be contiguous within a single source file.
A section may not be broken into pieces within a singe source file.
The physical address of the code can be fixed by supplying the optional
address parameter of the CODE directive. Situations where this might be
necessary are:
Specifying interrupt vectors
Ensuring that a code segment does not overlap page boundaries
6.4.3
DS33014G-page 74
H0lFF
Start
CODE
CLRW
OPTION
where:
<relocatable symbol> is any label that defines a program or data
memory address
<constant offset> is an expression that is resolvable at assembly
time to a value between -32768 and 32767
Either <relocatable symbol> or <constant offset> may be omitted.
Operands of the form:
<relocatable symbol> - <relocatable symbol>
will be reduced to a constant value if both symbols are defined in the same
code or data section.
If HIGH is used, only bits 8 through15 of the expression will be used. If LOW is
used, only bits 0 through 7 of the expression will be used. If UPPER is used,
only bits 16 through 21 of the expression will be used.
6.6
RAM Allocation
RAM space must be allocated in a data section. Five types of data sections
are available:
UDATA Uninitialized data. This is the most common type of data section. Locations reserved in this section are not initialized and can be
accessed only by the labels defined in this section or by indirect
accesses.
UDATA_ACS Uninitialized access data. This data section is used for
variables that will be placed in access RAM of PIC18CXX devices.
Access RAM is used as quick data access for specified instructions.
UDATA_OVR Uninitialized overlaid data. 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. A typical use of this section is for temporary variables.
UDATA_SHR Uninitialized shared data. This data section is used for
variables that will be placed in RAM that is unbanked or shared across
all banks.
IDATA Initialized data. The linker will generate a lookup table that can
be used to initialize the variables in this section to the specified values.
The locations reserved by this section can be accessed only by the
labels defined in this section or by indirect accesses.
The following example shows how a data declaration might be created.
DS33014G-page 75
MPASM
6.5
Absolute Code:
CBLOCK
0x20
InputGain, OutputGain
HistoryVector
Templ, Temp2, Temp3
ENDC
6.6.2
Relocatable Code:
HistoryVector
IDATA
DB
0
InputGain
OutputGain
UDATA
RES 1
RES 1
Templ
Temp2
Temp3
UDATA_OVR
RES 1
RES 1
RES 1
6.6.3
Relocatable Code:
00001
00002
0000 01 02 03
00003
0003 34 12 78 56 00004
0007 41 42 43 00 00005
6.7
LIST p=17C44
IDATA
Bytes DB 1,2,3
Words DW H1234,H5678
String DB ABC, 0
DS33014G-page 76
6.8.1
UDATA
RES 1
RES 1
GLOBAL
InputGain, OutputGain
CODE
Filter
GLOBAL
:
6.8.2
Filter
; Filter code
UDATA
Reading RES 1
CODE
...
MOVLW
MOVWF
MOVLW
MOVWF
MOVF
CALL
6.9
GAIN1
InputGain
GAIN2
OutputGain
Reading,W
Filter
DS33014G-page 77
MPASM
6.8
Absolute Code:
#include
LIST P=12C509
P12C509.INC
Varl
Var2
EQU H'10'
EQU H'30'
...
MOVLW InitialValue
BCF FSR, 5
MOVWF Varl
BSF FSR, 5
MOVWF Var2
BSF STATUS, PA0
CALL Subroutine
...
Subroutine CLRW
;In Page 1
...
RETLW 0
6.9.2
Relocatable Code:
#include
LIST P=12C509
P12C509.INC
UDATA
RES 1
RES 1
...
CODE
MOVLW InitialValue
BANKSEL Varl
MOVWF Varl
BANKSEL Var2
MOVWF Var2
PAGESEL Subroutine
CALL Subroutine
...
Subroutine CLRW
...
RETLW 0
Varl
Var2
DS33014G-page 78
Macro capability and nearly all directives are available when generating an
object file. The only directive that is not allowed is the ORG directive. This can
be replaced by specifying an absolute CODE segment, as shown below.
6.10.1
Absolute Code:
Reset ORG H01FF
GOTO Start
6.10.2
Relocatable Code:
Reset CODE H0lFF
GOTO Start
6.12.1
Absolute Code:
LIST P=16C54
#INCLUDE P16C5x.INC
mulcnd
mulplr
H_byte
L_byte
count
mpy
cblock H 020
RES 1
; 8 bit multiplicand
RES 1
; 8 bit multiplier
RES 1
; High byte of the 16 bit result
RES 1
; Low byte of the 16 bit result
RES 1
; loop counter
clrf H_byte
clrf L_byte
movlw 8
movwf count
movf mulcnd,w
bcf STATUS,C ;Clear carry bit
DS33014G-page 79
MPASM
rrf mulplr,F
btfsc STATUS,C
addwf H_byte,F
rrf H_byte,F
rrf L_byte,F
decfsz count,F
goto loop
retlw 0
;*******************************************************
;
Test Program
;*******************************************************
start
clrw
option
main
movf PORTB,w
movwf mulplr ; multiplier (in mulplr) = 05
movf PORTB,W
movwf mulcnd
call_m
call mpy
goto main
ORG 01FFh
goto start
END
Since a eight-by-eight bit multiply is a useful, generic routine, it would be
handy to break this off into a separate object file that can be linked in when
required. The above file can be broken into two files, a calling file representing
an application and a generic routine that could be incorporated in a library.
6.12.2
CODE
DS33014G-page 80
start
clrw
option
main
movf PORTB, W
movwf mulplr
movf PORTB, W
movwf mulcnd
call_m call mpy
goto main
Reset
CODE H0lFF
goto start
END
6.12.3
mulcnd
mulplr
H_byte
L_byte
count
UDATA
RES l ; 8 bit multiplicand
RES 1 ; 8 bit multiplier
RES 1 ; High byte of the 16 bit result
RES 1 ; Low byte of the 16 bit result
RES 1 ; loop counter
GLOBAL mulcnd, mulplr, H_byte, L_byte
CODE
mpy
GLOBAL
loop
mpy
clrf H_byte
clrf L_byte
movlw 8
movwf count
movf muland, W
bcf STATUS, C
; Clear carry bit
rrf mulplr, F
btfsc STATUS, C
addwf H_byte, F
rrf H_byte, F
rrf L_byte, F
decfsz count, F
goto loop
retlw 0
END
DS33014G-page 81
DS33014G-page 82
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.
Macros consist of sequences of assembler instructions and directives. They
can be written to accept arguments, making them quite flexible. Their
advantages are:
Higher levels of abstraction, improving readability and reliability.
Consistent solutions to frequently performed functions.
Simplified changes.
Improved testability.
Applications might include creating complex tables, frequently used code, and
complex operations.
7.2
Highlights
Topics covered in this chapter:
Macro Syntax
Macro Directives
Text Substitution
Macro Usage
Code Examples
7.3
Macro Syntax
MPASM macros are defined according to the following syntax:
<label> macro [<arg1>,<arg2> ..., <argn>]
:
:
endm
where <label> is a valid MPASM label and <arg> is any number of optional
arguments supplied to the macro. 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.
DS33014G-page 83
7.4
Macro Directives
There are directives that are unique to macro definitions. They cannot be
used out of the macro context (refer to Chapter 7 for details concerning these
directives):
MACRO
LOCAL
EXITM
ENDM
When writing macros, you can use any of these directives PLUS any other
directives supported by MPASM.
Note:
7.5
Text Substitution
String replacement and expression evaluation may appear within the body of
a macro.
Command
Description
<arg>
#v(<expr>)
Arguments may be used anywhere within the body of the macro, except as
part of normal expression. For example, the following macro:
DS33014G-page 84
Macro Language
macro
local
while
dw 0
entry#v(a)
a += 1
MPASM
define_table
a = 0
a < 3
endw
endm
when invoked, would generate:
entry0
entry1
entry2
entry3
7.6
dw
dw
dw
dw
0
0
0
0
Macro Usage
Once the macro has been defined, it can be invoked at any point within the
source module by using a macro call, as described below:
<macro_name>
DS33014G-page 85
Code Examples
7.7.1
Eight-by-Eight Multiply
subtitle
page
macro definitions
;
; multiply - eight by eight multiply macro, executing
; in program memory. optimized for speed, straight
; line code.
;
; written for the PIC17C42.
;
multiply macro arg1, arg2,
dest_hi, dest_lo
;
local i = 0
; establish local index variable
; and initialize it.
;
movlw arg1
; setup multiplier
movwf mulplr ;
;
movlw arg2
; setup multiplicand in w reg
;
clrf dest_hi ; clear the destination regs
clrf dest_lo ;
;
bcf _carry
; clear carry for test
;
while i < 8
; do all eight bits
addwf dest_hi ; then add multiplicand
rrcf dest_hi ; shift right through carry
rrcf dest_lo ; shift right again, snag carry
; if set by previous rotate
i += 1
; increment loop counter
endw
; break after eight iterations
endm
; end of macro.
The macro declares all of the required arguments. In this case, there are four.
The LOCAL directive then establishes a local variable i that will be used as
an index counter. It is initialized to zero.
A number of assembler instructions are then included. When the macro is
executed, these instructions will be written in line with the rest of the
assembler source code.
The macro writes the multiplication code using an algorithm that uses right
shifts and adds for each bit set in the eight bits of the multiplier. The WHILE
directive is used for this function, continuing the loop until i is greater than
or equal to eight.
DS33014G-page 86
Macro Language
7.7.2
Constant Compare
As another example, if the following macro were written:
include 16cxx.reg
;
; compare file to constant and jump if file
; >= constant.
;
cfl_jge macro file, con, jump_to
movlw con & 0xff
subwf file, w
btfsc status, carry
goto
jump_to
endm
and invoked by:
cfl_jge
it would produce:
movlw
subwf
btfsc
goto
DS33014G-page 87
MPASM
The end of the loop is noted by the ENDW directive. Execution continues with
the statement immediately following the ENDW when the WHILE condition
becomes FALSE. The entire macro is terminated by the ENDM directive.
DS33014G-page 88
8.1
Introduction
This chapter describes various expression formats, syntax, and operations
used by MPASM.
8.2
Highlights
Topics covered in this chapter:
Text Strings
Numeric Constants and Radix
Arithmetic Operators and Precedence
High/Low/Upper and Increment/Decrement Operators
8.3
Text Strings
A string is a sequence of any valid ASCII character (of the decimal range of
0 to 127) enclosed by double quotes.
Strings may be of any length that will fit within a 255 column source line. If a
matching quote mark is found, the string ends. If none is found before the end
of the line, the string will end at the end of the line. While there is no direct
provision for continuation onto a second line, it is generally no problem to use
a second DW directive for the next line.
The DW directive will store the entire string into successive words. If a string
has an odd number of characters (bytes), the DW and DATA directives will pad
the end of the string with one byte of zero (00).
If a string is used as a literal operand, it must be exactly one character long, or
an error will occur.
DS33014G-page 89
MPASM
7374
6F75
2073
6720
696E
7470
7472
6F6E
dw
#define
B061
7465
6720
7420
7574
696E
7374
6669
6F75
2073
6700
696E
7273
7470
7472
\b
Backspace character
08
\f
0C
\n
0A
\r
0D
\t
09
\v
0B
Backslash
5C
3F
\\
\?
DS33014G-page 90
Hex
Value
Description
07
27
22
\0OO
\xHH
Hexadecimal number
Syntax
Example
Decimal
D<digits>
D100
Hexadecimal
H<hex_digits>
0x<hex_digits>
H9f
0x9f
Octal
O<octal_digits>
O777
Binary
B<binary_digits>
B00111001
ASCII
<character>
A<character>
C
AC
Current/Return program
counter
goto $ + 3
Left Parenthesis
1 + (d * 4)
Right Parenthesis
(Length + 1) * 256
-1 * Length
Complement
flags = ~flags
Example
DS33014G-page 91
MPASM
8.4
Multiply
a = b * c
Divide
a = b / c
Modulus
entry_len = tot_len % 16
Add
tot_len = entry_len * 8 + 1
Subtract
entry_len = (tot - 1) / 8
<<
Left shift
>>
Right shift
>=
Greater or equal
>
Greater than
<
Less than
Less or equal
<=
DS33014G-page 92
Example
==
Equal to
if entry_idx == num_entries
Not equal to
if entry_idx != num_entries
&
Bitwise AND
Bitwise exclusive OR
Bitwise inclusive OR
&&
Logical AND
||
Logical OR
if (len == 512) || (b == c)
Set equal to
entry_index = 0
+=
entry_index += 1
-=
entry_index -= 1
*=
entry_index *= entry_length
/=
entry_total /= entry_length
%=
entry_index %= 8
<<=
flags <<= 3
>>=
flags >>= 3
&=
|=
flags |= ERROR_FLAG
^=
flags ^= ERROR_FLAG
++
Increment
i ++
--
Decrement
i --
8.5
High/Low/Upper
8.5.1
Syntax
high <operand>
low
<operand>
upper <operand>
8.5.2
Description
These operators are used to return one byte of a multi-byte label value. This is
done to handle dynamic pointer calculations as might be used with table read
and write instructions.
8.5.3
Example
movlw
movpf
movlw
movpf
8.6
low size
; handle the lsbs
wreg, low size_lo
high size
; handle the msbs
wreg, high size_hi
Increment/Decrement (++/--)
8.6.1
Syntax
<variable>++
<variable>--
8.6.2
Description
Increments or decrements a variable value. These operators can only be used
on a line by themselves; they cannot be embedded within other expression
evaluation.
8.6.3
Example
LoopCount = 4
while LoopCount > 0
rlf Reg, f
LoopCount -endw
DS33014G-page 93
DS33014G-page 94
Introduction
This chapter discusses initialization code for various PICmicro devices.
9.2
Highlights
Topic covered int this chapter:
Initialization Code Examples
9.3
DS33014G-page 95
DS33014G-page 96
DS33014G-page 97
MPLINK
DS33014G-page 98
Introduction
This chapter will define what MPLINK is and how it can help you develop
firmware for PICmicro devices.
1.2
Highlights
Topics covered in this chapter:
MPLINK
What MPLINK Is
What MPLINK Does
How MPLINK Helps You
MPLINK Examples
Tool Versions and Platforms Supported
1.3
What MPLINK Is
MPLINK is a linker for the Microchip relocatable assembler, MPASM, and the
Microchip C compiler, MPLAB-C17/C18. For more information on MPASM,
see Part 1 of this document. For more information on MPLAB-C17/C18, see
the MPLAB-C17/C18 Compiler Users Guide (DS51112).
MPLINK also may be used with the Microchip librarian, MPLIB. See Part 3 of
this document for more information on MPLIB.
MPLINK is designed to be used with MPLAB, though it does not have to be.
However, once an application is built, it is convenient to use MPLAB to test
and debug the code using the simulator or an emulator, and to use a device
programmer to program a part. For more information on MPLAB, see the
MPLAB Users Guide (DS51025).
1.4
DS33014G-page 99
1.5
1.6
MPLINK Examples
You can learn how to use MPLINK from the four sample applications at the
end of this part. These sample applications can be used as templates for your
own application.
Sample Application 1
- How to place program code in different memory regions
- How to place data tables in ROM memory
- How to set configuration bits in C
DS33014G-page 100
MPLINK Preview
Sample Application 2
- How to partition memory for a boot loader
- How to compile code that will be loaded into external RAM and
executed
Sample Application 3
- How to access peripherals that are memory mapped
- How to create new sections
Sample Application 4
1.7
Platforms Supported
DS33014G-page 101
MPLINK
DS33014G-page 102
Introduction
This chapter will tell you how to install MPLINK on your system and give you
an overview of how the linker (MPLINK) works.
2.2
Highlights
Topics covered in this chapter:
MPLINK
Installation
Overview of Linker
Linker Input/Output Files
2.3
Installation
There are two versions of MPLINK. MPLINKD.EXE is a DOS extender version
and is only recommended for DOS or Windows 3.x systems. MPLINK.EXE is
a Windows 32-bit console application and is for Windows 95/98/NT.
MPLINKD.EXE and MPLINK.EXE are command-line applications.
MPLINKD.EXE may be used with DOS or a DOS window in Windows 3.x.
MPLINK.EXE may be used with a DOS window in Windows 95/98/NT. You
can use it with MPLAB (recommended).
If you are going to use MPLAB with MPLINK, you do not need to install the
linker and supporting files separately. When MPLAB is installed, MPLINK is
also installed. To find out how to install MPLAB, please refer to the MPLAB
Users Guide (DS51025). You may obtain the MPLAB software and users
guide either from the Microchip Technical Library CD or from our web site.
If you are not going to use MPLAB with MPLINK, you can obtain the linker and
supporting files separately either from the Microchip Technical Library CD or
from our web site. MPLINK is bundled with MPLIB into a zip file. To install:
Create a directory in which to place the files
Unzip the MPLINK and MPLIB files using either WinZip or PKZIP
DS33014G-page 103
Overview of Linker
Figure 2.1 is a diagram of how MPLINK works with other Microchip tools.
mult.c
avg.asm
add.asm
MPLAB-C17/C18 MPASM
mult.o
MPASM
avg.o
add.o
main.c
prog.asm
MPLAB-C17/C18
source
files
MPASM
main.o
prog.o
object
files
MPLIB
library
math.lib
MPLINK
prog.out
prog.cod
prog.hex
prog.lst
17c756.lkr
linker
script
prog.map
output
files
DS33014G-page 104
Source files (C or assembly code) are used when building the listing file.
2.5.1
DS33014G-page 105
MPLINK
2.5
2.5.3
2.5.4
2.5.5
2.5.6
2.5.7
2.5.8
DS33014G-page 106
2
Location
--------program
program
program
data
Size(Bytes)
--------0x000002
0x000004
0x000026
0x000005
The second table in the map file (Symbols Sorted by Name) provides
information about the symbols in the output module. The table is sorted by the
symbol name and includes the address of the symbol, whether the symbol
resides in program or data memory, whether the symbol has external or static
linkage, and the name of the file where defined. The following table is an
example of the symbol table sorted by symbol name in a map file:
Name
------call_m
loop
main
mpy
start
H_byte
L_byte
count
mulcnd
mulplr
Address
-------0x000026
0x00002e
0x000024
0x000028
0x000023
0x000022
0x000023
0x000024
0x000020
0x000021
Symbols Location
-------program
program
program
program
program
data
data
data
data
data
Sorted by Name
Storage
File
---------------static
C:\PROGRA~1\MPLAB\ASMFOO\sampobj.asm
static
C:\MPASMV2\MUL8X8.ASM
static
C:\PROGRA~1\MPLAB\ASMFOO\sampobj.asm
extern
C:\MPASMV2\MUL8X8.ASM
static
C:\PROGRA~1\MPLAB\ASMFOO\sampobj.asm
extern
C:\MPASMV2\MUL8X8.ASM
extern
C:\MPASMV2\MUL8X8.ASM
static
C:\MPASMV2\MUL8X8.ASM
extern
C:\MPASMV2\MUL8X8.ASM
extern
C:\MPASMV2\MUL8X8.ASM
DS33014G-page 107
MPLINK
Section
--------Reset
.cinit
.code
.udata
Section Info
Type
Address
--------- --------code
0x000000
romdata
0x000021
code
0x000023
udata
0x000020
DS33014G-page 108
Introduction
This chapter will describe how to use MPLINK on a DOS command line.
3.2
Highlights
Topic covered in this chapter:
Linker Command Line Options
You must have one command file (cmdfile) and at least one object file
(objfile).
cmdfile is the name of a linker command file. All linker command files
must have the extension '.lkr'.
objfile is the name of an assembler or compiler generated object file.
All object files must have the extension '.o'.
libfile is the name of a librarian created library file. All library files must
have the extension '.lib'.
option is a linker command line option described in Table 3.1.
Table 3.1: MPLINK Command Line Options
Option
Description
/o filename
/m filename
/l pathlist
/k pathlist
/n length
/h, /?
/a hexformat
/q
Quiet mode.
/d
DS33014G-page 109
MPLINK
3.3
/m MAIN.MAP /o MAIN.OUT
This instructs MPLINK to use the 17C756.LKR linker script file to link the
input modules MAIN.O, FUNCT.O, and the precompiled library ADC17.LIB. It
also instructs MPLINK to produce a map file named MAIN.MAP. MAIN.O and
FUNCT.O must have been previously compiled or assembled with
MPLAB-C17/C18 or MPASM. The output files MAIN.HEX and MAIN.COD file
will be produced if no errors occur during the link process.
DS33014G-page 110
Introduction
This chapter will describe how to use MPLINK with MPLAB projects.
4.2
Highlights
Topics contained in this chapter:
MPLAB Projects and MPLINK
MPLINK
4.3
C Source Files
Assembly Source Files
Library Files
Pre-Compiled Object Files
Linker Script Files
In this chapter, we are concerned with the relationship between MPLAB and
MPLINK. For more general information about MPLAB projects, consult the
MPLAB Users Guide (DS51025).
DS33014G-page 111
Project Files
Target Node
Language Tools
MPLINK
Properties
Source Node
.C
MPLABC17/C18
Properties
Source Node
.ASM
MPASM
Properties
.HEX
Library Node
.LIB
Object Node
.O
Linker Script
.LKR
DS33014G-page 112
MPLINK
DS33014G-page 113
DS33014G-page 114
MPLINK
DS33014G-page 115
DS33014G-page 116
4.6
MPLAB/MPLINK Troubleshooting
If have experienced problems, check the following:
DS33014G-page 117
MPLINK
DS33014G-page 118
Introduction
This chapter will describe how to make and modify linker scripts for use with
MPLINK.
5.2
Highlights
Topics covered in this chapter:
MPLINK
5.3
5.4
DS33014G-page 119
.;C:\PROJECTS\INCLUDE
LKRPATH
Linker command files that do not have a path are searched for using the linker
command file search path. The following directive appends additional search
directories to the linker command file search path:
LKRPATH lkrpath
where, lkrpath is a semicolon delimited list of directories.
Example:
To append the current directory's parent and the directory
C:\PROJECTS\SCRIPTS to the linker command file search path, the
following line should be added to the linker command file:
LKRPATH
..;C:\PROJECTS\SCRIPTS
FILES
The following directive specifies object or library files for linking:
FILES objfile/libfile [objfile/libfile...]
where, objfile/libfile is either an object or library file. Note, more
than one object or library file can be specified in a single FILES directive.
Example:
To specify that the object module main.o be linked with the library file
math.lib, the following line should be added to the linker command file:
FILES
main.o
math.lib
INCLUDE
The following directive includes an additional linker command file:
INCLUDE cmdfile
where, cmdfile is the name of the linker command file to include.
Example:
To include the linker command file named mylink.lkr, the following line
should be added to the linker command file:
INCLUDE
DS33014G-page 120
mylink.lkr
5.5.1
where:
memName is any ASCII string used to identify a CODEPAGE.
addr is a decimal or hexadecimal number specifying an address.
fillValue is a value which fills any unused portion of a memory block. If
this value is in decimal notation, it is assumed to be a 16-bit quantity. If it is in
hexadecimal notation (e.g., 0x2346), it may be any length divisible by full
words (16 bits).
The optional keyword PROTECTED indicates a region of memory that only can
be used by program code that specifically requests it.
DS33014G-page 121
MPLINK
The CODEPAGE directive is used for program code, initialized data values,
constant data values and external memory for PIC17CXX devices. It has the
following format:
5.5.2
Reset Vector
Interrupt Vectors
0000h
0008h
CODEPAGE vectors
0020h
CODEPAGE page0
07FFh
FE00h
CODEPAGE .config
FE10h
FF60h
FFFFh
5.5.3
Unbanked registers
SHAREBANK NAME=memName START=addr END=addr [PROTECTED]
Access registers (PIC18CXX only)
ACCESSBANK NAME=memName START=addr END=addr [PROTECTED]
where:
memName is any ASCII string used to identify an area in RAM.
addr is a decimal or hexadecimal number specifying an address.
The optional keyword PROTECTED indicates a region of memory that only can
be assigned to variables that are specifically identified in the source code.
DS33014G-page 122
Bank 0
Bank 1
Bank 2
00h
INDF0
01h
FSR0
0Eh
TBLPTRH
0Fh
BSR
PORTA
DDRC
11h
DDRB
PORTC
TMR1
PW1DCL
TMR2
PW2DCL
16h
TXREG
PIR
PR3LCA1L
TCON1
17h
SPBRG
PIE
PR3HCA1H
TCON2
18h
PRODL
19h
PRODH
1Ah
:
1Fh
20h
:
FFh
General
Purpose
RAM
General
Purpose
RAM
Not Used
DS33014G-page 123
MPLINK
10h
Bank 3
NAME=sfr0
NAME=sfr1
NAME=sfr2
NAME=sfr3
START=0x10
START=0x110
START=0x210
START=0x310
END=0x17
END=0x117
END=0x217
END=0x317
PROTECTED
PROTECTED
PROTECTED
PROTECTED
//Special
//Special
//Special
//Special
Function
Function
Function
Function
Registers
Registers
Registers
Registers
in
in
in
in
Bank0
Bank1
Bank2
Bank3
NAME=sfrnobnk
NAME=sfrnobnk
NAME=sfrnobnk
NAME=sfrnobnk
START=0x0
START=0x100
START=0x200
START=0x300
END=0xF
END=0x10F
END=0x20F
END=0x30F
PROTECTED
PROTECTED
PROTECTED
PROTECTED
//INDF0
//INDF0
//INDF0
//INDF0
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
NAME=sfrprod
NAME=sfrprod
NAME=sfrprod
NAME=sfrprod
START=0x18
START=0x118
START=0x218
START=0x318
END=0x19
END=0x119
END=0x219
END=0x319
PROTECTED
PROTECTED
PROTECTED
PROTECTED
//PRODL,
//PRODL,
//PRODL,
//PRODL,
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
NAME=gpr2
NAME=gpr2
NAME=gpr2
NAME=gpr2
START=0x1A
START=0x11A
START=0x21A
START=0x31A
END=0x1F
END=0x11F
END=0x21F
END=0x31F
PROTECTED
PROTECTED
PROTECTED
PROTECTED
//1A
//1A
//1A
//1A
DS33014G-page 124
thru
thru
thru
thru
thru
thru
thru
thru
BSR
BSR
BSR
BSR
PRODH
PRODH
PRODH
PRODH
1F
1F
1F
1F
available
available
available
available
available
available
available
available
available
available
available
available
in
in
in
in
in
in
in
in
in
in
in
in
all
all
all
all
all
all
all
all
all
all
all
all
banks
banks
banks
banks
banks
banks
banks
banks
banks
banks
banks
banks
where:
memName is a previously defined ACCESSBANK, SHAREBANK,
DATABANK, or CODEPAGE.
The ROM attribute must always refer to program memory previously defined
using a CODEPAGE directive. The RAM attribute must always refer to data
memory previously defined with a ACCESSBANK, DATABANK or
SHAREBANK directive.
Example:
To specify that a section whose name is filter_coeffs be loaded into the
previously defined logical block of program memory named constants, the
following line should be added to the linker command file:
Example 5.4: Logical Section Definition
SECTION NAME=filter_coeffs ROM=constants
To place MPASM source code into the filter_coeffs section, use the
following line prior to the desired source code:
Example 5.5: Logical Section Usage
filter_coeffs CODE
DS33014G-page 125
MPLINK
STACK Definition
MPLAB-C17/C18 requires a software stack be set up. The following statement
specifies the stack size and an optional DATABANK where the stack is to be
allocated:
STACK
SIZE=allocSize
[RAM=memName]
where:
allocSize is the size in bytes of the stack and memName is the name of
a memory previously declared using a ACCESSBANK, DATABANK or
SHAREBANK statement.
Example:
To set the stack size to be 0x20 in the RAM area previously defined by
gpr0, the following line should be added to the linker command file:
Example 5.6: Stack Definition
STACK SIZE=0x20
RAM=gpr0
5.8
DS33014G-page 126
Introduction
This chapter discusses how linker processing works.
6.2
Highlights
Topics covered in this chapter:
Linker Processing Overview
MPLINK
6.3
DS33014G-page 127
6.4
Absolute Assigned
Absolute Unassigned
Relocatable Assigned
Relocatable Unassigned
6.4.1
Absolute Allocation
Absolute sections may be assigned to target memory blocks in the linker
command file. But, since the absolute section's address is fixed, the linker can
only verify that if there is an assigned target memory block for an absolute
section, the target memory block has enough space and the absolute section
does not overlap other sections. If no target memory block is assigned to an
absolute section, the linker tries to find the one for it. If one can not be located,
an error is generated. Since absolute sections can only be allocated at a fixed
address, assigned and unassigned sections are performed in no particular
order.
6.4.2
Relocatable Allocation
Once all absolute sections have been allocated, the linker allocates
relocatable assigned sections. For relocatable assigned sections, the linker
checks the assigned target memory block to verify that there is space
available, otherwise its an error. The allocation of relocatable assigned
sections occurs in the order in which they were specified in the linker
command file.
After all relocatable assigned sections have been allocated, the linker
allocates relocatable unassigned sections. The linker starts with the largest
relocatable unassigned section and works its way down to the smallest
relocatable unassigned section. For each allocation, it chooses the target
memory block with the smallest available space that can accommodate the
section. By starting with the largest section and choosing the smallest
accommodating space, the linker increases the chances of being able to
allocate all the relocatable unassigned sections.
DS33014G-page 128
Linker Processing
The stack is not a section but gets allocated along with the sections. The
linker command file may or may not assign the stack to a specific target
memory block. If the stack is assigned a target memory block, it gets allocated
just before the relocatable assigned sections are allocated. If the stack is
unassigned, then it gets allocated after the relocatable assigned sections and
before the other relocatable unassigned sections are allocated.
6.5
Relocation Example
The following example illustrates how the linker relocates sections. 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-C17/C18 to
handle the functions entry and exit):
0x0000 MOVLW 0xFF
0x0001 MOVLR ??
0x0002 MOVWF ??
When the compiler processes source line 1, it creates a symbol table entry for
the identifier var1 which has the following information:
Symbol[index] => name=var1, value=0, section=.data,
class=extern
When the compiler processes source line 3, it generates two relocation
entries in the code section for the identifier symbol var1 since its final address
is unknown until link time. The relocation entries have the following
information:
Reloc[index] => address=0x0001 symbol=var1 type=bank
Reloc[index] => address=0x0002 symbol=var1 type=offset
Once the linker has placed every section into target memory, the final
addresses are known. Once all identifier symbols have their final addresses
assigned, the linker must patch all references to these symbols using the
relocation entries. In the example above, the updated symbol might now be at
location 0x125:
Symbol[index] => name=var1, value=0x125, section=.data,
class=extern
If the code section above were relocated to begin at address 0x50, the
updated relocation entries would now begin at location 0x51:
Reloc[index] => address=0x0051 symbol=var1 type=bank
Reloc[index] => address=0x0052 symbol=var1 type=offset
DS33014G-page 129
MPLINK
/* File: ref.c */
char var1;
/* Line 1 */
void setVar1(void) { /* Line 2 */
var1 = 0xFF;
/* Line 3 */
}
6.6
Initialized Data
MPLINK performs special processing for input sections with initialized data.
Initialized data sections contain initial values (initializers) for the variables and
constants defined within them. Because the variables and constants within an
initialized data section reside in RAM, their data must be stored in nonvolatile
program memory (ROM). For each initialized data section, the linker creates a
section in program memory. The data is moved by initializing code (supplied
with MPLAB-C17/C18 and MPASM) to the proper RAM location(s) at start-up.
The names of the initializer sections created by the linker are the same as the
initialized data sections with a _i appended. For example, if an input object
module contains an initialized data section named .idata_main.o the linker
will create a section in program memory with the name .idata_main.o_i
which contains the data.
In addition to creating initializer sections, the linker creates a section named
.cinit in program memory. The .cinit section contains a table with entries for
each initialized data section. Each entry is a triple which specifies where in
program memory the initializer section begins, where in data memory the
initialized data section begins, and how many bytes are in the initialized data
section. The boot code accesses this table and copies the data from ROM to
RAM.
DS33014G-page 130
Highlights
Topics covered in this chapter:
How to place program code in different memory regions
Overview
This example is for the PIC17C44 in extended microcontroller mode. It places
interrupt handling code written in assembly at 0x8000. The assembly code
directive, INTHAND CODE, places the code that follows into the INTHAND
section. The linker script maps the INTHAND section to the CODE region that
begins at 0x8000.
It also has a 0x1000 element data table in program memory in the same code
page with the interrupt handlers.
Note:
The data table is defined in C using the #pragma romdata directive to place
the table in a section called DATTBL. The linker script maps the DATTBL
section to the CODE region that begins at 0x8000.
The main function in the C file is placed in the default CODE section because
there is no section directive explicitly assigned.
DS33014G-page 131
MPLINK
7.2
Code Regions
0-28 vectors
29-1FFF code, on-chip
2000-3FFF code, external
8000-9FFF protected
0x0000
Vectors
0x0028
0x0029
0x1FFF
0x2000
0x3FFF
0x4000
0x7FFF
0x8000
0x87FE
Interrupt Handlers
0x87FF
0x9FFF
Data Tables
0xA000
0xFFFF
Figure 7.1: Program Memory Map Sample Application 1
7.3
DS33014G-page 132
Sample Application 1
4. Edit the APP1 MPLAB Project, since one of the files includes the
P17C44.H header file:
Include path = c:\mcc\h
Note:
7.4
Source Code
EEPROM1.C contains a 0x1000 data array placed in romdata section
DATTBL, and a main function in the default code section.
EEPROM.LKR contains the PIC17C44 description with a protected CODE
region from 0x8000 to 0x9FFF. The sections INTHAND and DATTBL are
mapped into the protected CODE region.
7.4.1
eeprom.asm
; EEPROM.ASM
LIST p=17c44
#include "p17c44.inc"
INTHAND CODE
; place interrupt handling code in here
END
DS33014G-page 133
MPLINK
eeprom1.c
/* EEPROM1.C
*/
#include "p17c44.h"
#define DATA_SIZE 0x1000
#pragma romdata DATTBL // put following romdata into section DATTBL
unsigned rom data[DATA_SIZE];
#pragma romdata
// set back to default romdata section
/* Main application code for default CODE section */
void main( void )
{
while( 1 )
{
} /* end while */
} /* end main */
DS33014G-page 134
Sample Application 1
7.4.3
// File: EEPROM.LKR
LIBPATH
eeprom.lkr
PIC17C44
CODEPAGE
CODEPAGE
CODEPAGE
NAME=vectors
NAME=page
NAME=eeprom
START=0x0
START=0x28
START=0x8000
END=0x27
END=0x1FFF
END=0x9FFF
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
NAME=gprshare
NAME=gprshare
NAME=gprshare
NAME=gprshare
START=0x1A
START=0x11A
START=0x21A
START=0x31A
END=0x1F
END=0x11F
END=0x21F
END=0x31F
DATABANK
DATABANK
NAME=gpr0
NAME=gpr1
START=0x20
START=0x120
END=0xFF
END=0x1FF
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
NAME=sfrnobnk
NAME=sfrnobnk
NAME=sfrnobnk
NAME=sfrnobnk
START=0x0
START=0x100
START=0x200
START=0x300
END=0xF
END=0x10F
END=0x20F
END=0x30F
PROTECTED
PROTECTED
PROTECTED
PROTECTED
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
NAME=sfrprod
NAME=sfrprod
NAME=sfrprod
NAME=sfrprod
START=0x18
START=0x118
START=0x218
START=0x318
END=0x19
END=0x119
END=0x219
END=0x319
PROTECTED
PROTECTED
PROTECTED
PROTECTED
DATABANK
DATABANK
DATABANK
DATABANK
NAME=sfr0
NAME=sfr1
NAME=sfr2
NAME=sfr3
START=0x10
START=0x110
START=0x210
START=0x310
END=0x17
END=0x117
END=0x217
END=0x317
PROTECTED
PROTECTED
PROTECTED
PROTECTED
SECTION
SECTION
SECTION
SECTION
NAME=STARTUP
NAME=PROG
NAME=INTHAND
NAME=DATTBL
//
//
//
//
PROTECTED
MPLINK
ROM=vectors
ROM=page
ROM=eeprom
ROM=eeprom
PROTECTED
DS33014G-page 135
DS33014G-page 136
Highlights
Topics covered in this chapter:
Overview
Many applications require field-updateable firmware. The PIC17CXXX family
of processors supports this in a straightforward manner in extended
microcontroller mode. This example uses a PIC17C44.
A simple boot loader is located in on-chip program memory, possibly with one
or more support functions that may be called by the firmware. The primary
firmware is located in off-chip program memory. The program memory data
tables are located in the appropriate memory region as an assigned section.
0x0000
0x0028
0x0029
0x07FF
0x0800
0x1FFF
0x2000
0x3FFF
0x4000
0x7FFF
Vectors
Boot Loader
Main Application Code
(on-chip)
0x8000
0xFFFF
Figure 8.1: Program Memory Map Sample Application 2
DS33014G-page 137
MPLINK
8.2
DS33014G-page 138
Sample Application 2
Note:
8.4
boot.c The boot loader code copies the firmware into external program
memory and jumps to a pre-defined address which is the entry point of the
firmware. A firmware-callable support function is supplied at a fixed address
as well.
DS33014G-page 139
MPLINK
loader.lkr The boot loader linker script defines only those regions of
program memory which are on-chip.
boot.c
#include <p17c44.h>
/* The firware entry point is defined to be at 0x4000 */
#define FW_ENTRY
0x4000
#define LGOTO(x) {_asm movlw high (x) movwf PCLATH movlw (x) movwf PCL _endasm}
void load_firmware( void );
void load_firmware( void )
{
/* Do whatever needs to be done to load in the firmware
* into external memory.
*/
}
void main( void )
{
load_firmware();
LGOTO( FW_ENTRY );
}
/* Well provide a function for the firmware to call to output a character
* to an LCD display.
*
* We need the function at a hard address so we can define the entry
* point in the firmware.
*/
#pragma code out_lcd=0x1000
void out_lcd( unsigned char );
void out_lcd( unsigned char ch )
{
/* Do whatever needs doing */
}
#pragma romdata CONFIG
// The following config bit definitions are from the P17C44.INC header file:
#define _PMC_MODE 0x7FAF
#define _XMC_MODE 0xFFBF
#define _MC_MODE 0xFFEF
#define _MP_MODE 0xFFFF
#define
#define
#define
#define
#define
_WDT_NORM 0xFFF3
_WDT_OFF 0xFFF3
_WDT_64 0xFFF7
_WDT_256 0xFFF
_WDT_1 0xFFFF
#define
#define
#define
#define
_LF_OSC
_RC_OSC
_XT_OSC
_EC_OSC
0xFFFC
0xFFFD
0xFFFE
0xFFFF
rom const unsigned int my_config = _MC_MODE & _WDT_OFF & _XT_OSC ;
DS33014G-page 140
Sample Application 2
8.4.2
loader.lkr
LIBPATH .
// Add a directory to the library search path
LIBPATH c:\work\mcc\cc\install\lib
FILES
p17c44.o
NAME=reset_vector
NAME=page0
NAME=page1
NAME=config
START=0x0000
START=0x0028
START=0x2000
START=0xFE00
END=0x0027
END=0x1FFF
END=0x3FFF
END=0xFE0F
// Reset Vector
// On chip memory
// On chip memory
PROTECTED
SHAREBANK
DATABANK
DATABANK
DATABANK
DATABANK
DATABANK
DATABANK
DATABANK
DATABANK
SHAREBANK
DATABANK
DATABANK
NAME=sharedsfr
NAME=sfr0
NAME=sfr1
NAME=sfr2
NAME=sfr3
NAME=sfr4
NAME=sfr5
NAME=sfr6
NAME=sfr7
NAME=registers
NAME=gpr0
NAME=gpr1
START=0x00
START=0x10
START=0x110
START=0x210
START=0x310
START=0x410
START=0x510
START=0x610
START=0x710
START=0x18
START=0x20
START=0x120
END=0x0f
END=0x17
END=0x117
END=0x217
END=0x317
END=0x417
END=0x517
END=0x617
END=0x717
END=0x1f
END=0xEF
END=0x1FB
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
// General purpose RAM bank 0
// General purpose RAM bank 1
DATABANK
NAME=stack
START=0xF0
END=0xFF
SECTION
NAME=CONFIG
DS33014G-page 141
MPLINK
CODEPAGE
CODEPAGE
CODEPAGE
CODEPAGE
8.5.1
firmware.c
#include <p17c44.h>
#include "fwentry.h"
void fw_entry_func( void );
void signon( void );
#pragma code fw_entry = 0x4000
void fw_entry_func( void )
{
/* signon message */
signon();
/* do whatever needs doing... */
while(1);
}
#pragma code // we dont care where the rest of stuff goes
void signon( void )
{
static const rom char msg[] = "FW v1.00";
rom char *p;
for( p=msg ; *p != 0 ; p++ )
out_lcd( *p );
}
8.5.2
fwtables.c
#include <p17c44.h>
#pragma romdata fw_tables
rom unsigned datatable[] = {
0x0000,
0x0001,
0x0002,
0x0003,
0x0004,
0x0005,
0x0006,
0x0007,
0x0008,
};
DS33014G-page 142
Sample Application 2
8.5.3
fwentry.h
#ifndef FWENTRY_H
#define FWENTRY_H
void out_lcd( unsigned char ch );
#endif
8.5.4
fwentry.asm
MPLINK
GLOBAL out_lcd
OUTLCDENTRY CODE 0x1000
out_lcd
END
8.5.5
firmware.lkr
LIBPATH .
// Add a directory to the library search path
LIBPATH c:\work\mcc\cc\install\lib
FILES
p17c44.o
//CODEPAGE
NAME=reset_vector
START=0x0000
END=0x0027
// Reset Vector
// For off-chip firmware, we dont want anything located in the
// on-chip address space.
//
// We make some of the on-chip stuff PROTECTED because we put
// the entry points to the bootloader which the firmware calls
// in there. No code will actuall go there, but we need to
// locate empty sections there to get the relocations.
CODEPAGE
NAME=entrypoints START=0x1000
END=0x3fff
PROTECTED
CODEPAGE
CODEPAGE
NAME=firmware
NAME=tables
START=0x4000
START=0x6000
END=0x5FFF
END=0x7FFF
PROTECTED
SHAREBANK
DATABANK
DATABANK
DATABANK
DATABANK
DATABANK
DATABANK
DATABANK
DATABANK
SHAREBANK
DATABANK
DATABANK
NAME=sharedsfr
NAME=sfr0
NAME=sfr1
NAME=sfr2
NAME=sfr3
NAME=sfr4
NAME=sfr5
NAME=sfr6
NAME=sfr7
NAME=registers
NAME=gpr0
NAME=gpr1
START=0x00
START=0x10
START=0x110
START=0x210
START=0x310
START=0x410
START=0x510
START=0x610
START=0x710
START=0x18
START=0x20
START=0x120
END=0x0f
END=0x17
END=0x117
END=0x217
END=0x317
END=0x417
END=0x517
END=0x617
END=0x717
END=0x1f
END=0xEF
END=0x1FF
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
// General purpose RAM bank 0
// General purpose RAM bank 1
DATABANK
NAME=stack
START=0xF0
END=0xFF
DS33014G-page 143
DS33014G-page 144
Highlights
Topics covered in this chapter:
9.2
Overview
The code declares multiple variables at each of the two locations 0x8000 and
0x9000. When one of these variables is read or written, the device at the
location of the variable is read from or written to. The directive #pragma
romdata creates an absolute section at the specified memory location.
The linker script file declares code pages for each device and for the program
memory. The code page for each device is set to PROTECTED to prevent the
linker from placing unassigned relocatable sections into this memory block.
The linker script file also has sections declared for the code0 and code1 code
pages. The section names are used with the directive #pragma code so the
linker will place the code following the #pragma in that section's memory
location.
DS33014G-page 145
MPLINK
The example has two external devices; a DAC at 0x8000 and an IRD at
0x9000.
0x0000
0x0028
0x0029
0x1FFF
0x2000
0x3FFF
0x8000
0x800F
0x9000
0x9001
Vectors
Code Page 0
Code Page 1
Code Regions
0-28 vectors
29-1FFF code page 0
2000-3FFF code page 1
8000 - 800F device 1 (protected)
9000 - 9001 device 2 (protected)
Code Page 0 & 1: C
Device 1 - DAC
Device 2 - IRD
0xFFFF
Figure 9.1: Program Memory Map Sample Application 3
DS33014G-page 146
Sample Application 3
9.3
Note:
Note:
DS33014G-page 147
MPLINK
Source Code
9.4.1
memmapio.c
#include <P17C756.H>
void main(void);
#pragma romdata dev1 = 0x8000
unsigned rom loc0;
unsigned rom loc1;
unsigned rom loc2;
unsigned rom loc3;
unsigned rom loc4;
unsigned rom loc5;
unsigned rom loc6;
unsigned rom loc7;
unsigned rom loc8;
unsigned rom loc9;
unsigned rom loca;
unsigned rom locb;
unsigned rom locc;
unsigned rom locd;
unsigned rom loce;
unsigned rom locf;
#pragma romdata dev2 = 0x9000
const volatile unsigned rom inp;
unsigned rom outp;
#pragma code code0
void main(void)
{
unsigned int input;
loc0 = 0;
loc1 = 1;
input = inp;
outp = 0x7;
}
DS33014G-page 148
Sample Application 3
9.4.2
memmapio.lkr
// File: memmapio.lkr
// Sample linker command file for 17C756, 17C756A, 17C766
// 12/16/97
LIBPATH
.
NAME=vectors
NAME=code0
NAME=code1
NAME=device1
NAME=device2
NAME=config
START=0x0
START=0x28
START=0x2000
START=0x8000
START=0x9000
START=0xFE00
END=0x27
END=0x1fff
END=0x3FFF
END=0x800F
END=0x9001
END=0xFE0F
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
NAME=sfrnobnk
NAME=sfrnobnk
NAME=sfrnobnk
NAME=sfrnobnk
NAME=sfrnobnk
NAME=sfrnobnk
NAME=sfrnobnk
NAME=sfrnobnk
START=0x0
START=0x100
START=0x200
START=0x300
START=0x400
START=0x500
START=0x600
START=0x700
END=0xF
END=0x10F
END=0x20F
END=0x30F
END=0x40F
END=0x50F
END=0x60F
END=0x70F
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
DATABANK
DATABANK
DATABANK
DATABANK
DATABANK
DATABANK
DATABANK
DATABANK
NAME=sfr0
NAME=sfr1
NAME=sfr2
NAME=sfr3
NAME=sfr4
NAME=sfr5
NAME=sfr6
NAME=sfr7
START=0x10
START=0x110
START=0x210
START=0x310
START=0x410
START=0x510
START=0x610
START=0x710
END=0x17
END=0x117
END=0x217
END=0x317
END=0x417
END=0x517
END=0x617
END=0x717
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
NAME=sfrprod
NAME=sfrprod
NAME=sfrprod
NAME=sfrprod
NAME=sfrprod
NAME=sfrprod
NAME=sfrprod
NAME=sfrprod
START=0x18
START=0x118
START=0x218
START=0x318
START=0x418
START=0x518
START=0x618
START=0x718
END=0x19
END=0x119
END=0x219
END=0x319
END=0x419
END=0x519
END=0x619
END=0x719
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
NAME=registers
NAME=registers
NAME=registers
NAME=registers
NAME=registers
NAME=registers
NAME=registers
NAME=registers
START=0x1A
START=0x11A
START=0x21A
START=0x31A
START=0x41A
START=0x51A
START=0x61A
START=0x71A
END=0x1F
END=0x11F
END=0x21F
END=0x31F
END=0x41F
END=0x51F
END=0x61F
END=0x71F
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
DATABANK
DATABANK
DATABANK
DATABANK
NAME=gpr0
NAME=gpr1
NAME=gpr2
NAME=gpr3
SECTION
SECTION
NAME=code0
NAME=code1
START=0x20
START=0x120
START=0x220
START=0x320
PROTECTED
PROTECTED
PROTECTED
PROTECTED
END=0xFF
END=0x1FF
END=0x2FF
END=0x3FF
ROM=code0
ROM=code1
DS33014G-page 149
MPLINK
CODEPAGE
CODEPAGE
CODEPAGE
CODEPAGE
CODEPAGE
CODEPAGE
DS33014G-page 150
10.2 Overview
main.c
morse.c
morse.h
usart.c
usart.h
portb.c
portb.h
delayms.asm
delayms.h
DS33014G-page 151
MPLINK
0x0000
0x001A
0x001F
0x0020
0x004F
0x0050
0x01FF
0x0220
0x02FF
0x0320
0x03FF
Data 1 Buffer
Data 2 Buffer
Data Regions
1A-1F global pointers (protected)
CurrentBufferWritePos and CurrentBufferReadPos
20 - 4F sw stack (size should increase to 0x30 bytes)
50 - 1FF data 0 - from morse.c
220 - 2FF data 1 from delayms.asm
320 - 3FF data 2 all other
Buffer access code: ASM
Buffer date: ASM
Main code: C
Main data declarations: C
Quick access data: C
DS33014G-page 152
Sample Application 4
10.3 Building the Application
The source files for this sample application may be compiled by the included
batch file or through MPLAB.
The batch file app4.bat compiles this application. This file assumes that
MCC17, MPASM, and MPLINK can be found in your PATH statement. Also,
the MCC_INCLUDE environment variable should be set to point to MCC\H. You
can set these in your AUTOEXEC.BAT file and check them by going to the MSDOS prompt and typing SET. MPLINK sets the library path to C:\MCC\LIB. If
MPLAB-C17/C18 is installed somewhere else, change the path in the
MPLINK line of the batch file.
DS33014G-page 153
MPLINK
morse756.lkr
// File: morse756.lkr
LIBPATH
CODEPAGE
CODEPAGE
CODEPAGE
CODEPAGE
NAME=vectors
NAME=page0
NAME=page1
NAME=config
START=0x0
START=0x28
START=0x2000
START=0xFE00
END=0x27
END=0x1FFF
END=0x3FFF
END=0xFE0F
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
NAME=sfrnobnk
NAME=sfrnobnk
NAME=sfrnobnk
NAME=sfrnobnk
NAME=sfrnobnk
NAME=sfrnobnk
NAME=sfrnobnk
NAME=sfrnobnk
START=0x0
START=0x100
START=0x200
START=0x300
START=0x400
START=0x500
START=0x600
START=0x700
END=0xF
END=0x10F
END=0x20F
END=0x30F
END=0x40F
END=0x50F
END=0x60F
END=0x70F
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
DATABANK
DATABANK
DATABANK
DATABANK
DATABANK
DATABANK
DATABANK
DATABANK
NAME=sfr0
NAME=sfr1
NAME=sfr2
NAME=sfr3
NAME=sfr4
NAME=sfr5
NAME=sfr6
NAME=sfr7
START=0x10
START=0x110
START=0x210
START=0x310
START=0x410
START=0x510
START=0x610
START=0x710
END=0x17
END=0x117
END=0x217
END=0x317
END=0x417
END=0x517
END=0x617
END=0x717
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
NAME=sfrprod
NAME=sfrprod
NAME=sfrprod
NAME=sfrprod
NAME=sfrprod
NAME=sfrprod
NAME=sfrprod
NAME=sfrprod
START=0x18
START=0x118
START=0x218
START=0x318
START=0x418
START=0x518
START=0x618
START=0x718
END=0x19
END=0x119
END=0x219
END=0x319
END=0x419
END=0x519
END=0x619
END=0x719
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
SHAREBANK
NAME=share0
NAME=share0
NAME=share0
NAME=share0
NAME=share0
NAME=share0
NAME=share0
NAME=share0
DATABANK
DATABANK
DATABANK
DATABANK
DATABANK
NAME=stackram
NAME=gpr0
NAME=gpr1
NAME=gpr2
NAME=gpr3
START=0x1A
START=0x11A
START=0x21A
START=0x31A
START=0x41A
START=0x51A
START=0x61A
START=0x71A
END=0x1F
END=0x11F
END=0x21F
END=0x31F
END=0x41F
END=0x51F
END=0x61F
END=0x71F
START=0x20
START=0x50
START=0x120
START=0x220
START=0x320
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
PROTECTED
END=0x4F
END=0xFF
END=0x1FF
END=0x2FF
END=0x3FF
PROTECTED
PROTECTED
PROTECTED
PROTECTED
RAM=share0
RAM=gpr0
RAM=gpr1
RAM=gpr2
DS33014G-page 154
Sample Application 4
10.4.2
#include
#include
#include
#include
main.c
"usart.h"
"morse.h"
"delayms.h"
<p17c756.h>
MPLINK
while( DisplayNextMorseVal() )
{
DelayXMS( 100 );
}
TerminateUSARTInput();
}
10.4.3
morse.h
#ifndef _MORSE_H_
#define _MORSE_H_
#define MORSE_BUFFER_SIZE
#define DOT
#define DASH
#define TERMINATE
#define DOT_LENGTH
#define DASH_LENGTH
220
1
2
3
100
250
DS33014G-page 155
morse.c
#include "portb.h"
#include "morse.h"
#include "delayms.h"
#pragma udata shared global_vars
unsigned char *CurrentBufferWritePos;
unsigned char *CurrentBufferReadPos;
#pragma udata morse_buf
unsigned char USARTBuffer[MORSE_BUFFER_SIZE];
#pragma udata morse_dat
void InitializeMorseTable( void )
{
CurrentBufferWritePos = USARTBuffer;
CurrentBufferReadPos = USARTBuffer;
PortBInitialize();
}
DS33014G-page 156
Sample Application 4
10.4.5
portb.h
#ifndef _PORTB_H_
#define _PORTB_H_
void PortBInitialize( void );
void PortBOutput( unsigned char OutputValue );
#endif
2
10.4.6
portb.c
MPLINK
#include "portb.h"
#include <p17C756.h>
void PortBInitialize( void )
{
PORTB = 0xff;
// Clear Port B register
DDRB = 0x00;
// Set Port B as output
}
10.4.7
usart.h
#ifndef _USART_H_
#define _USART_H_
void InitializeUSART( void );
void TerminateUSARTInput( void );
void GetMorseFromUSART( void );
#endif
DS33014G-page 157
usart.c
"usart.h"
"morse.h"
<usart16.h>
<p17C756.h>
10.4.9
delayms.h
#ifndef _DELAYMS_H_
#define _DELAYMS_H_
void DelayXMS( unsigned int time );
#endif
DS33014G-page 158
Sample Application 4
10.4.10
delayms.asm
list p=17c756
#include <p17c756.inc>
EXTERN _stack
GLOBAL DelayXMS
delay_dat
MSB
LSB
UDATA
RES
RES
1
1
CODE
DelayXMS:
_stack
_stack,FSR0
FSR0,f
INDF0,MSB
FSR0,f
INDF0,LSB
MPLINK
banksel
movfp
decf
movfp
decf
movfp
dly1:
nop
nop
decfsz
goto
decfsz
goto
return
LSB,1
dly1
MSB,1
dly1
end
DS33014G-page 159
DS33014G-page 160
MPLIB
DS33014G-page 161
DS33014G-page 162
Introduction
Topics covered in this chapter.
1.2
Highlights
Topics covered in this chapter:
What MPLIB Is
What MPLIB Does
How MPLIB Helps You
1.3
What MPLIB Is
MPLIB is a librarian for use with COFF object modules (filename.o)
created using either MPASM v2.0, MPASMWIN v2.0, or MPLAB-C v2.0 or
later.
1.4
Libraries help keep code small. Since a linker only uses the required
object files contained in a library, not all object files which are contained
in the library necessarily wind up in the linker's output module.
Libraries make projects more maintainable. If a library is included in a
project, the addition or removal of calls to that library will not require a
change to the link process.
Libraries help to convey the purpose of a group of object modules.
Since libraries can group together several related object modules, the
purpose of a library file is usually more understandable than the purpose of its individual object modules. For example, the purpose of a file
named 'math.lib' is more apparent than the purpose of power.o,
ceiling.o, and floor.o.
DS33014G-page 163
MPLIB
Libraries make linking easier. Since library files can contain many object
files, the name of a library file can be used instead of the names of
many separate object files when linking.
DS33014G-page 164
Introduction
This chapter discussed how to install MPLIB and an overview of the librarian
(MPLIB).
2.2
Highlights
Topics covered in this chapter:
Installation
Overview of Librarian
2.3
Installation
There are two versions of MPLIB. MPLIBD.EXE is a DOS extender version
and is only recommended for DOS or Windows 3.x systems. MPLIB.EXE is a
Windows 32-bit console application and is for Windows 95/98/NT.
MPLIBD.EXE and MPLIB.EXE are command-line applications. MPLIBD.EXE
may be used with DOS or a DOS window in Windows 3.x. MPLIB.EXE may
be used with a DOS window in Windows 95/98/NT.
If you are not going to use MPLAB, you can obtain the librarian separately
either from the Microchip Technical Library CD or from our web site. MPLINK
is bundled with MPLIB into a zip file. To install:
Create a directory in which to place the files
Unzip the MPLINK and MPLIB files using either WinZip or PKZIP
DS33014G-page 165
MPLIB
If you are going to use MPLAB, you do not need to install the librarian
separately. When MPLAB is installed, MPLIB is also installed. To find out how
to install MPLAB, please refer to the MPLAB Users Guide (DS51025). You
may obtain the MPLAB software and users guide either from the Microchip
Technical Library CD or from our web site.
Overview of Librarian
Figure 2.1 is a diagram of how MPLIB works with other Microchip tools.
mult.c
MPLAB-C17/C18
mult.o
avg.asm
add.asm
MPASM
MPASM
avg.o
add.o
source
files
object
files
MPLIB
math.lib
library
DS33014G-page 166
Introduction
This chapter discussed how to use the librarian (MPLIB).
3.2
Highlights
Topics covered in this chapter:
Usage Format
Usage Examples
Tips
3.3
Usage Format
MPLIB is invoked with the following syntax:
mplib [/q] /{ctdrx} LIBRARY [MEMBER...]
3
options:
/c create library;
/d
/r
/x
/q
DS33014G-page 167
MPLIB
/t
Usage Examples
Suppose a library named dsp.lib is to be created from three object
modules named fft.o, fir.o, and iir.o. The following command line
would produce the desired results:
mplib /c dsp.lib fft.o fir.o iir.o
To display the names of the object modules contained in a library file names
dsp.lib, the following command line would be appropriate:
mplib /t dsp.lib
3.5
Tips
MPLIB creates library files that may contain only a single external definition
for any symbol. Therefore, if two object modules define the same external
symbol, MPLIB 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 librarys member object modules should be as small as possible.
Creating object modules that contain only a single function can significantly
reduce code space.
DS33014G-page 168
APPENDICES
DS33014G-page 169
DS33014G-page 170
Introduction
MPASM is capable of generating several different hex file formats.
A.2
Highlights
Topics covered in this appendix:
Intel Hex Format (INHX8M) (for standard programmers)
Intel Split Hex Format (INHX8S) (for ODD/EVEN ROM programmers)
Intel Hex 32 Format (INHX32) (for 16-bit core programmers)
A.3
APPENDICES
DS33014G-page 171
A.4
DS33014G-page 172
APPENDICES
DS33014G-page 173
DS33014G-page 174
Introduction
This appendix lists abbreviated information on MPASM and PICmicro
instruction sets for use in developing applications using MPASM, MPLINK and
MPLIB.
B.2
Highlights
Topics covered in this appendix:
MPASM Quick Reference
Key to PICmicro Instruction Sets
12-Bit Core Instruction Set
14-Bit Core Instruction Set
16-Bit Core Instruction Set
Key to Enhanced 16-Bit Core Instruction Set
Enhanced 16-Bit Core Instruction Set
Hexadecimal to Decimal Conversion
ASCII Character Set
B.3
Table B.1:
Directive
Description
Syntax
CONTROL DIRECTIVES
Declare Symbol Constant
#DEFINE
#define <name>
[[(<arg>,...,<arg>)]<value>]
END
end
EQU
<label>
ERROR
error "<text_string>"
ERRORLEVEL
errorlevel 0|1|2|<+-><msg>
#INCLUDE
include <<include_file>>
include "<include_file>"
APPENDICES
CONSTANT
equ <expr>
DS33014G-page 175
Directive
Description
Syntax
LIST
Listing Options
list [<option>[,...,<option>]]
MESSG
messg "<message_text>"
NOLIST
nolist
ORG
<label>
PAGE
page
PROCESSOR
processor <processsor_type>
RADIX
radix
SET
<label>
SPACE
space
SUBTITLE
subtitl
TITLE
title
#UNDEFINE
#undefine <label>
VARIABLE
org
<expr>
<default_radix>
set
<expr>
[<expr>]
"<sub_text>"
"<title_text>"
CONDITIONAL ASSEMBLY
ELSE
else
ENDIF
endif
ENDW
endw
IF
if
IFDEF
ifdef
IFNDEF
ifndef <label>
WHILE
while <expr>
_ _BADRAM
_ _badram <expr>
CBLOCK
cblock
_ _CONFIG
_ _config <expr> OR
_ _config <addr>, <expr>
DA
DATA
data <expr>,[,<expr>,...,<expr>]
data
"<text_string>"[,"<text_string>",...]
DB
db <expr>[,<expr>,...,<expr>]
DE
de <expr>[,<expr>,...,<expr>]
DT
Define Table
dt <expr>[,<expr>,...,<expr>]
DW
dw
ENDC
endc
FILL
fill
_ _ IDLOCS
Set ID locations
_ _idlocs <expr>
<expr>
<label>
DATA
DS33014G-page 176
[<expr>]
<expr> [,<expr>,...,<expr>]
<expr>, <count>
Quick Reference
Table B.1:
Directive
Description
Syntax
_ _MAXRAM
_ _maxram <expr>
RES
Reserve Memory
res
ENDM
endm
EXITM
exitm
EXPAND
expand
LOCAL
local
MACRO
NOEXPAND
noexpand
<mem_units>
MACROS
<label> [,<label>]
bankisel <label>
BANKSEL
banksel <label>
CODE
EXTERN
GLOBAL
IDATA
PAGESEL
pagesel <label>
UDATA
UDATA_ACS
UDATA_OVR
UDATA_SHR
Table B.2:
Option
Default
Description
N/A
INHX8M
On
N/A
On
N/A
APPENDICES
d
e
DS33014G-page 177
Option
Default
On
On
Off
None
Off
Hex
Off
Table B.3:
Description
Radix
Syntax
Example
Decimal
D<digits>
D100
Hexadecimal (default)
H<hex_digits>
0x<hex_digits>
H9f
0x9f
Octal
O<octal_digits>
O777
Binary
B<binary_digits>
B00111001
Character (ASCII)
<character>
A<Character>
C
AC
DS33014G-page 178
Quick Reference
Table B.4:
Operator
Description
Example
goto $ + 3
Left Parenthesis
1 + ( d * 4 )
Right Parenthesis
( Length + 1 ) * 256
if ! ( a - b )
-1 * Length
Complement
flags = ~flags
high
low
Multiply
a = b * c
Divide
a = b / c
Modulus
entry_len = tot_len % 16
Add
tot_len = entry_len * 8 + 1
Subtract
entry_len = ( tot - 1 ) / 8
<<
Left shift
>>
Right shift
>=
Greater or equal
>
Greater than
upper
<
Less than
<=
Less or equal
==
Equal to
if entry_idx == num_entries
!=
Not equal to
if entry_idx != num_entries
&
Bitwise AND
Bitwise exclusive OR
Bitwise inclusive OR
Logical AND
&&
Logical OR
if (len == 512) || (b == c)
Set equal to
entry_index = 0
+=
entry_index += 1
-=
entry_index -= 1
*=
entry_index *= entry_length
/=
entry_total /= entry_length
%=
entry_index %= 8
<<=
flags <<= 3
>>=
flags >>= 3
&=
|=
flags |= ERROR_FLAG
DS33014G-page 179
APPENDICES
||
=
Operator
Description
Example
^=
flags ^= ERROR_FLAG
++
Increment
i ++
--
Decrement
i --
B.4
Field
Description
Destination select;
PH:PL
DS33014G-page 180
Quick Reference
B.5
Mnemonic
Description
Function
Ekk
ANDLW
k .AND. W W
9kk
CALL
k Call subroutine
PC + 1 TOS, k PC
004
CLRWDT
Akk
GOTO
k PC(9 bits)
Dkk
IORLW
k .OR. W W
Ckk
MOVLW
k Move Literal to W
k W
002
OPTION
8kk
RETLW
003
SLEEP
00f
TRIS
f Tristate port f
Fkk
XORLW
k .XOR. W W
W OPTION Register
k W, TOS PC
0 WDT, stop oscillator
Mnemonic
Description
Function
1Cf
ADDWF
W + f d
14f
ANDWF
W .AND. f
06f
CLRF
040
CLRW
Clear W
24f
COMF
f,d Complement f
.NOT. f d
f Clear f
0f
0 W
0Cf
DECF
f,d Decrement f
f - 1 d
2Cf
DECFSZ
f - 1 d, skip if zero
28f
INCF
f,d Increment f
f + 1 d
3Cf
INCFSZ
f + 1 d,skip if zero
IORWF
W .OR. f d
MOVF
f,d Move f
f d
02f
MOVWF
000
NOP
34f
RLF
f Move W to f
W f
No operation
f,d Rotate left f
register f
C
7......0
DS33014G-page 181
APPENDICES
10f
20f
Mnemonic
RRF
Description
Function
register f
C
7......0
08f
SUBWF
f - W d
38f
SWAPF
f(0:3) f(4:7) d
18f
XORWF
W .XOR. f d
Mnemonic
Description
Function
4bf
BCF
0 f(b)
5bf
BSF
1 f(b)
6bf
BTFSC
skip if f(b) = 0
7bf
BTFSS
skip if f(b) = 1
DS33014G-page 182
Quick Reference
B.6
Mnemonic
Description
Function
3Ekk
ADDLW
k Add literal to W
k + W W
39kk
ANDLW
k .AND. W W
2kkk
CALL
k Call subroutine
PC + 1
0064
CLRWDT
2kkk
GOTO
k PC(9 bits)
38kk
IORLW
k .OR. W W
30kk
MOVLW
k Move Literal to W
k W
TOS, k PC
0062
OPTION
W OPTION Register
0009
RETFIE
TOS
34kk
RETLW
0008
RETURN
PC, 1 GIE
k W, TOS PC
TOS PC
0 WDT, stop oscillator
0063
SLEEP
3Ckk
SUBLW
k - W W
006f
TRIS
f Tristate port f
3Akk
XORLW
k .XOR. W W
Mnemonic
Description
ADDWF
Function
W + f
W .AND. f
05ff
ANDWF
018f
CLRF
0100
CLRW
Clear W
09ff
COMF
f,d Complement f
.NOT. f d
03ff
DECF
f,d Decrement f
f - 1 d
0Bff
DECFSZ
f - 1 d, skip if 0
0Aff
INCF
f,d Increment f
f + 1 d
0Fff
INCFSZ
f + 1 d, skip if 0
04ff
IORWF
W .OR. f d
08ff
MOVF
f,d Move f
f d
0 f
0 W
DS33014G-page 183
APPENDICES
f Clear f
Mnemonic
008f
MOVWF
0000
NOP
0Dff
RLF
Description
f Move W to f
Function
W f
No operation
f,d Rotate left f
register f
C
0Cff
7......0
RRF
register f
C
7......0
02ff
SUBWF
f - W d
0Eff
SWAPF
f(0:3) f(4:7) d
06ff
XORWF
W .XOR. f d
Mnemonic
Description
Function
0 f(b)
BSF
1 f(b)
BTFSC
skip if f(b) = 0
BTFSS
skip if f(b) = 1
1bff
BCF
1bff
1bff
1bff
Description
Equivalent
Operation(s)
Status
ADDCF
f,d
BTFSC
INCF
3,0
f,d
ADDDCF
f,d
BTFSC
INCF
3,1
f,d
Branch
GOTO
BC
Branch on Carry
BTFSC
GOTO
3,0
k
BDC
BTFSC
GOTO
3,1
k
BNC
Branch on No Carry
BTFSS
GOTO
3,0
k
BNDC
BTFSS
GOTO
3,1
k
BNZ
Branch on No Zero
BTFSS
GOTO
3,2
k
BZ
Branch on Zero
BTFSC
GOTO
3,2
k
DS33014G-page 184
Quick Reference
Table B.11: 12-Bit/14-Bit Core Special Instruction Mnemonics (Continued)
Mnemonic
Equivalent
Operation(s)
Description
Status
CLRC
Clear Carry
BCF
3,0
CLRDC
BCF
3,1
CLRZ
Clear Zero
BCF
3,2
Move File to W
MOVF
f,0
Negate File
COMF
INCF
f,1
f,d
SETC
Set Carry
BSF
3,0
SETDC
BSF
3,1
SETZ
Set Zero
BSF
3,2
SKPC
Skip on Carry
BTFSS
3,0
SKPDC
BTFSS
3,1
SKPNC
Skip on No Carry
BTFSC
3,0
SKPNDC
BTFSC
3,1
SKPNZ
BTFSC
3,2
LCALL
LGOTO
MOVFW
NEGF
f,d
Skip on Zero
BTFSS
3,2
SUBCF
f,d
BTFSC
DECF
3,0
f,d
SUBDCF
f,d
BTFSC
DECF
3,1
f,d
Test File
MOVF
f,1
SKPZ
TSTF
APPENDICES
DS33014G-page 185
Mnemonic
Description
Function
f p
f,p Move f to p
6pff
MOVFP
b8kk
MOVLB
k BSR (3:0)
bakx
MOVLP
k BSR (7:4)
4pff
MOVPF
01ff
MOVWF
a8ff
TBLATH f if t=1,
TBLATL f if t=0;
ProgMem(TBLPTR) TBLAT;
TBLPTR + 1 TBLPTR if i=1
acff
f TBLATH if t = 1,
f TBLATL if t = 0;
TBLAT ProgMem(TBLPTR);
TBLPTR + 1 TBLPTR if i=1
a0ff
TLRD
TBLATH f if t = 1
TBLATL f if t = 0
a4ff
TLWT
f TBLATH if t = 1
f TBLATL if t = 0
p W
p,f Move p to f
f Move W to F
W f
Mnemonic
Description
k Add literal to W
Function
(W + k) W
b1kk
ADDLW
0eff
ADDWF
f,d Add W to F
(W + f) d
10ff
ADDWFC
(W + f + C) d
b5kk
ANDLW
(W .AND. k) W
0aff
ANDWF
(W .AND. f) d
28ff
CLRF
0x00 f,0x00 d
12ff
COMF
f,d Complement f
.NOT. f
2eff
DAW
W adjusted f and d
06ff
DECF
f,d Decrement f
(f - 1) f and d
14ff
INCF
f,d Increment f
(f + 1) f and d
b3kk
IORLW
DS33014G-page 186
(W .OR. k) W
Quick Reference
Table B.13: 16-Bit Core Arithmetic and Logical Instruction (Continued)
Hex
Mnemonic
Description
Function
(W .OR. f) d
08ff
IORWF
b0kk
MOVLW
k Move literal to W
k W
bckk
MULLW
(k x W) PH:PL
34ff
MULWF
f Multiply W and f
(W x f) PH:PL
2cff
NEGW
1aff
RLCF
(W + 1)
f,(W + 1) d
register f
22ff
RLNCF
7......0
register f
7......0
18ff
RRCF
register f
C
20ff
RRNCF
7......0
register f
7......0
0xff f,0xff d
2aff
SETF
b2kk
SUBLW
04ff
SUBWF
(f - W) d
02ff
SUBWFB
(f - W - c) d
1cff
SWAPF
f,d Swap f
f(0:3) d(4:7),
f(4:7) d(0:3)
b4kk
XORLW
0cff
XORWF
(k - W)
(W .XOR. k) W
(W .XOR. f)
Mnemonic
Description
Function
8bff
BCF
f,b
Bit clear f
0 f(b)
8bff
BSF
f,b
Bit set f
1 f(b)
BTFSC
f,b
skip if f(b) = 0
BTFSS
f,b
skip if f(b) = 1
3bff
BTG
f,b
Bit toggle f
DS33014G-page 187
APPENDICES
9bff
9bff
Mnemonic
Description
Function
ekkk
CALL
31ff
CPFSEQ
f-W, skip if f = W
32ff
CPFSGT
30ff
CPFSLT
16ff
DECFSZ
(f-1) d, skip if 0
26ff
DCFSNZ
(f-1)
ckkk
GOTO
d, skip if not 0
k PC(12:0)
k(12:8) PCLATH(4:0),
PC(15:13) PCLATH(7:5)
1eff
INCFSZ
(f+1) d, skip if 0
24ff
INFSNZ
b7kk
LCALL
0005
RETFIE
b6kk
RETLW
0002
RETURN
33ff
TSTFSZ
(PC+1) TOS; k
(PCLATH) PCH
k W, TOS PC,
(PCLATH unchanged)
TOS PC
(PCLATH unchanged)
PCL,
skip if f = 0
Mnemonic
Description
Function
0004
CLRWT
0003
SLEEP
DS33014G-page 188
WDT,
Quick Reference
B.8
Field
Description
File Addresses
f
fs
fd
dest
Literals
kk
kb
kc
kd
Offsets, Addresses
nn
nd
ml
mm
xx
Bits
b
APPENDICES
DS33014G-page 189
Mnemonic
Description
Function
0Fkk
ADDLW
kk
W+kk W
0Bkk
ANDLW
kk
W .AND. kk W
0004
CLRWDT
0007
DAW
09kk
IORLW
kk
W .OR. kk W
EFkc
F0kd
LFSR
kd:kc FSRr
01kb
MOVLB
kb
kb BSR
0Ekk
MOVLW
kk
kk W
0Dkk
MULLW
kk
W * kk PRODH:PRODL
08kk
SUBLW
kk
kkW W
0Akk
XORLW
kk
W .XOR. kk W
Mnemonic
Description
Function
0008
TBLRD *
0009
TBLRD *+
000A
TBLRD *-
000B
TBLRD +*
TBLPTR +1 TBLPTR
Prog Mem (TBLPTR) TABLAT
000C
TBLWT *
000D
TBLWT *+
DS33014G-page 190
Quick Reference
Table B.18: Enhanced 16-Bit Core Memory Operations (Continued)
Hex
Mnemonic
Description
Function
000E
TBLWT *-
000F
TBLWT +*
TBLPTR +1 TBLPTR
TABLAT Prog Mem(TBLPTR)
Mnemonic
Description
Function
E2nn
BC
nn
E6nn
BN
nn
E3nn
BNC
nn
E7nn
BNN
nn
E5nn
BNOV
nn
E1nn
BNZ
nn
BOV
nn
E0nd
BRA
nd
Unconditional relative
branch
PC+2+2*nd PC
E0nn
BZ
nn
ECml
Fmm
CALL
EFml
Fmm
GOTO
mm:ml
Absolute Branch
(second word)
mm:ml PC<20:1>
0000
NOP
No Operation
No operation
0006
POP
TOS-1 TOS
0005
PUSH
PC +2 TOS
D8nd
RCALL
00FF
RESET
0010
RETFIE
0Ckk
RETLW
kk
kk W,
0012
RETURN s
0003
SLEEP
nd
DS33014G-page 191
APPENDICES
E4nn
Mnemonic
Description
Function
9bf
BCF
f,b,a
Bit Clear f
0 f<b>
8bf
BSF
f,b,a
Bit Set f
1 f<b>
Bbf
BTFSC
f,b,a
Abf
BTFSS
f,b,a
7bf
BTG
f,b,a
Bit Toggle f
f<b> f<b>
Mnemonic
Description
Function
W+f dest
24f
ADDWF
f,d,a
ADD WREG to f
20f
ADDWFC
f,d,a
14f
ANDWF
f,d,a
W .AND. f dest
6Af
CLRF
f,a
Clear f
0f
1Cf
COMF
f,d,a
Complement f
f dest
62f
CPFSEQ
f,a
64f
CPFSGT
f,a
60f
CPFSLT
f,a
04f
DECF
f,d,a
Decrement f
f1 dest
2Cf
DECFSZ
f,d,a
Decrement f, skip if 0
4Cf
DCFSNZ
f,d,a
28f
INCF
f,d,a
Increment f
f+1 dest
3Cf
INCFSZ
f,d,a
Increment f, skip if 0
48f
INFSNZ
f,d,a
10f
IORWF
f,d,a
W .OR. f dest
50f
MOVF
f,d,a
Move f
f dest
Cfs
Ffd
MOVFF
fs,fd
Move fs to fd
(second word)
fs fd
6Ef
MOVWF
f,a
Move WREG to f
Wf
02f
MULWF
f,a
W * f PRODH:PRODL
6Cf
NEGF
f,a
Negate f
f +1 f
34f
RLCF
f,d,a
register f
C
DS33014G-page 192
7......0
Quick Reference
Table B.21: Enhanced 16-Bit Core File Register Operations (Continued)
Hex
44f
Mnemonic
RLNCF
f,d,a
Description
Function
register f
7......0
30f
RRCF
f,d,a
register f
C
40f
RRNCF
f,d,a
7......0
register f
7......0
48f
SETF
f,a
Set f
0xFF f
54f
SUBFWB
f,d,a
WfC dest
5Cf
SUBWF
f,d,a
fW dest
58f
SUBWFB
f,d,a
fWC dest
38f
SWAPF
f,d,a
Swap nibbbles of f
66f
TSTFSZ
f,a
Test f, skip if 0
18f
XORWF
f,d,a
W .XOR. f dest
APPENDICES
DS33014G-page 193
Dec
Byte
Hex
Dec
Hex
Dec
Hex
Dec
4096
256
16
8192
512
32
12288
768
48
16384
1024
64
20480
1280
80
24576
1536
96
28672
1792
112
32768
2048
128
36864
2304
144
40960
2560
160
10
45056
2816
176
11
49152
3072
192
12
53248
3328
208
13
57344
3584
224
14
61440
3840
240
15
Using This Table: For each Hex digit, find the associated decimal value. Add
the numbers together. For example, Hex A38F converts to 41871 as follows:
Hex 1000s Digit Hex 100s Digit Hex 10s Digit Hex 1s Digit
40960
DS33014G-page 194
768
128
15
Result
41871
Decimal
Quick Reference
B.11 ASCII Character Set
NUL
DLE
Space
SOH
DC1
STX
DC2
"
ETX
DC3
EOT
DC4
ENQ
NAK
ACK
SYN
&
Bell
ETB
BS
CAN
HT
EM
LF
SUB
VT
ESC
FF
FS
<
CR
GS
SO
RS
>
SI
US
DEL
APPENDICES
DS33014G-page 195
DS33014G-page 196
Introduction
The following messages are produced by MPASM. These messages always
appear in the listing file directly above each line in which the error occurred.
The messages are stored in the error file (.ERR) if no MPASM options are
specified. If the /e- option is used (turns error file off), then the messages will
appear on the screen. If the /q (quiet mode) option is used with the /e-, then
the messages will not display on the screen or in an error file. The messages
will still appear in the listing file.
C.2
Highlights
Topics covered in this appendix:
Errors
Warnings
Messages
C.3
Errors
101 ERROR:
User error, invoked with the ERROR directive.
102 Out of memory.
Not enough memory for macros, #defines or internal processing.
Eliminate any TSRs, close any open applications, and try assembling
the file again. If this error was obtained using the Real Mode DOS
executable, try using either the Windows version (MPASMWIN) or DPMI
version (MPASM_DP)
103 Symbol table full.
No more memory available for the symbol table. Eliminate any TSRs,
close any open applications, and try assembling the file again. If this
error was obtained using the Real Mode DOS executable, try using
either the Windows version (MPASMWIN) or DPMI version
(MPASM_DP)
Could not create a temporary file. Check the available disk space.
105 Cannot open file.
Could not open a file. If it is a source file, the file may not exist. If it is an
output file, the old version may be write protected.
DS33014G-page 197
APPENDICES
107
Illegal digit.
An illegal digit in a number. Valid digits are 0-1 for binary, 0-7 for octal,
0-9 for decimal, and 0-9, a-f, and A-F for hexadecimal.
108
Illegal character.
An illegal character in a label. Valid characters for labels are alphabetic
(a..f, A..F), numeric (0-9), the underscore (_), and the question mark
(?). Labels may not begin with a numeric.
109
Unmatched (
An open parenthesis did not have a matching close parenthesis. For
example, DATA (1+2.
110
Unmatched )
An close parenthesis did not have a matching open parenthesis. For
example, DATA 1+2).
111
Missing symbol.
An EQU or SET statement did not have a symbol to assign the value to.
112
Missing operator.
An arithmetic operator was missing from an expression. For example,
DATA 1 2.
113
114
Divide by zero.
Division by zero encountered during an expression evaluation.
115
Duplicate label.
A label was declared as a constant (e.g., with the EQU or CBLOCK
directive) in more than one location.
116
117
118
DS33014G-page 198
MPASM Errors/Warnings/Messages
119
120
121
Illegal label.
Labels are not allowed on certain directive lines. Simply put the label on
its own line, above the directive. Also, HIGH, LOW, PAGE, and BANK
are not allowed as labels.
122
Illegal opcode.
Token is not a valid opcode.
123
Illegal directive.
Directive is not allowed for the selected processor; for example, the
_ _IDLOCS directive on the PIC17C42.
124
Illegal argument.
An illegal directive argument; for example, LIST STUPID.
125
Illegal condition.
A bad conditional assembly. For example, an unmatched ENDIF.
126
127
128
Missing argument(s).
Not enough arguments for a macro call or an opcode.
129
Expected.
Expected a certain type of argument. The expected list will be provided.
130
132
Unknown processor.
The selected processor is not a valid processor.
DS33014G-page 199
APPENDICES
131
134
135
136
137
138
139
140
141
142
143
Illegal nesting.
Macros, IFs and WHILEs must be completely nested; they cannot
overlap. If you have an IF within a WHILE loop, the ENDIF must come
before the ENDW.
144
Unmatched ENDC.
ENDC found without a CBLOCK.
145
Unmatched ENDM.
ENDM found without a MACRO definition.
146
Unmatched EXITM.
EXITM found without a MACRO definition.
147
DS33014G-page 200
MPASM Errors/Warnings/Messages
148
149
150
151
152
153
154
155
All overlaid sections of the same name must have the same
starting address.
If multiple UDATA_OVR sections with the same name are declared, they
must all have the same starting address.
156
DS33014G-page 201
APPENDICES
UNKNOWN ERROR.
An error has occurred which MPASM cannot understand. It is not any of
the errors described in this appendix. Contact your Microchip Field
Application Engineer (FAE) if you cannot debug this error.
C.4
Warnings
201
202
203
204
205
206
207
208
209
Missing quote.
A text string or character was missing a quote. For example,
DATA a.
210
Extra ),
An extra comma was found at the end of the line.
211
212
Expected
Expected a certain type of argument. A description should be provided.
For the warning, an assumption is made about the argument.
DS33014G-page 202
MPASM Errors/Warnings/Messages
213
214
Unmatched (
An unmatched parenthesis was found. The warning is used if the
parenthesis is not used for indicating order of evaluation.
215
216
217
218
219
220
221
222
223
Redefining processor
The selected processor is being reselected by the LIST or
PROCESSOR directive.
Use of this instruction is not recommended.
Use of the TRIS and OPTION instructions is not recommended for a
PIC16CXX device.
225
DS33014G-page 203
APPENDICES
224
UNKNOWN WARNING
A warning has occurred which MPASM cannot understand. It is not any
of the warnings described in this appendix. Contact your Microchip
Field Application Engineer (FAE) if you cannot debug this warning.
C.5
Messages
301
MESSAGE:
User message, invoked with the MESSG directive.
302
303
304
305
306
307
308
309
310
312
DS33014G-page 204
MPASM Errors/Warnings/Messages
313
314
UNKNOWN MESSAGE
A message has occurred which MPASM cannot understand. It is not
any of the messages described in this appendix. Contact your
Microchip Field Application Engineer (FAE) if you cannot debug this
message.
APPENDICES
DS33014G-page 205
DS33014G-page 206
Introduction
MPLINK produces the following errors and warnings.
D.2
Highlights
Topics covered in this appendix:
Parse Errors
Linker Errors
Linker Warnings
Library File Errors
COFF File Errors
COFF to COD Converter Errors
COFF to COD Converter Warnings
D.3
Parse Errors
Invalid attributes for memory in cmdfile:line. A CODEPAGE, DATABANK,
or SHAREBANK directive does not specify a NAME, START, or END attribute;
or another attribute is specified which is not valid.
Invalid attributes for STACK in cmdfile:line. A STACK directive does not
specify a SIZE attribute, or another attribute is specified which is not valid.
Invalid attributes for SECTION in cmdfile:line. A SECTION directive must
have a NAME and either a RAM or ROM attribute.
Could not open cmdfile. A linker command file could not be opened. Check
that the file exists, is in the current search path, and is readable.
Multiple inclusion of linker command file cmdfile. A linker command file
can only be included once. Remove multiple INCLUDE directives to the
referenced linker command file.
Illegal <libpath> for LIBPATH in cmdfile:line. The libpath must be a
semicolon delimited list of directories. Enclose directory name which have
embedded spaces in double quotes.
DS33014G-page 207
APPENDICES
D.4
Linker Errors
Memory memName overlaps memory memName. All CODEPAGE
blocks must specify unique memory ranges which do not overlap. Similarly
DATABANK and SHAREBANK blocks may not overlap.
Duplicate definition of memory memName. All CODEPAGE and
DATABANK directives must have unique NAME attributes.
Multiple map files declared: File1, File2. The m <mapfile> switch was
specified more than once.
Multiple output files declared: File1, File2. The o <outfile> switch was
specified more than once.
Multiple inclusion of object file File1, File2. An object file has been
included multiple times either on the command line or with a FILES directive
in a linker command file. Remove the multiple references.
Overlapping definitions of SHAREBANK memName. A SHAREBANK
directive specifies a range of addresses that overlap a previous definition.
Overlaps are not permitted.
Inconsistent length definitions of SHAREBANK memName. All
SHAREBANK definitions which have the same NAME attribute must be of
equal length.
Multiple STACK definitions. A STACK directive occurs more than once in
the linker command file or included linker command files. Remove the multiple
STACK directives.
DS33014G-page 208
MPLINK Errors/Warnings
Undefined DATABANK/SHAREBANK memName for STACK.
Duplicate definitions of SECTION secName. Each SECTION directive
must have unique NAME attributes. Remove duplicate definitions.
Undefined CODEPAGE memName for SECTION secName. A SECTION
directive with a ROM attribute refers to a memory block which has not been
defined. Add a CODEPAGE directive to the linker command file for the
undefined memory block.
Undefined DATABANK/SHAREBANK memName for SECTION
secName. A SECTION directive with a RAM attribute refers to a memory
block that has not been defined. Add a DATABANK or SHAREBANK directive
to the linker command file for the undefined memory block.
No input object files specified. At least one object module must be
specified either on the command line or in the linker command file using the
FILES directive.
Could not find file File. An input object or library file was specified which
does not exist, or cannot be found in the linker path.
Processor types do not agree across all input files. Each object module
and library file specifies a processor type or a processor family. All input
modules processor types or families must match.
ROM width of xx not supported. An input module specifies a processor
whose ROM width is not 12, 14, or 16 bits wide.
Unknown section type for secName in file File. An input object or library
module is not of the proper file type or it may be corrupted.
Section types for secName do not match across input files. A section
with the name secName may occur in more than one input file. All input files
which have this section must also have the same section type.
Section secName is absolute but occurs in more than one input file. An
absolute section with the name secName may only occur in a single input
file. Relocatable sections with the same name may occur in multiple input
files. Either remove the multiple absolute sections in the source files or use
relocatable sections instead.
Section share types for secName do not match across input files. A
section with the name secName occurs in more than one input file, however,
in some it is marked as a shared section and in some it is not. Change the
sections share type in the source files and rebuild the object modules.
Section secName contains uninitialized data and can not have a ROM
memory attribute specified in the linker command file. Use only the RAM
attribute when defining the section in the linker command file.
DS33014G-page 209
APPENDICES
Section secName contains code and can not have a RAM memory
attribute specified in the linker command file. Use only the ROM attribute
when defining the section in the linker command file.
DS33014G-page 210
MPLINK Errors/Warnings
Symbol symName out of range of relative branch instruction. A relative
branch instruction had symName as its target, but a 2s compliment encoding
of the offset to symName wouldnt fit in the limited number of instruction bits
used for the target of a branch instruction.
Symbol symName is not word-aligned. It cannot be used as the target of
a {branch | call or goto} instruction. The target of a branch, call, or goto
instruction was at an odd address, but the instruction encoding cannot
reference addresses that are not word-aligned.
{PCL | TOSH | TOSU | TOSL} cannot be used as the destination of a
MOVFF instruction. The MOVFF instruction has unpredictable results when
its destination is the PCL, TOSH, TOSU, or TOSL registers. MPLINK will not
allow the destination of a MOVFF instruction to be replaced with any of these
addresses.
Absolute code section secName must start at a word-aligned address.
Program code sections will only be allocated at word-aligned addresses.
MPLINK will give this error message if an absolute code section address is
specified that is not word-aligned.
D.5
Linker Warnings
Fill pattern for memory memName doesnt divide evenly into unused
section locations. Last value was truncated. If a fill pattern is specified for a
ROM section, but the free space in that section isnt evenly divisible by the fill
pattern size, this warning will be issued to warn of incomplete patterns.
D.6
Could not write archive magic string in library file filename. The file may
be corrupted.
Could not write member header for memberName in library file
filename. The file may be corrupted.
DS33014G-page 211
APPENDICES
Could not open library file filename for writing. Verify that if filename
exists, it is not read-only.
D.7
DS33014G-page 212
MPLINK Errors/Warnings
Coff file filename could not write raw data.
Coff file filename could not write reloc.
Coff file filename could not write lineinfo.
Coff file filename could not write symbol.
Coff file filename could not write string table length.
Coff file filename could not write string.
D.8
D.9
APPENDICES
DS33014G-page 213
DS33014G-page 214
Introduction
MPLIB detects the following sources of error and reports them.
E.2
Highlights
Topics covered in this appendix:
Parse Errors
Library File Errors
COFF File Errors
E.3
Parse Errors
invalid switch. An unsupported switch was specified. Refer to Usage for a
list of supported command line options.
library filename is required. All commands require a library filename. All
library filenames must end with '.lib'.
invalid object filename. All object filenames must end with '.o'.
E.4
E.5
APPENDICES
DS33014G-page 215
DS33014G-page 216
Highlights
This glossary contains definitions for the terms used in the MPASM, MPLINK
and MPLIB sections. Most terms are used in all three, though some may be
section-specific.
Terms
Absolute Section
A section with a fixed absolute address which can not be changed by the
Linker.
Alpha Character
Alpha characters are those characters, regardless of case, that are normally
contained in the alphabet: (a, b, , z, A, B, , Z).
Alphanumeric
Alphanumeric characters include alpha characters and numbers: (0,1, , 9).
Application
A set of software and hardware developed by the user, usually designed to be
a product controlled by a PICmicro microcontroller.
Assemble
The act of executing the MPASM macro assembler to translate source code to
machine code.
Assembler Source Code
A text file that is processed by an assembler to produce a one-to-one
correspondence between assembler instructions and PICmicro machine
code.
Assigned Section
A section which has been assigned to a target memory block in the linker
command file. The Linker allocates an assigned section into its assigned
target memory block.
Build
A function that recompiles all the source files for an application.
DS33014G-page 217
External Linkage
A function or variable has external linkage if it can be accessed from outside
the module in which it is defined.
External Symbol
A symbol for an identifier which has external linkage.
External Symbol Definition
An external symbol for a function or variable defined in the current module.
External Symbol Reference
An external symbol which references a function or variable defined outside
the current module.
DS33014G-page 218
Glossary
External Symbol Resolution
A process performed by the linker in which external symbol definitions from all
input modules are collected in an attempt to update all external symbol
references. Any external symbol references which do not get updated cause a
linker error to be reported.
Hex Code
Executable instructions assembled or compiled from source code into
standard hexadecimal format code. Hex code can be directly converted to
object code. Hex code is contained in a hex file.
Hex File
An ASCII file containing hexadecimal addresses and values (hex code)
suitable for programming a device. This format is readable by a device
programmer.
Identifier
A function or variable name.
Initialized Data
Data which is defined with an initial value. In C, int myVar=5; defines a
variable which will reside in an initialized data section.
Internal Linkage
A function or variable has internal linkage if it can not be accessed from
outside the module in which it is defined.
Library
A library is a collection of relocatable object modules. It is created by
assembling multiple source files to object files, and then using the librarian to
combine the object files into one library file. A library can be linked with object
modules and other libraries to create executable code. Libraries are created
and manipulated with Microchips librarian, MPLIB.
Link
Linking is the process of combining object files and libraries to create
executable code. Linking is performed by Microchips linker, MPLINK.
Listing Directives
Listing Directives are those directives that control the MPASM listing file
format. They allow the specification of titles, pagination and other listing
control.
Listing File
A listing file is an ASCII text file that shows the machine code generated for
each assembly instruction, MPASM directive, or macro encountered in a
source file.
DS33014G-page 219
DS33014G-page 220
Glossary
Node
MPLAB project component.
Object Code
The machine code that is produced from the source code after it is processed
by an assembler or compiler. This code will be the memory-resident code that
will run on the PICmicro in the users application. Relocatable code is code
produced by MPASM or MPLAB-C17/C18 that can be run through MPLINK.
Object code is contained in an object file.
Object File
A module which may contain relocatable code or data and references to
external code or data. Typically, multiple object modules are linked to form a
single executable output.Special directives are required in the source code
when generating an object file. The object file contains object code.
Object File Directives
These directives are used only when creating an object file.
Operators
Operators are arithmetic symbols, like the plus sign + and the minus sign -,
that are used when forming well-defined expressions. Each operator has an
assigned precedence.
PC
Any IBM or compatible Personal Computer. MPLAB needs a 486X or better
machine.
PC Host
The computer running Windows 3.1x or Windows 95/98.
PICmicro
PICmicro refers to the PIC12CXX, PIC14000, PIC16C5X, PIC16CXX,
PIC17CXX and PIC18CXX Microchip microcontroller families.
Precedence
Precedence is the concept that some elements of an expression get
evaluated before others. Operators of the same precedence are evaluated
from left to right.
Program Memory
Memory in the emulator or simulator containing the downloaded target
application firmware.
Project
A set of source files and instructions to build the object code for an
application.
DS33014G-page 221
DS33014G-page 222
Glossary
Source File
The ASCII text file of PICmicro instructions and MPASM directives and
macros (source code) that will be translated into machine code. It is an ASCII
file that can be created using any ASCII text editor.
Stack
An area in data memory where function arguments, return values, local
variables, and return addresses are stored.
Symbol
A symbol is a general purpose mechanism for describing the various pieces
which comprise a program. These pieces include function names, variable
names, section names, file names, struct/enum/union tag names, etc.
Unassigned Section
A section which has not been assigned to a specific target memory block in
the linker command file. The linker must find a target memory block in which
to allocate an unassigned section.
Uninitialized Data
Data which is defined without an initial value. In C, int myVar; defines a
variable which will reside in an uninitialized data section.
DS33014G-page 223
DS33014G-page 224
DS33014G-page 225
DS33014G-page 226
Index
PROCESSOR ............................ 42, 55, 64, 203
Processor Type ...................................... 22, 203
Program Memory ............................................ 74
Project ............................................ 29, 111, 221
R
RADIX ............................................................ 64
Radix ............................ 12, 22, 59, 91, 203, 222
RAM Allocation ............................................... 75
README Files ................................................. 4
Relocatable Objects ....................................... 73
RES ................................................................ 65
S
SET ...................................... 19, 43, 65, 70, 198
SHAREBANK ....................... 122, 123, 125, 126
Shell ....................................................... 21, 222
Source Code ................................................ 222
Source File ..................................................... 16
SPACE ........................................................... 66
STACK Definition ......................................... 126
SUBTITLE ...................................................... 66
T
Text Strings .................................................... 89
TITLE .............................................................. 66
U
UDATA ........................................................... 67
UDATA_ACS ............................................ 68, 75
UDATA_OVR ................................................. 68
UDATA_SHR .................................................. 69
UPPER ........................................................... 75
V
VARIABLE .......................................... 19, 43, 70
W
Warnings ...................................... 202, 211, 213
WHILE ........................................ 50, 71, 86, 200
WHILE-ENDW .............................................. 200
Windows Shell Interface ................................. 27
WWW Address ................................................. 5
DS33014G-page 227
DS33014G-page 228
Index
NOTES:
DS33014G-page 229
AMERICAS (continued)
Corporate Office
Toronto
Singapore
Atlanta
Boston
Microchip Technology Inc.
5 Mount Royal Avenue
Marlborough, MA 01752
Tel: 508-480-9990 Fax: 508-480-8575
Chicago
Microchip Technology Inc.
333 Pierce Road, Suite 180
Itasca, IL 60143
Tel: 630-285-0071 Fax: 630-285-0075
Dallas
Microchip Technology Inc.
4570 Westgrove Drive, Suite 160
Addison, TX 75248
Tel: 972-818-7423 Fax: 972-818-2924
Dayton
Microchip Technology Inc.
Two Prestige Place, Suite 150
Miamisburg, OH 45342
Tel: 937-291-1654 Fax: 937-291-9175
Detroit
Microchip Technology Inc.
Tri-Atria Office Building
32255 Northwestern Highway, Suite 190
Farmington Hills, MI 48334
Tel: 248-538-2250 Fax: 248-538-2260
Los Angeles
Microchip Technology Inc.
18201 Von Karman, Suite 1090
Irvine, CA 92612
Tel: 949-263-1888 Fax: 949-263-1338
New York
Microchip Technology Inc.
150 Motor Parkway, Suite 202
Hauppauge, NY 11788
Tel: 631-273-5305 Fax: 631-273-5335
San Jose
Microchip Technology Inc.
2107 North First Street, Suite 590
San Jose, CA 95131
Tel: 408-436-7950 Fax: 408-436-7955
ASIA/PACIFIC
Hong Kong
ASIA/PACIFIC (continued)
Taiwan, R.O.C
Microchip Technology Taiwan
10F-1C 207
Tung Hua North Road
Taipei, Taiwan, ROC
Tel: 886-2-2717-7175 Fax: 886-2-2545-0139
EUROPE
Beijing
United Kingdom
India
Denmark
Japan
France
Korea
Germany
Shanghai
Microchip Technology
RM 406 Shanghai Golden Bridge Bldg.
2077 Yanan Road West, Hong Qiao District
Shanghai, PRC 200335
Tel: 86-21-6275-5700 Fax: 86 21-6275-5060
Italy
11/15/99
All rights reserved. 1999 Microchip Technology Incorporated. Printed in the USA. 11/99
Information contained in this publication regarding device applications and the like is intended for suggestion only and may be superseded by updates. No representation or warranty is given and no liability is assumed
by Microchip Technology Incorporated with respect to the accuracy or use of such information, or infringement of patents or other intellectual property rights arising from such use or otherwise. Use of Microchips products
as critical components in life support systems is not authorized except with express written approval by Microchip. No licenses are conveyed, implicitly or otherwise, under any intellectual property rights. The Microchip
logo and name are registered trademarks of Microchip Technology Inc. in the U.S.A. and other countries. All rights reserved. All other trademarks mentioned herein are the property of their respective companies.