Why clearing a bit is not an andi.
Clearing a flag is AND with the inverse mask. Going by the earlier AND lesson you'd bet on andi.. You'd lose. Watch MWCC clear bit 6, the 0x40 bit, of a value:
rlwinm r3,r3,0,26,24
blr
That's rlwinm, short for rotate-left-word-immediate-then-AND-with-mask. No andi. in sight, and the reason is the constant itself. The complement of a one-bit mask spans 32 bits, while andi. only holds a 16-bit immediate, nowhere near enough for the high half. So MWCC leans on rlwinm instead, rotating by 0 and masking off everything except the single bit it's clearing.
Decoding the mask is the fiddly part. PowerPC numbers bits from the MSB, so bit 0 is 0x80000000 and bit 31 is 0x1. That puts value bit 6 (0x40) at PPC bit
- The
[MB,ME] = [26,24] pair wraps around the end of the word, lighting up bits 26-31 and 0-24, everything but bit 25.
You'll meet this idiom constantly. The ~ is the trigger; it produces a 32-bit constant and that's what pulls in rlwinm. Drop in a bare literal like 0xFFFFFFBF and you'd clear bit 25 too, but it's the shape of the expression rather than its value that decides which instruction MWCC picks. The target uses other operands, so spot the bit being cleared, write it in C, and rlwinm shows up.
Your task
Write clear_flag so it compiles to the rlwinm above.