Assembly x86 division with DX:AX

試著忘記壹切 提交于 2019-12-20 04:53:37

问题


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?


回答1:


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. :)



来源:https://stackoverflow.com/questions/7970290/assembly-x86-division-with-dxax

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!