为什么设置为小于 ALU 运算

发布于 2024-12-11 14:12:23 字数 425 浏览 0 评论 0原文

为什么slt被视为ALU运算?我认为它只会做一个减法,然后从 ALU 得到 *Z*ero 输出?

 ALU control lines |     Function
-------------------+-------------------
       0000        |       AND
       0001        |       OR
       0010        |       add
       0110        |     subtract
       0111        | set on less than

或者,如果 A - B(在 slt $t1, A, B 中)的结果为负,ALU 是否应该输出 1。

Why is slt considered an ALU operation? I thought it will just do a subtract then get the *Z*ero output from ALU?

 ALU control lines |     Function
-------------------+-------------------
       0000        |       AND
       0001        |       OR
       0010        |       add
       0110        |     subtract
       0111        | set on less than

Or is the ALU supposed to output 1 if the result of A - B (in slt $t1, A, B) is negative.

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

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

发布评论

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

评论(1

楠木可依 2024-12-18 14:12:23

如果 A 小于 b,则输出 1,否则输出 0。这通常需要计算 A - B,您需要 ALU。

现在,如果只是计算 A - B 的符号位,那将是多余的,但请考虑 A = -2147483648 = 0x80000000B = 1 的情况= 0x00000001,这里减法结果将是0x7fffffff = 2147483647,即使 A A A 也没有设置最高有效位。 B。

由于该表来自“Patterson, David A.; Hennessy, John L.:计算机组织与设计”,我将建议您参阅第 3 章,特别是涉及“加法和减法”的小节(第 2 版中的 3.3, 3.2 第 4 部分)。它有一个处理溢出/下溢的表,可以在其中查找极端情况。

另请记住,ALU 结果是 32 位,因此即使结果只是减法结果的符号位,它仍然需要不同的 ALU 操作代码来表示应返回与结果位连接的 31 个零,而不是完整的零。减法结果。

您可能指的是“零”线 - 在书中讨论的架构中 - IIRC 仅用于与分支相等/分支不相等相关的比较。手上的SLT/SLTI将其结果存储在寄存器中。

It's supposed to output 1 if A is less than b and 0 otherwise. This often entails calculating A - B, which you need the ALU for.

Now if it was just calculating the sign bit of A - B it would be redundant, but consider the case where A = -2147483648 = 0x80000000 and B = 1 = 0x00000001, here the subtraction result will be 0x7fffffff = 2147483647, which does not have the most significant bit set even though A < B.

As the table is from "Patterson, David A.; Hennessy, John L.: Computer Organization and Design" I'll refer you to chapter 3, specifically the subsection that deals with "addition and subtraction" (3.3 in the 2nd edition, 3.2 in the 4th). It has a table dealing with overflow/underflow where the corner cases can be looked up.

Also remember that the ALU result is 32 bits, so even if the result was just the sign bit of the subtraction result it would still need a different ALU operation code to signal that 31 zeros concatenated with the result bit should be returned rather than the full subtraction result.

The "Zero" line you're probably referring to is - in the architectures discussed in the book - IIRC only used for comparisons in relation to branch equal / branch not equal. SLT/SLTI on the hand stores its result in a register.

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