为什么设置为小于 ALU 运算
为什么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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果 A 小于 b,则输出 1,否则输出 0。这通常需要计算 A - B,您需要 ALU。
现在,如果只是计算
A - B
的符号位,那将是多余的,但请考虑A = -2147483648 = 0x80000000
和B = 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 whereA = -2147483648 = 0x80000000
andB = 1 = 0x00000001
, here the subtraction result will be0x7fffffff = 2147483647
, which does not have the most significant bit set even thoughA < 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.