Compiler memory barriers has the effect among other things to force the compiler to make sure all stack variables that are cached in registers are written t
I guess you can achieve it by specifying your variable in the list of output values of asm:
__asm__ __volatile__ ("" : "=r" (x) : : )
See Extended Asm for some information.
It may be better to use "g" constraint instead of "r" as more permissive.
__asm__ __volatile__ ("" : "=g" (x) : : )
Also, I've found another great howto for inline assembly.