07.04.2013 Views

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

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

16-Bit C <strong>Compiler</strong> User’s Guide<br />

TABLE 9-1: CONSTRAINT LETTERS SUPPORTED BY THE COMPILER<br />

Letter Constraint<br />

a Claims WREG<br />

b Divide support register W1<br />

c Multiply support register W2<br />

d General purpose data registers W1 - W14<br />

e Non-divide support registers W2 - W14<br />

g Any register, memory or immediate integer oper<strong>and</strong> is allowed, except <strong>for</strong><br />

registers that are not general registers.<br />

i An immediate integer oper<strong>and</strong> (one with constant value) is allowed. This<br />

includes symbolic constants whose values will be known only at assembly time.<br />

r A register oper<strong>and</strong> is allowed provided that it is in a general register.<br />

v AWB register W13<br />

w Accumulator register A - B<br />

x x prefetch registers W8 - W9<br />

y y prefetch registers W10 - W11<br />

z MAC prefetch registers W4 - W7<br />

0, 1, … , An oper<strong>and</strong> that matches the specified oper<strong>and</strong> number is allowed. If a digit is<br />

9<br />

used together with letters within the same alternative, the digit should come last.<br />

By default, %n represents the first register <strong>for</strong> the oper<strong>and</strong> (n). To access the<br />

second, third, or fourth register, use a modifier letter.<br />

T A near or far data oper<strong>and</strong>.<br />

U A near data oper<strong>and</strong>.<br />

TABLE 9-2: CONSTRAINT MODIFIERS SUPPORTED BY THE COMPILER<br />

Letter Constraint<br />

= Means that this oper<strong>and</strong> is write-only <strong>for</strong> this instruction: the previous value is<br />

discarded <strong>and</strong> replaced by output data.<br />

+ Means that this oper<strong>and</strong> is both read <strong>and</strong> written by the instruction.<br />

& Means that this oper<strong>and</strong> is an earlyclobber oper<strong>and</strong>, which is modified<br />

be<strong>for</strong>e the instruction is finished using the input oper<strong>and</strong>s. There<strong>for</strong>e, this<br />

oper<strong>and</strong> may not lie in a register that is used as an input oper<strong>and</strong> or as part of<br />

any memory address.<br />

d Second register <strong>for</strong> oper<strong>and</strong> number n, i.e., %dn..<br />

q Fourth register <strong>for</strong> oper<strong>and</strong> number n, i.e., %qn..<br />

t Third register <strong>for</strong> oper<strong>and</strong> number n, i.e., %tn..<br />

EXAMPLE 9-3: PASSING C VARIABLES<br />

This example demonstrates how to use the swap instruction (which the compiler does<br />

not generally use):<br />

asm ("swap %0" : "+r"(var));<br />

Here var is the C expression <strong>for</strong> the oper<strong>and</strong>, which is both an input <strong>and</strong> an output<br />

oper<strong>and</strong>. The oper<strong>and</strong> is constrained to be of type r, which denotes a register oper<strong>and</strong>.<br />

The + in +r indicates that the oper<strong>and</strong> is both an input <strong>and</strong> output oper<strong>and</strong>.<br />

Each oper<strong>and</strong> is described by an oper<strong>and</strong>-constraint string followed by the C expression<br />

in parentheses. A colon separates the assembler template from the first output<br />

oper<strong>and</strong>, <strong>and</strong> another separates the last output oper<strong>and</strong> from the first input, if any.<br />

Commas separate output oper<strong>and</strong>s <strong>and</strong> separate inputs.<br />

DS51284H-page 122 © 2008 <strong>Microchip</strong> Technology Inc.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!