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.

MSP430FR4133: variables being written on same register

Part Number: MSP430FR4133

Hello everyone. I'm trying to process some data using the MSP430FR4133 EVM, and i'm getting this issue where my variables are being written to the same register. This snippet of code i'm taking in some dummy array of 8 bit values, combining them into one 16 bit value, and then dissecting them into an exponent (bits 15-12) and a mantissa (bits 11-0). Whenever i run the code the exponent variables shares its value with the "value" variable. I looked and they using the same register as their address. How can I specify them not to be this way? 

  • The compiler is free to reuse registers as it sees fit. If it sees that something in a register isn't going to be needed again, it can put something else there. This will never be a problem for the compiler as it keeps careful track of such things.

  • Then why would my variables be written to the same register? When i step through the code in debug mode, I can see both "exponent" and "value" changing whenever the other changes. I instantiate "mantissa", "exponent", and "value" right before I perform operations on them, and you can see on that right that it chose to put mantissa on Register R10 by itself, but exponent and value on Register R15.

  • As I said, the compiler keeps very careful track of register usage. If it sees that a value in a register isn't going to be needed later, it can and will  use that register for something else. But your debugger doesn't have that information (it would have to duplicate the operation on the source code of the compiler and optimizer) which is why you see both change. It has no clue what the scope of each is.

    Assignment of auto variables to registers is not a static one and done sort of thing. The compiler uses registers when it wants to.

    You say you chose to put a variable in R10 but I see nothing in what you have posted that could possibly do that.

**Attention** This is a public forum