Bit-Shifting Operations
Last updated
Last updated
SHL/SAL -> Shift Left operation shifts the most significant bit to left one position.
In this operation, Carry Flag is used to store the shifted bit. And as we can see the LSB is auto-populated with 0.
SHR -> Shift Right
In this, LSB is shifted to carry flag and MSB is auto-populated with 0.
SAR-> Shift Arithmetic Right. This is very interesting. If the operand is positive, 0 is populated in the MSB but if it is negative, 1 is populated.
ROR-> Rotate Right. Some bits are rotated from LSB to MSB by a particular value.
Here is a demo:
Shift left by 0x20 (32 bits decimal)
SHL by 1 bit again. See CF is now 1 as 1 bit from ff is taken which becomes fe.
Continue and inspect this behavior.