使用 DX:AX 装配 x86 划分
我正在使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如您正确地注意到的,您不能使用 32 位数字作为 16 位除法中的除数,但由于我们只对整数除法感兴趣,所以这不是问题。
有两种情况需要考虑(对于无符号除法):
DX == 0
:C*D
的结果适合 16 位,因此我们可以使用正常进行>ax
作为 16 位除数。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 ofC*D
fits in 16 bits so we can proceed as normal usingax
as the 16-bit divisor.DX > 0
(DX != 0
):C*D
is greater than 65335 (0xFFFF
) and the 16-bit unsigned division ofA
and that number will always be 0 and the remainder is simplyA
.Or you could do as C and just assume that the result of
C*D
fits in 16 bit. :)