繁体   English   中英

在x86汇编中减去两个64位数字的正确方法

[英]Proper way to subtract two 64 bit numbers in x86 assembly

我使用的是32位系统,并且在EDX:EAX中保存了64位数字。 我试图减去保存在ESI中的数字:EDI是否正确? 我很确定不是,因为经过3次迭代后结果不正确。

sub %esi, %edx          #Subtract two 64 bit numbers
sub %edi, %eax

您需要进行两项更改:

  1. 首先减去低阶32位,而不是高阶
  2. 如果将低阶32位相减产生borrow位,则需要从高阶位中再减去一个。 幸运的是,CPU会记住是否有借位(在carry flag CF中),并且有一条指令通过借位减SBB

这是最终代码

sub %edi, %eax          # Subtract low order 32-bits, borrow reflected in CF
sbb %esi, %edx          # Subtract high order 32-bits, and the borrow if there was one

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM