X86 IDIV余数的符号取决于8/-3和-8/3的分红符号? [英] X86 IDIV sign of remainder depends on sign of dividend for 8/-3 and -8/3?

查看:102
本文介绍了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:

非整数结果将被截断(切成零),变成0.

Non-integral results are truncated (chopped) towards 0.

结合除法" 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的分红符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆