简体   繁体   English

为什么下面用汇编语言显示的 V 标志设置为 1 而不是 0? 为什么会发生溢出?

[英]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.

相关问题 此汇编语言还如何检测签名溢出? - How does this assembly language detect signed overflow in addition? 汇编语言中的 NEG 指令是否设置溢出标志 - does NEG instruction in assembly language sets the Overflow flag 为什么在装配中出现“访问冲突读取位置”错误? - Why does “Access violation reading location” error occur in assembly? 为什么这个组件会产生24而不是4? - Why does this assembly yield 24 instead of 4? 为什么CMP(比较)有时会在8086汇编中设置进位标志? - Why does CMP (compare) sometimes sets a Carry Flag in 8086 assembly? 为什么除了GOT之外还存在PLT,而不仅仅是使用GOT? - Why does the PLT exist in addition to the GOT, instead of just using the GOT? 为什么在这个例子中没有设置溢出标志? - Why is the overflow flag not being set in this example? 为什么编译器优化在汇编语言中不显示循环? - Why compiler optimization does not show loop in the assembly language? 为什么这个汇编语言程序以相反的顺序打印十六进制数字? - Why does this assembly language program print hex digits in reverse order? 为什么objdump为这个汇编语言指令显示一个空操作码? - Why does objdump show a null opcode for this assembly language instruction?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM