Using ARM cortex with thumb instruction set and Keil realview compiler, is it safe to access to 32 bit integer? Since the thumb register set is 16 bits, does this mean, fetching a 32 bit int needs 2 machine instructions? If so, accessing 32 bit will not be atomic. If my worry is true, does it mean that int assignment should be protected by a critical region?
Asked
Active
Viewed 1,527 times
2 Answers
1
Thumb uses the same 32-bit registers as ARM, so there's no issue there. What's halved is the instruction size (and even that is not strictly true for Thumb-2).
Do not worry, you don't need to change your code if you're compiling to Thumb.

Igor Skochinsky
- 24,629
- 2
- 72
- 109
-
Likewise both thumb and thumb2 you retain the ldm/stm instructions, up to 8 registers per instruction with thumb and looks to be the full complement as ARM for thumb2. Basically if you were happy with the ARM's behavior then dont worry about thumb/thumb2. It is an instruction decoder thing not an execution thing. – old_timer Jun 17 '11 at 18:20
-
However, the LDM/STM instructions are not atomic for the whole set of up to 8 registers. Atomicity is only guaranteed per 32-bit word. – unixsmurf Jun 24 '11 at 13:23
0
The instruction size is 16-Bit in thumb mode, not the register size.
This means that a constant assignment - as in i=1;
- can be seen as atomic. Although more than one instruction is generated, only one will modify the memory location of i
even if i
is int32_t
.
But you need a critical section once you to things like i=i+1
. That is of course not atomic.

Turbo J
- 7,563
- 1
- 23
- 43