SAL/SAR vs SHR/SAR in assembly 8086
Because there's nothing to preserve in case of a left shift. In those cases that a left shift changes the sign (which you might have wanted to prevent somehow), the result without overflow would not fit in a register (this is automatically so - if it did fit, then it wouldn't have overflowed to begin with). So there's nothing you can do about it anyway.
But right shift can't overflow, it makes the number smaller (or it stays the same). So now you can choose, do I keep the top bit intact or not.
![Abrar](https://i.stack.imgur.com/wOLaH.jpg?s=256&g=1)
Comments
-
Abrar about 2 years
I am learning assembly language (specific to x86). I have understood that the
SAL
andSHL
works in similar way (clearing the lsb and carrying the msb to CF) from here Difference between SHL and SAL in 80x86.Considering that
SHR
andSAR
doesn't operate in similar way (the latter keeping the msb unchanged).I would like to have a clear concept about why the functionality of Shift Arithmetic Right
SAR
is defined different from Shift RightSHR
but at the same time theSHL
andSAL
are kept with similar functionality ?