This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

how to use general purpose registers apart from R4 and R5

Other Parts Discussed in Thread: MSP430F2274

Hi,

       I've checked the IAR c/c++ compiler reference page 221 , but It has given R4 and R5 general registers to use first to lock them and then use them

what if I wanna use many registers ? any examples links for MSP430F2274 series to use general purpose registers in C Programming

  • If you want to use c, let c-compiler use what it wants to use,

    If you want to decide which register to use, do not use c.

  • There are documented ways to mix C + assembler, and generally you do need to either limit your register use, or preserve the values of any registers you may use and then return them to their previous values before any C routines execute.  Sometimes you may even have to prevent interrupts if you've disturbed the contents of certain global / compiler use variables, though this is a less common necessity.  Check the documentation for your compiler.

    Typically there are also documents that show you how to call an assembly language function from C and in such a case you're more free to use whatever registers you want as long as you obey the calling and exit conventions relevant to your function call setup.

    You can always write some C code and then compile it to assembler, inspect the assembler and use that as a guide to either refine the C code until it efficiently uses registers as you require, or you may choose to hand modify the generated assembler code and use it either as inline assembler or as a c-callable assembly function of your own customization to garner the desired performance / efficiency effects.

    Typically it should be possible to get the C compiler to be as efficient as your hand coded assembly would be for most simple sections of code inolving loops or simple macros / trivial subroutines / inline functions et. al.

     

**Attention** This is a public forum