Shift Operations
Shifting the contents of a word or byte left or right can also
be a useful operation. With binary numbers, left shifts are the
the same as multiplying by two for each position shifted left.
Likewise, shifting right is like dividing by two (assuming it
is an unsigned integer!)
The simplest type of shift instruction is to shift zeroes into the
vacated positions and to throw away the bits shifted out the other
end. This is called a logical shift. The instructions are:
shl
shr
The last bit shifted out is stored in the Carry Flag so that it
can be tested. The form is:
shl/shr mem/reg, count
The is also a arithmetic shift, where the only difference
is during a right shift, inside of the high order bit becoming a
zero, it keeps the value that it had, which is useful with signed
integers.
The last shifts are called rotates.
CSEE |
211 |
Current |
lectures |
news |
help