gcc will always issue assembly instructions that you say to emit. Therefore, instead of explicitly writing code to load registers with the value you want to manipulate, instead you want to tell gcc to do this on your behalf. You can do this with case restrictions.
Unfortunately, the 6811 code generator does not seem to be a standard part of gcc --- I do not review the documentation in the manual. Therefore, I cannot point you to a specific bit of the document. But the general bit that you should read is here: http://gcc.gnu.org/onlinedocs/gcc-4.8.1/gcc/Extended-Asm.html#Extended-Asm
The syntax is fancy, but a summary:
asm("instructions" : outputs : inputs);
... where inputs and outputs are lists of constraints that tell gcc what value to put where. Classic example:
asm("fsinx %1,%0" : "=f" (result) : "f" (angle));
f indicates that the named value should go into the floating point register; = indicates exit; then the register names are replaced in the instructions.
So, you probably want something like this:
asm("b" #op " " #offset ",%0 " #mask : "=Z" (i) : "0" (i));
... where i is the variable containing the value you want to change. Z you need to find in 6811 gcc docs --- this is a constraint that represents a case that is valid for the asm command that is created. 0 indicates that the input shares the register with output 0 and is used for read / write values.
Since you told gcc which register you want i be, it can integrate this knowledge into its register allocator and find the least costly way to get i where you need it with the least amount of code, (Sometimes there is no extra code.)
The built-in gcc assembly is highly distorted and strange, but quite powerful. It is worth spending some time to fully understand the system of restrictions in order to make the best use of it.
(By the way, I donβt know the code 6811, but did you forget to put the result of the operation somewhere? I expect to see that stx matches stx .)
Update: Oh, I see what bset is doing bset --- it writes the result back to the memory location, right? It is still doable, but it is a little painful. You need to tell gcc that you are modifying this memory location so that it does not rely on any cached value. You will need to have an output parameter with a m constraint that represents this location. Check documents.