0

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)
          ); 
old_timer
  • 69,149
  • 8
  • 89
  • 168
  • STRB makes no sense with a register output; it's a store to memory. Just tell the compiler you produce an output in R0 and let it handle storing. (https://stackoverflow.com/tags/inline-assembly/info / [ARM inline asm: exit system call with value read from memory](https://stackoverflow.com/a/37363860) – Peter Cordes Mar 05 '22 at 01:27

1 Answers1

1

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.

Chris Dodd
  • 119,907
  • 13
  • 134
  • 226