汇编-进位标志VS溢出标志
我有下一个代码:
mov al, -5
add al, 132
add al, 1
当我检查它时,溢出标志和进位标志将在第一个操作中设置,而在第二个操作中,仅设置溢出。
但我不明白为什么:
- 在无符号数中,结果是143(8FH),因此适合8位无符号数(小于255)=>不应设置进位标志。在有符号数中,结果为127,适合8位有符号,不应设置溢出。
怎么了?谢谢。
I have the next code:
mov al, -5
add al, 132
add al, 1
As I check it, the overflow flag and the carry flag will set in the first operation, and in the second, only the overflow will set.
But I don't understand why:
- In unsigned number, the result is 143 (8FH), and for that is fit 8-bit unsigned number (is smaller than 255) => the carry flag shouldn't be set. In signed number, the result is 127, It's fit to 8-bit signed, and the overflow shouldn't be set.
Whats wrong? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当两个正数相加的结果为负数或
两个负数相加的结果是正数。
例如:
+127+1=?
当我们查看两个操作数的符号位和
结果发现发生了溢出,答案不正确。
Overflow occurs when the result of adding two positive numbers is negative or
the result of adding two negative numbers is positive.
For instance:
+127+1=?
As we look at the sign bits of the two operands and the sign bit of
the result, we find out that Overflow occurred and the answer is incorrect.
在无符号算术中,您将
0xFB
添加到0x84
,即251 + 132,它确实大于8位,因此设置了进位标志。在第二种情况下,您将+127 加到1,这确实超出了有符号的8 位范围,因此设置了溢出标志。
In unsigned arithmetic, you have added
0xFB
to0x84
, i.e. 251 + 132, which indeed is larger than 8-bit, and so the carry flag is set.In the second case, you are adding +127 to 1, which indeed exceeds a signed 8-bit range, and so the overflow flag is set.