SHR and SAR Commands

北城以北 提交于 2020-01-11 14:24:06

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/30644708/shr-and-sar-commands

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!