x86体系结构是否以特殊方式处理零/与零比较的二进制减法?

在再次处理x86程序集时,我遇到了一种情况,在这种情况下,我试图了解如何解释cpu的行为。

使用cmp命令比较两个无符号整数时,进位和零标志的状态反映了两个整数的关系。因为cmp的行为类似于sub命令,而没有将减法的结果写入最终寄存器,所以进位标志将成为借位标志的一部分。此外,减法只不过是求反值的加法。因此,CPU不会减去1,而是加上-1。

现在,当被减数小于减数时,cmp期间的加法将不会导致进位,但由于需要借位,因此必须设置进位标志。因此,您可以说进位标记必须在加法之后反转才能得到正确的状态。
前一个假设适用于无符号整数的每种组合,但有一个例外:

从任何无符号整数中减去零与对其加零相同,这不会产生进位。因此,反向进位会导致设置进位标志,该标志是不正确的,因为被减数(

我用一个小的汇编程序检查了此行为,当然,CPU不会产生置位进位标志。但这只有在CPU还检查subtrahend为零(并且minuend不为零,minuend = subtrahend->设置为零标志)的情况下才有可能。

我对我的假设是正确的还是我缺少什么?

shi443213174 回答:x86体系结构是否以特殊方式处理零/与零比较的二进制减法?

您的直觉几乎是正确的。这是丢失的位:可以通过对减数,进位进位(<!--Each individual box.--> <div class="box"> <!--The box inside each individual box. Think of it as like bubble wrap inside a box.--> <div class="inside-box" onMouseOver="showDDContent();" onMouseOut="hideDDContent();"> <!--The div with an image in it. Top one inside the box div.--> <div> <a href="Lab_01/LB1_WeiJianZhen_DD.html"> <!--Get an image with 300px width by 200px height. Make it responsive.--> <img src="../../../Visual Content/placeholder.jpg" alt="Under Contruction" class="imgGrids"> </a> </div> <!--The div that contains the heading or title of the lab.--> <div class="txtBar"> <h3><a href="Lab_01/LB1_WeiJianZhen_DD.html">Lab 1</a></h3> </div> <!--The div that drops down to explain the lab with some text.--> <div class="dropdown-content"> <p>My first website ever made in an HTML file! Describes a bit about the process of making a very basic website like mine.</p> </div> <!--End of inside box div.--> </div> <!--End of box div.--> </div> <!--Lab 2--> <!--Each individual box.--> <div class="box"> <!--The box inside each individual box. Think of it as like bubble wrap inside a box.--> <div class="inside-box" onMouseOver="showDDContent();" onMouseOut="hideDDContent();"> <!--The div with an image in it. Top one inside the box div.--> <div> <a href="Lab_02/LB2_WeiJianZhen_DD.html"> <img src="../../../Visual Content/placeholder.jpg" alt="Under Contruction" class="imgGrids"> </a> </div> <!--The div that contains the heading or title of the lab.--> <div class="txtBar"> <h3><a href="Lab_02/LB2_WeiJianZhen_DD.html">Lab 2</a></h3> </div> <!--The div that drops down to explain the lab with some text.--> <div class="dropdown-content"> <p> This webpage describes a bit about myself and my aspirations about programming/web designer. Has an image of me too. </p> </div> <!--End of inside box div.--> </div> <!--End of box div.--> </div>的0,变为1)和输出进位进行补码来实现减法。当您从某个数字中减去0时,所加的是sub(假设是32位CPU)和一个反向的进位中的1。因此,我们实际上添加了0xffffffff,设置了支出结转(即清除支出借入)。这与您的模型的不同之处在于,该模型将添加0,而不是设置传出进位(即设置传出借位),

本文链接:https://www.f2er.com/3169820.html

大家都在问