17.02.2015 Views

CCS C Compiler Manual PCB / PCM / PCH

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

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

PreProcessor<br />

{<br />

int8 a;<br />

int16 b;<br />

} test;<br />

Care should be taken by the user when accessing individual elements<br />

of a packed struct – creating a pointer to 'b' in 'test' and attempting to<br />

dereference that pointer would cause an address fault. Any attempts<br />

to read/write 'b' should be done in context of 'test' so the compiler<br />

knows it is packed:<br />

test.b = 5;<br />

Purpose<br />

Examples:<br />

Example Files:<br />

((aligned(y))<br />

By default the compiler will alocate a variable in the first free memory<br />

location. The aligned attribute will force the compiler to allocate a<br />

location for the specified variable at a location that is modulus of the y<br />

parameter. For example:<br />

int8 array[256] __attribute__((aligned(0x1000)));<br />

This will tell the compiler to try to place 'array' at either 0x0, 0x1000,<br />

0x2000, 0x3000, 0x4000, etc.<br />

To alter some specifics as to how the compiler operates<br />

struct __attribute__((packed))<br />

{<br />

int8 a;<br />

int8 b;<br />

} test;<br />

int8 array[256] __attribute__((aligned(0x1000)));<br />

None<br />

#asm #endasm<br />

Syntax:<br />

Elements:<br />

Examples:<br />

Example Files:<br />

#ASM or #ASM ASIS code #ENDASM<br />

code is a list of assembly language instructions<br />

int_ffind_parity(int data){int count;, result,datal; data1=data; asm MOV<br />

#0x08, MOV WF, count CLRF result Loop: MOVF data1,w XORWF<br />

result, F RRCF data1,F DECFSZ count,F BRA LOOP MOVLW 0x01<br />

ANDWF resutt, F #end asm<br />

retturn (result)';<br />

}<br />

ex_glint.c<br />

85

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

Saved successfully!

Ooh no, something went wrong!