大会师的x86与DX:AX [英] Assembly x86 division with DX:AX
问题描述
我与MASM工作,我以前遇到过的情景,我不容易理解如何解决,例如:
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)
如果我多C *Ð第一,我的价值是DX:AX据我所知,我不能使用,作为除数。如果我做单独的司A / C和A / D,我冒丢失precision(从提醒等)的风险。什么是实现这个的最佳方式?
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?
推荐答案
当你正确地指出,你不能用一个32位的数字为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
:C *ð
的结果符合16位,所以我们可以继续正常使用斧
为16位除数。 -
DX&GT; (<!code> DX = 0
)0 :C *ð
大于65335(大于0xFFFF的
)和A
,这个数字将始终为0,其余的仅仅是A
。
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
.
或者你可以做C和只是假设, C的结果* D
16位相符。 :)
Or you could do as C and just assume that the result of C*D
fits in 16 bit. :)
这篇关于大会师的x86与DX:AX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!