EmbeddedRelated.com
Forums

storing a variable in a dedicated register

Started by Jim_Strieter/Rockwell_Automation_Strieter/CONTRACT/NorthAmerica/RA/Rockwell August 3, 2005
Everybody,
I am using the '430F1232. I need to store a variable constantly all the 
time permanently in register 15.
Doing it in assembly looks like

#define [variable name] R15

I tried entering that into my C program ('cause I have to do this in C), 
and the compiler bawlks at it.

The online help talks about this statement

  __regvar __no_init int NMA @ __R5;

but implies that it only works with R4 and R5. My program's not working 
and I want to find out of this is a reason.

Cheers,

Jim Strieter
Advanced Technology
Rockwell Automation




Beginning Microcontrollers with the MSP430

Jim_Strieter/Rockwell_Automation_Strieter/CONTRACT/NorthAmerica/RA/Rockwell

wrote:

>Everybody,
>I am using the '430F1232. I need to store a variable constantly all the

>time permanently in register 15.
>Doing it in assembly looks like
>
>#define [variable name] R15
>
>I tried entering that into my C program ('cause I have to do this in
C), 
>and the compiler bawlks at it.
>
>The online help talks about this statement
>
>  __regvar __no_init int NMA @ __R5;
>
>but implies that it only works with R4 and R5. My program's not working

>and I want to find out of this is a reason.
>  
>

Hi Jim and Everybody!

Storing global variables in processor registers is not standardized 
between the different MSP430 compilers.

When it comes to the IAR compiler (which is the one that uses the 
__regvar syntax) it only has support for using R4 and R5. If you 
dedicate more registers to global variables then there are fewer ones 
available to the compiler, making all the rest of the the code larger. 
In addition, this would also constrain the hand-written floating-point 
support code,  so giving up more than two global registers is not a good 
idea.

The calling convention directly controls which registers you could use. 
Register R12 through to R15 are used to pass normal parameters. The IAR 
compiler also uses R8 to R11 to pass 64 bit scalars (long long and 
doubles). This leaves R4, R5, R6, and R7. Out of these we selected R4 
and R5 since they have earlier been used by some ROM-monitor code.

To conclude, you can't use R15 as a dedicated register in using the IAR 
compiler, or any other compiler on the MSP430 market that I know of.

    -- Anders Lindgren, IAR Systems
-- 
Disclaimer: Opinions expressed in this posting are strictly my own and 
not necessarily those of my employer.