Arm learning-Summary of bit operations and arm learning Summary
In the process of learning arm, the sensory register basically does not provide bitwise operations, but the overall operation,
The overall operation is to note that when assigning a value to a specific bit, it does not affect other places. It does not look simple,
In fact, the overall operation is skillful,
So let's summarize:
1. First, we must understand that the "|" symbol is used to set 1, and the "&" symbol is used to set 0.
2. Whether set to 1 or 0, the left side of "<" always appears in the form of 1. Set 0 and add the inverse symbol.
Combining the above two rules makes it easy:
For example, if we first write the 6th position 1 of a register (1 <6) to be used.
Then set 1 to use the "|" rule, so it is: reg | = (1 <6 );
What if the 6th position is 0:
In the same way, first write (1 <6) to be used.
If it is set to 0, "&" is used to add a rule that obtains the inverse symbol. So it is: reg & = ~ (1 <6 );
Now, it's hard to understand:
Reg & = ~ (1 <6) | (1 <7) | (1 <2 ));
What does this mean? When you see "& =", you will know that you want to set a position 0.
(1 <6) | (1 <7) | (1 <2) indicates that, 2, 6, and 7 are set to 1, and the reverse is displayed.
So the meaning of this sentence is to set 2, 6, and 7 to 0.
Let's return to the program:
If (dwDat & (1 <2 ))
What does this sentence mean?
It is to judge whether the second bits of swDat are 1, if the second bits are 1, the result is 1, and if is true.
This can be understood as a read operation ~