I have this piece of code:

unsigned char var;

void foo() { var |= 4; }

and want to have a bset generated. How can I do that?

The compiler can generate bset instructions if you pass it the -mrelax option. In that case you must pass -mrelax for compiling and for linking. The instructions are then optimized during the link, if it turns out that the global variable is in page0.

Try compiling:

unsigned char __attribute__((section ("page0"))) var;

int main() { var |= 4; return 0; }

with -Os -mshort -fomit-frame-pointer -mrelax And do the m6811-elf-objdump -d on the final executable. You'll see that the global var is set using bset.

See Also

How do I tell the compiler to use direct addressing mode to access data