Search code examples
gccintrinsicsmsp430

Bit manipulation intrinsics using GCC for MSP430


The MSP430 series microcontrollers provide fast bit set / bit clear machine instructions.

These bit manipulation comamnds are useful for some register or I/O manipulations that have side effects or need atomic access to prevent glitches or race conditions.

However, beside many intrinsics for almost all other special features of the MSP430 core, GCC does not provide intrinsics to the bit manipulation instructions.

Why is that? Does GCC still issue those instructions, and what C code would be neccessary to issue them?


Solution

  • The C language already allows to express bit manipulations:

    $ cat bits.c
    #include <msp430.h>
    void main(void)
    {
            P1IFG &= ~BIT1;
            P1IE |= BIT1;
    }
    $ msp430-gcc -mmcu=msp430f2013 -Os -S bits.c
    $ cat bits.s 
    ...
            ; end of prologue
            BIC.B   #2, &0x0023
            BIS.B   #2, &0x0025
            ; start of epilogue
    ...