ASM x86 整数溢出

Jam*_*hko 2 html x86 assembly

GetLCM PROC
tryAgain:
   mov bx, 0
   inc Multiple
   mov ax, UserInputNum1              ;Move UserInputNum1 to the 16 bit Register
   mov bx, Multiple
   div bx                             ;<-------Error here
   cmp dx,0                           ;If dx is not zero then there is a remainder
   jne tryAgain                       ;If not equal jump
ret
GetLCM ENDP
Run Code Online (Sandbox Code Playgroud)

尝试对这两个数字进行除法运算时,我不断收到整数溢出错误。当我尝试使用 div 时它会中断。

我试图找到用户输入的两个数字的最小公倍数。我决定尝试将每个数字除以首先找到质数,然后将每次找到的质数与用户输入的另一个数字进行比较。当然,我会同时做这两个数字,但到目前为止,我正试图克服这个错误。

这只是我在 ASM 的第五周,所以我有点困惑为什么会发生这种情况。另外我想补充一点,我也想让这项工作适用于 32 位数字。我的想法是使用指针。这是一个很好的方法吗?谢谢你的帮助!

Gun*_*ner 5

xor dx, dx 在你之前的某个地方 div