SW006012 Microchip Technology, SW006012 Datasheet - Page 122

C COMPILER FOR DSPIC30F FAMILY

SW006012

Manufacturer Part Number
SW006012
Description
C COMPILER FOR DSPIC30F FAMILY
Manufacturer
Microchip Technology
Type
MPLAB® C30 Compilerr
Series
PIC24 & DsPICr
Datasheets

Specifications of SW006012

Supported Families
PIC24, DsPIC30F And DsPIC33F
Core Architecture
PIC, DsPIC
Kit Contents
Software And Docs
Mcu Supported Families
PIC24 MCUs And DsPIC DSCs
Tool Type
Compiler
Processor Series
PIC24, dsPIC
Lead Free Status / RoHS Status
Not applicable / Not applicable
For Use With/related Products
dsPIC30F
Lead Free Status / Rohs Status
Lead free / RoHS Compliant
MPLAB
DS51284F-page 116
®
C30 User’s Guide
EXAMPLE 8-6:
Unless an output operand has the & constraint modifier, MPLAB C30 may allocate it in
the same register as an unrelated input operand, on the assumption that the inputs are
consumed before the outputs are produced. This assumption may be false if the
assembler code actually consists of more than one instruction. In such a case, use &
for each output operand that may not overlap an input operand. For example, consider
the following function:
int
exprbad(int a, int b)
{
}
The intention is to compute the value (a + b) << a. However, as written, the value
computed may or may not be this value. The correct coding informs the compiler that
the operand c is modified before the asm instruction is finished using the input
operands, as follows:
int
exprgood(int a, int b)
{
}
EXAMPLE 8-7:
When the assembler instruction has a read-write operand, or an operand in which only
some of the bits are to be changed, you must logically split its function into two separate
operands: one input operand and one write-only output operand. The connection
between them is expressed by constraints that say they need to be in the same location
when the instruction executes. You can use the same C expression for both operands
or different expressions. For example, here is the add instruction with bar as its
read-only source operand and foo as its read-write destination:
asm ("add %2,%1,%0"
: "=r" (foo)
: "0" (foo), "r" (bar));
The constraint “0” for operand 1 says that it must occupy the same location as operand
0. A digit in constraint is allowed only in an input operand and must refer to an output
operand. Only a digit in the constraint can ensure that one operand will be in the same
place as another. The mere fact that foo is the value of both operands is not enough
to ensure that they will be in the same place in the generated assembler code. The
following would not work:
asm ("add %2,%1,%0"
: "=r" (foo)
: "r" (foo), "r" (bar));
int c;
__
return(c);
int c;
__
return(c);
asm
asm
__
__
("add %1,%2,%0\n sl %0,%1,%0"
("add %1,%2,%0\n sl %0,%1,%0"
: "=r"(c) : "r"(a), "r"(b));
: "=&r"(c) : "r"(a), "r"(b));
USING '&' TO PREVENT INPUT REGISTER CLOBBERING
MATCHING OPERANDS
© 2007 Microchip Technology Inc.

Related parts for SW006012