Constructing Masks

If you need to set bits, use or

If you need to clear bits, use and

If you need to set some bits and clear others, use one of each

Here is a diagram showing a 32-bit value in $t0 with asterisks in the bits we need to set or clear: 2, 9, 13, 21

It also shows the binary masks we would need to do the setting or clearing

The general rule is to use dominant values against the bits we need to set or clear and recessive values against the bits we need to leave as they are

This general rule has two special cases: one for setting bits, and one for clearing bits

We need to be careful about the size of the mask

Summary