MPLAB C Compiler for PIC24 MCUs and dsPIC DSCs ... - Microchip
MPLAB C Compiler for PIC24 MCUs and dsPIC DSCs ... - Microchip
MPLAB C Compiler for PIC24 MCUs and dsPIC DSCs ... - Microchip
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Differences Between 16-Bit Device C <strong>and</strong> ANSI C<br />
as usual if the program refers to its address, because that can’t be inlined. The compiler<br />
will only eliminate inline functions if they are declared to be static <strong>and</strong> if the function<br />
definition precedes all uses of the function.<br />
When an inline function is not static, then the compiler must assume that there<br />
may be calls from other source files. Since a global symbol can be defined only once<br />
in any program, the function must not be defined in the other source files, so the calls<br />
therein cannot be integrated. There<strong>for</strong>e, a non-static inline function is always<br />
compiled on its own in the usual fashion.<br />
If you specify both inline <strong>and</strong> extern in the function definition, then the definition is<br />
used only <strong>for</strong> inlining. In no case is the function compiled on its own, not even if you<br />
refer to its address explicitly. Such an address becomes an external reference, as if you<br />
had only declared the function <strong>and</strong> had not defined it.<br />
This combination of inline <strong>and</strong> extern has a similar effect to a macro. Put a function<br />
definition in a header file with these keywords <strong>and</strong> put another copy of the definition<br />
(lacking inline <strong>and</strong> extern) in a library file. The definition in the header file will cause<br />
most calls to the function to be inlined. If any uses of the function remain, they will refer<br />
to the single copy in the library.<br />
2.3.4 Variables in Specified Registers<br />
The compiler allows you to put a few global variables into specified hardware registers.<br />
Note: Using too many registers, in particular register W0, may impair the ability of<br />
the 16-bit compiler to compile.<br />
You can also specify the register in which an ordinary register variable should be<br />
allocated.<br />
• Global register variables reserve registers throughout the program. This may be<br />
useful in programs such as programming language interpreters which have a<br />
couple of global variables that are accessed very often.<br />
• Local register variables in specific registers do not reserve the registers. The<br />
compiler’s data flow analysis is capable of determining where the specified<br />
registers contain live values, <strong>and</strong> where they are available <strong>for</strong> other uses. Stores<br />
into local register variables may be deleted when they appear to be unused.<br />
References to local register variables may be deleted, moved or simplified.<br />
These local variables are sometimes convenient <strong>for</strong> use with the extended inline<br />
assembly (see Chapter 9. “Mixing Assembly Language <strong>and</strong> C Modules”), if you<br />
want to write one output of the assembler instruction directly into a particular register.<br />
(This will work provided the register you specify fits the constraints specified <strong>for</strong> that<br />
oper<strong>and</strong> in the inline assembly statement).<br />
2.3.4.1 DEFINING GLOBAL REGISTER VARIABLES<br />
You can define a global register variable like this:<br />
register int *foo asm ("w8");<br />
Here w8 is the name of the register which should be used. Choose a register that is<br />
normally saved <strong>and</strong> restored by function calls (W8-W13), so that library routines will not<br />
clobber it.<br />
Defining a global register variable in a certain register reserves that register entirely <strong>for</strong><br />
this use, at least within the current compilation. The register will not be allocated <strong>for</strong> any<br />
other purpose in the functions in the current compilation. The register will not be saved<br />
<strong>and</strong> restored by these functions. Stores into this register are never deleted even if they<br />
would appear to be dead, but references may be deleted, moved or simplified.<br />
© 2008 <strong>Microchip</strong> Technology Inc. DS51284H-page 27