Bit Band Address Generator

This is from the Mastering STM32 book:

#temp |= 0x4;
a: 79fb ldrb r3, [r7, #7]
c: f043 0304 orr.w r3, r3, #4
10: 71fb strb r3, [r7, #7]

#temp &= ~0x4;
12: 79fb ldrb r3, [r7, #7]
14: f023 0304 bic.w r3, r3, #4
18: 71fb strb r3, [r7, #7]

As we can see, such a simple operation requires three assembly instructions (fetch, modify, save). This leads to two types of problems. First of all, there is a waste of CPU cycles related to those three instructions. Second, that code works fine if the CPU is working in single task mode, and we have just one execution stream, but, if we are dealing with concurrent execution, another task (or simply an interrupt routine) may affect the content of the memory before we complete the “bit mask” operation (that is, for example, an interrupt occurs between instructions at lines 0xC-0x10 or 0x14-0x18 in the above assembly code).

Bit-banding is the ability to map each bit of a given area of memory to a whole word in the aliased bit-banding memory region, allowing atomic access to such bit.

/r/embedded Thread Parent Link - i.redd.it