11.07.2015 Views

PicC 9.50 dsPIC Manual.pdf

PicC 9.50 dsPIC Manual.pdf

PicC 9.50 dsPIC Manual.pdf

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.

C Language FeaturesMixing C and Assembler Code}asm("mov.w _var,w0");asm("sl.w w0,w0");asm("mov.w w0,_var");When using in-line assembler code, great care must be taken to avoid interacting with compilergeneratedcode. The code generator cannot scan the assembler code for register usage and so willremain unaware if registers are clobberred or used by the code. If in doubt, compile your programwith the DSPICC -S option and examine the assembler code generated by the compiler.3.11.3 Accessing C objects from within Assembly CodeThe following applies regardless of whether the assembly is part of a separate assembly module, orin-line with C code.For any non-local assembly symbol, the GLOBAL directive must be used to link in with the symbolif it was defined elsewhere. If it is a local symbol, then it may be used immediately.3.11.3.1 Equivalent Assembly SymbolsThe assembler equivalent identifier to an identifier in C code follows a form that is dependent onthe scope and type of the C identifier. The different forms are discussed below. Accessing the Cidentifier in C code and its assembly equivalent in assembly code implies accessing the same object.Here, “global” implies defined outside a function; “local” defined within a function.C identifiers are assigned different symbols in the output assembly code so that an assemblyidentifier cannot conflict with an identifier defined in C code. If assembly programmers chooseidentifier names that do not begin with an underscore, these identifiers will never conflict with Cidentifiers. Importantly, this implies that the assembly identifier, i, and the C identifier i relate todifferent objects at different memory locations.3.11.3.2 Accessing specifal function register names from assemblerWhen the code generator compiles a C module, it includes a list of EQU directives for some of themore commonly used SFRs. These registers are listed in Table 3.8. Any assembly code that is placedin-line into a C module can use these register names. If writing separate assembly modules, theseSFR definitions will not be present since the code generator does not process assembler files in anyway.Another way of using the SFRs in in-line assembly code is refer to the symbols defined by thechip-specific C header files. Whenever you include into a C module, all the availableSFRs are defined as absolute C variables. As the contents of this file is C code, it cannot be includedinto an assembler module, but assembler code can uses these definitions. To use a SFR in in-line53

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

Saved successfully!

Ooh no, something went wrong!