使用 DX:AX 装配 x86 划分

发布于 2024-12-13 09:24:05 字数 181 浏览 3 评论 0原文

我正在使用 masm,遇到了一个我不太明白如何解决的场景,例如:

X = (A)/(C*D)

如果我先乘以 C*D,我的值是 DX:AX,据我所知,我不能将其用作除数。如果我将 A/C 和 A/D 分开进行除法,我就会面临失去精度的风险(来自提醒等)。实现这一点的最佳方法是什么?

I'm working with masm and I've encountered a scenario I do not readily understand how to solve, for example:

X = (A)/(C*D)

If I multiple C*D first, my value is DX:AX and to my knowledge, I cannot use that as a divisor. If I do division separately as A/C and A/D, I run the risk of losing precision (from the reminders, etc.). What's the best way to implement this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤千羽 2024-12-20 09:24:05

正如您正确地注意到的,您不能使用 32 位数字作为 16 位除法中的除数,但由于我们只对整数除法感兴趣,所以这不是问题。

有两种情况需要考虑(对于无符号除法):

  • DX == 0C*D 的结果适合 16 位,因此我们可以使用 正常进行>ax 作为 16 位除数。
  • <代码>DX> 0 (DX != 0):C*D 大于 65335 (0xFFFF) 和 16 位无符号除法A 的数字始终为 0,余数就是 A

或者您可以像 C 那样执行,并假设 C*D 的结果适合 16 位。 :)

As you correctly note, you can't use a 32-bit number as the divisor in a 16-bit division, but since we're only interested in doing integer division that's not a problem.

There are two cases to consider (for unsigned division):

  • DX == 0: The result of C*D fits in 16 bits so we can proceed as normal using ax as the 16-bit divisor.
  • DX > 0 (DX != 0): C*D is greater than 65335 (0xFFFF) and the 16-bit unsigned division of A and that number will always be 0 and the remainder is simply A.

Or you could do as C and just assume that the result of C*D fits in 16 bit. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文