Sat Feb 7 11:43:48 EST 2015

Setting bits

What is the fastest way to set a bit in a register on CM3?

Compiler generates:

        ldr	r3, [pc, #32]	; r3 <- 0x40000010 TIM2.SR
	ldr	r2, [r3, #0]
	bic.w	r2, r2, #1
        str	r2, [r3, #0]

The equivalent in gas is:

        .syntax unified
        ldr	r3, tim2_reg
	ldr	r2, [r3, #0]
        bic	r2, r2, #1
        bx	lr
        .word 0x40000010

Unified syntax[1].

.syntax [unified | divided]
    This directive sets the Instruction Set Syntax as described in the ARM-Instruction-Set section.

W suffix forces a 32-bit instruction encoding. The .N suffix forces a 16-bit instruction encoding.

[1] https://sourceware.org/binutils/docs-2.23/as/ARM_002dInstruction_002dSet.html#ARM_002dInstruction_002dSet