溢出和进位标志
是否可以将两个带符号的 8 位数字相加并设置进位和溢出位?
Is it possible to add two signed 8-bit numbers together and set both the carry and overflow bits?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
是否可以将两个带符号的 8 位数字相加并设置进位和溢出位?
Is it possible to add two signed 8-bit numbers together and set both the carry and overflow bits?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
根据您的评论,您的问题似乎是“是否可以为涉及有符号数的二进制补码加法设置进位和溢出?”这是。典型的实现是将最后一个加法器的进位输入与链末尾的进位输出进行异或 - 因此,负数的溢出加法将导致设置进位位和要设置的溢出位。
这是一个例子,将-1添加到-128:
将设置进位,因为最后一次添加导致进位 - 并且将根据上面的规则设置溢出(另外,请注意,-128添加到-1显然不是127)
Per your comments, your question seems to be "is it possible to have both carry and overflow set for a two's complement add involving signed number?" It is. The typical implementation is to take the exclusive-OR of the carry-in for the last adder with the carry-out at the end of the chain -- hence, an overflowing addition of negative numbers will cause the carry-out bit to be set and the overflow bit to be set.
Here's an example, add -1 to -128:
Carry will be set, since the last add resulted in a carry -- and overflow will be set based on the rule above (also, note that -128 added to -1 is obviously not 127)
您无权访问 C 中的标志,即使您可以让编译器生成设置它们的代码,您也无法使用它们。
You don't have access to the flags in C, even if you could get the compiler to generate code that set them, you have have no way to use them.
您可以用 C 语言编写自己的加法例程,该例程将返回进位和溢出标志
有符号的 8 位操作数。如果您指的是内部的硬件进位和溢出位
处理器,不,这不能在 C 中移植。
You can write your own add routine in C that will return carry and overflow flags for
signed 8-bit operands. If you're referring to the hardware carry and overflow bits inside
the processor, no, that cannot be done portably in C.