|mspgcc: A port of the GNU tools to the Texas Instruments MSP430 microcontrollers|
|<<< Previous||An introduction to the TI MSP430 low-power microcontrollers||Next >>>|
The processor has 16 16-bit registers, although only 12 of them are truly general purpose. The first four have dedicated uses:
r0 (aka PC) is the program counter. You can jump by assigning to r0, and immediate constants are fetched from the instruction stream using the post-increment addressing mode on r0. The PC is always even.
r1 (aka SP) is the stack pointer. This is used by call and push instructions, and by interrupt handling. There is only one stack pointer; the MSP430 doesn't have anything resembling a supervisor mode. The stack pointer is always even; It is unclear if the LSB is even implemented.
r2 (aka SR) is the status register. Its bits are assigned as follows:
GIE is the global interrupt enable. Turning off this bit masks interrupts. (NOTE: it may be delayed by 1 cycle, so an interrupt may be taken after the instruction after GIE is cleared. Add a NOP or clear GIE one instruction earlier than your real "critical section".)
N, Z, C and V are the usual processor status bits, set as a side effect to instruction execution. If r2 is specified as a destination, the explicitly written bits override the side effects. An instruction sets all 4 bits, or none of them. Logical instructions set C to the opposite of Z (C is set if the result is NOT zero), and clear V to 0.
C is a "carry" bit as opposed to a "borrow" bit when subtracting. That is, subtract with carry of A-B computes A + ~B + Carry. (~ is the C "not" or "bitwise invert" operator.)
Note that the basic move instruction does NOT set these bits (unless it's a move to r2).
r3 is hardwired to 0. If specified as a source, its value is 0. If specified as a destination, the value is discarded.
Note that some assemblers for the MSP430 allow the use of the alternate names "PC" for "r0", "SP" for "r1", and "SR" for "r2". GNU msp430 binutils does not understand these alternate names. You must use "r0", "r1" or "r2".