The optional volatile keyword tells the compiler that the assembly code has side-effects that the output, input, and clobber lists do not represent. For example, use this keyword with inline assembly code that sets the value of a System register.
Examples
The following is an example where the volatile keyword is required. If the volatile keyword is omitted, this example appears to still work. However, if the compiler inlines the code into a function that does not use the return value (old_table), then the inline assembly statement appears to be unnecessary, and could get optimized out. The volatile keyword lets the compiler know that the assembly has an effect other than providing the output value, so that this optimization does not happen.
The compiler inlines the calls to the functions without_volatile() and with_volatile() into foo(). However, because foo() does not use the return value of without_volatile(), the compiler removes the call to without_volatile().
Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers of your data.