I don't understand the idea of mask and why it is useful here?
Asked
Active
Viewed 372 times
0

Reem Aljunaid
- 109
- 1
- 9
-
1In order to "select some bits, and clear others to 0". – Oliver Charlesworth Dec 24 '15 at 17:39
-
@OliverCharlesworth where is the mask here? is it the register $t1? – Reem Aljunaid Dec 24 '15 at 17:42
-
i don't understand how we do that .. should i choose the mask by myself? – Reem Aljunaid Dec 24 '15 at 17:44
1 Answers
1
Supposed you have a value and you want to set all bits to zero except for a few that you're interested in. So you create a mask which has only 1s in the positions you want to keep protected. When you use an AND
operation with your mask that's the result you get. It appears to me that $t1
is the value being used above as the mask.
You might be familiar with how a painter uses masking tape to cover an area that shouldn't be painted. It's the same kind idea.
There are basically three different operations where you'll mask bits this way: AND
to clear bits, OR
to set bits and XOR
to toggle bits.

shawnt00
- 16,443
- 3
- 17
- 22