Accessing the MSP430's peripheral registers - the SFRs

The MSP430's memory mapped peripheral registers are termed special function registers (SFRs). The SFRs valid for the device you are using are declared when you include "io.h" in your source code, and specify the MCU architecture in the GCC command line.

You can consider any SFR as a normal variable, which is simply mapped to the specific memory location. You do not have to care about exactly which one.

SFRs are read from and written to using normal C assignments, so:

SFR = value;
will write from to and SFR, and
variable = SFR;
will read from one.

All SFRs are declared as "volatile". This implies a-la Harvard architecture GCC behaviour for read-modify-write: mov SFR's value to a register, modify the register, write back to the SFR. However, the GCC port for the MSP430 takes into account the possibility that this can often be reduced to something like:

and.b	#1, &0x0120 
and the appropriate code is produced. This optimisation can be switched off with the "-mno-volatile-workaround" compiler flag.