本文介绍了X86 IDIV余数的符号取决于8/-3和-8/3的分红符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人能为我解释为什么在这些情况下其余符号不同吗?这是模拟器错误还是真正的CPU也这样做?
Can anyone explain for me why the sign of the remainder is different in these cases? Is this an emulator bug or do real CPUs do this, too?
8 / -3 : quotient(AL) = -2 remainder(AH) = 2
-8 / 3 : quotient(AL) = -2 remainder(AH) = -2
推荐答案
它应该可以那样工作,尽管通过阅读文档来找出它很麻烦:
It is supposed to work that way, though it is tricky to find out by reading the documentation:
结合除法" X = dq + r(被除数是除数乘以商除以余数),我们发现余数r = X-d truncate(X/d)
Combined with the "division law" X = dq + r (the dividend is the divisor times the quotient plus the remainder), we find that therefore the remainder r = X - d truncate(X / d)
这表明余数取决于分红的符号,而不取决于除数的符号.
This shows that the remainder depends on the sign of the dividend, but not on the sign of the divisor.
这篇关于X86 IDIV余数的符号取决于8/-3和-8/3的分红符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!