I have read in my book this sentence:
Logical and Shift Instructions Operate on bits individually Unlike arithmetic, which operate on entire word
Use to isolate fields. Either by masking or by shifting back and forth.
I can not understand these two sentences at all.
Both shift and arithmetic instructions would change all the bits (in some situation), and in arithmetic, bits are added one by one to calculate the answer.
So what is the meaning of this part "Instructions Operate on bits individually Unlike arithmetic, which operate on entire word"?
My second question:
I don't know have any idea about this part can you explain it to me:
Use to isolate fields. Either by masking or by shifting back and forth.
My third question: what is a logical instruction. Did he mean AND, OR for example? Can you explain more?
Logical and Shift operations are commonly called bitwise operations. They operate on bits individually which means that each output bit depends on just bit(s) from a single fixed bit position in the input(s) and you can calculate that bit immediately without depending on any other bits or previous calculation results
For example in AND, OR, XOR... output[n]
(i.e. bit n in the output) is calculated from input1[n]
and input2[n]
. Similarly left shift by N produces output[i]
from only input[i - N]
, and complementing (NOT) converts from input[n]
to output[n]
. I'm taking the sample images from here so that it's easier to understand
OTOH each bit in the addition result depends on the carry in and you must wait for the previous add operations to complete like this Sn = An + Bn + Cn
It's possible to do faster additions by pre-calculating the carry in with some logic like in the carry-lookahead adder, but it's still slower and needs a lot more die area than bitwise operations that have no dependants. Similarly other arithmetic operations also can't be done by getting each output bit individually.
That's for your first and third questions. Regarding the second one
Use to isolate fields Either by masking or by shifting back and forth.
means they're used to get bit fields by masking with AND (i.e. let only bits bits in that field fall through, by filtering out bits in positions where the mask is zero), or by shifting out to zero the bits and shift back to their original position
Further reading: