谁能为我解释为什么在这些情况下余数的符号不同?这是模拟器错误还是真正的 CPU 也会这样做?
8 / -3 : quotient(AL) = -2 remainder(AH) = 2
-8 / 3 : quotient(AL) = -2 remainder(AH) = -2
最佳答案
它应该以这种方式工作,尽管通过阅读文档很难找到:
Non-integral results are truncated (chopped) towards 0.
结合“除法法则”X = dq + r(被除数是除数乘以商加上余数),我们发现因此余数r = X - d truncate(X/d)
这表明余数取决于被除数的符号,而不取决于除数的符号。
关于assembly - X86 余数的 IDIV 符号取决于 8/-3 和 -8/3 的被除数符号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53966486/