Reputation: 11
I use the following piece of assembly code to enter the critical section in ARM Cortex-M4. The question is, how can I access the local variable primeMask?
volatile uint8_t primaskValue;
asm(
"MRS R0, PRIMASK \n"
"CPSID i \n"
"STRB R0,%[output] \n"
:[output] "=r" (primaskValue)
);
Upvotes: 0
Views: 840
Reputation: 126408
The %[output]
string in the asm code is replaced by the register used to hold the value specified by the constraint [output] "=r" (primaskValue)
which will be a register used as the value of primaskValue afterwards. So within the block of the asm code, that register is the location of primaskValue.
If you instead used the constraint string "+r"
, that would be input and output (so the register would be initialized with the prior value of primaskValue as well as being used as the output value)
Since primaskValue
had been declared as volatile
this doesn't make a lot of sense -- it is not at all clear what (if anything) volatile
means on a local variable.
Upvotes: 1