MIPS指令问题
MIPS 中的 subu
指令能否给出负结果,或者由于我们正在执行 sub 的无符号版本,因此结果始终为正? 另外,如果我想进行算术右移,并将 1 放在数字的第 0 个位置,我应该使用 sra 指令,还是有其他指令?
Can the subu
instruction in MIPS give me a negative result, or will the result always be positive since we are doing the unsigned version of the sub?
Also, if I want to do arithmetic shift right, and put 1 at the 0th position of the number, should I use the sra
instruction, or is there another instruction for it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
与所有机器指令一样,
subu
将为您提供二进制结果 - 存储在目标寄存器中的 32 位。这些位只是位,它们本身既不是积极的也不是消极的,这取决于你如何解释它们。如果将它们解释为有符号整数,则该整数可能是正数或负数。您可以将这些位视为浮点指针数字——这些位来自哪里是无关紧要的——尽管这可能是无意义的。请注意,
sub
和subu
之间的唯一区别是sub
将捕获溢出,将操作数视为有符号整数。subu
将产生完全相同的结果,但不会捕获。sra 向下(向右)移动位,仅保留最高位(如果将寄存器中的位视为有符号整数,则为符号位),并将其复制到任何较高位置被腾空
Like all machine instructions,
subu
will give you a binary result -- 32 bits that are stored in the destination register. These bits are just bits, they are neither positive or negative in and of themselves, it depends on how you interpret them. If you interpret them as a signed integer, the integer might be positive or negative. You could instead treat the bits as a floating pointer number -- where the bits came from is irrelevant -- though that may be non-sensical.Note that the ONLY difference between
sub
andsubu
is thatsub
will trap on overflow, treating the operands as signed integers.subu
will produce exactly the same result, but will not trap.sra
shifts bits down (to the right) leaving the uppermost bit (which is the sign bit, if you treat the bits in the register as a signed integer) alone, and copying it into any upper positions that are vacated