[英]Why does the V flag shown in the addition in assembly language below is set to 1 instead of 0? Why does the overflow occur?
Here is a question on a practice quiz that I did but I do not understand why the V flag is 1.这是我做的一个练习测验的问题,但我不明白为什么 V 标志是 1。
$83 = –125 83 美元 = –125
$74 = 116 74 美元 = 116
–125 – 116 = –241, which doesn't fit in 8 bits. –125 – 116 = –241,这不适合 8 位。 (The range of an 8-bit signed number is –128 to +127.) Since the result doesn't fit, you get signed overflow, which sets the V bit.
(8 位有符号数的范围是 –128 到 +127。)由于结果不适合,您会出现有符号溢出,从而设置 V 位。
$83 - $74 = $83 + (-$74) = $83 + (~$74) + 1 $83 - $74 = $83 + (-$74) = $83 + (~$74) + 1
This is how the logic sees it.这就是逻辑看待它的方式。
1
10000011
+ 10001011
==============
finish结束
100000111
10000011
+ 10001011
==============
00001111
Two equivalent ways to determine the v flag if the carry in and the carry out of the msbit don't match then the v flag is set else not set.如果 msbit 的进位和进位不匹配,则确定 v 标志的两种等效方法,则设置 v 标志,否则不设置。 The other way is if the msbits of the operands (remember to invert and add one since this is addition in logic not subtraction) are the same and the result msbit is different than the two matching operands then it is an overflow otherwise if all three are the same or the two operand msbits differ then v = 0.
另一种方式是,如果操作数的 msbits(记住反转并加一个,因为这是逻辑中的加法而不是减法)相同并且结果 msbit 与两个匹配的操作数不同,那么它是溢出,否则如果所有三个都是相同或两个操作数 msbits 不同,则 v = 0。
This is the how, to understand the why see prl's answer, the answer does not fit in the number of bits available.这是如何理解为什么看到prl的答案,答案不适合可用位数。
The C flag is specific to architecture to do a subtract you invert the second operand and invert the carry in (make it a 1) on the way in, on the way out some architectures invert the carry out making it a borrow bit, others leave it as is. C 标志是特定于体系结构的,用于执行减法操作,您反转第二个操作数并反转进位(使其成为 1),在出路时某些体系结构反转进位使其成为借位,其他人离开照原样。 Often not documented, so you have to experiment to find out what the architecture does.
通常没有记录,因此您必须尝试找出架构的作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.