I am learning assembly language (specific to x86). I have understood that the
SAL
and SHL
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
and SAR
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 Right SHR
but at the same time the SHL
and SAL
are kept with similar functionality ?
SHL
andSAL
is actually a single instruction with two names. – CarpiJE
andJZ
. – Tandemshr
would be a perfectly valid C implementation. Sincesar
exists, it makes more sense to use it. It's possible to make a standards-conforming C implementation that is extremely unfriendly to use and violates many assumptions made in a lot of code. – Fleischer