MIPS大会:如何否定登记册?

发布于 2025-02-03 05:23:40 字数 277 浏览 2 评论 0原文

”

在问题IV中。

我的第一个指令是否成功否定了登记册i?我的第二个指令能解决问题吗?

Screen-Shot-2022-05-29-at-2-14-09-PM.png

In question iv.

Does my first instruction successfully negate the register i? Does my second instruction complete the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦在深巷 2025-02-10 05:23:40

是的,有效!


在此说明序列中,不必要使用$ t2,因为第一个指令可以直接将结果直接放回$ t0中,因为$ t0无论如何都将要更新,在此之后您只需要-i,但不再需要i本身的原始值。

通常,减少用于这样的小型代码序列的寄存器数量是一件好事,因为在较大的上下文中,我们可以用光寄存器。


对我来说,这样做会更自然了:

li $t2, 1
sub $t0, $t2, $t0

当然,这确实需要第二张登记册(无法消除它),因此,在一个措施中,您的代码顺序(修改为使用$ t0仅修改)更最佳。

Yes, that works!


The use of $t2 is unnecessary in this instruction sequence, as the first instruction can simply put the result directly back in $t0, since $t0 is going to be updated anyway, and you need only -i after that point, but no longer need the original value of i itself.

Generally, it is good to reduce the number of registers used for small code sequences like this, since there are larger contexts in which we can run out of registers.


To me it would have been more natural to do:

li $t2, 1
sub $t0, $t2, $t0

Of course, that does require a 2nd register (no way to eliminate it), so to one measure, your code sequence (modified to use $t0 only) is more optimal.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文