I would like to make sure I am understanding this concept 100% and if not get some clarification.
In an asm program, if you perform SHR 00110000b
you would end up with 00011000b
.
However, if you were to perform SHR
on 11111111b
you would end up with an incorrect answer and should use SAR
instead? This is because the number is signed?
if you perform SHR
00110000b you would end up with 00011000b
If you shifted one bit to the right, yes. You can specify the shift amount, so it's not fixed at 1.
However, if you were to perform SHR
on 11111111b you would end up with an incorrect answer
If you did a logical shift of 11111111b one bit to the right you'd get 01111111b. Whether you consider that to be incorrect or not depends entirely on what you're trying to achieve. If you wanted to preserve the sign you should've used SAR
.