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.

MSP430 general use registers for variables (-ffixed-reg)

Hello,


I am using four registers as global variables (R10, R11, R12, R13), in this case, as counters in interrupt. Every 10 us I need to check if there is 0 or 1 on pin. If there is 1, I increment the register value, using inline assembler. After 20 ms I send the value in the registers by I2C and clear them. Whole code is written in C, only few inline asm to work with the registers. Everything is working.

My only concern is about compiler using the R10 to R13 registers. I need to know, how to lock these registers, that they are not used by the compiler... I checked the dissassembly and only use of these registers is the part, where I use them. But what if the code is compiled with newer or older compiler....? Is there any chance to say to the compiler to not use my registers? Any idea how the -ffixed-reg works? (example ) Will this help my cause?


Thank you.

  • I presume you use the GCC MSP430 compiler, and not the TI MSP430 compiler.  

    The documentation on the GCC compiler can be found by performing an Internet search on the term GCC documentation.  I usually bring up the PDF file and search it.  You'll find that the -ffixed-reg option does cause the compiler to not use the named register.  So this option tells the compiler to not use R4: -ffixed-R4 .  If you specify something that is not a valid register name, the compiler issues an error.

    But you have a problem with the registers R12 and R13.  The calling convention uses those registers to pass arguments to functions.  There is nothing the compiler can do to avoid that.  It has to adhere to the convention.  You should change your global variable registers to something in the range R4-R10.

    Thanks and regards,

    -George

  • Hello George.


    Thank you for your reply. I am using TI MSP430 compiler.

    1. So it seem, that the -ffixed-Rx won't help me..... I tried to google any info I could get before I wrote my question here. But I wasn't sure about the -ffixed command and what is possible with the MPS430 compiler, that's why I asked...

    2. Thanks again. I will change change it from the R12 and R13 and I will hope, that the compiler won't use R8 to R11 regs and I will use them for my global var.

    I was hoping, that there is some instrument, that can prevent the compiler to use some of the registers that I need for my code thru the whole program....

    Thanks and best regards.

    Martin

  • Martin Barton said:
    I am using TI MSP430 compiler.

    That changes everything.  The TI compiler is different from the GCC compiler in nearly every way.  This includes the command line options.  The equivalent option on the TI compiler is named --global_register.  Please read about it in the MSP430 compiler manual.  You'll see that you can only reserve the registers R4 and R5.

    Thanks and regards,

    -George