IDIV in assembly isn't giving me the wanted result (NASM)

試著忘記壹切 提交于 2019-12-25 07:26:42

问题


I'm trying to do a simple division:

mov ebx, 10
mov eax, 1111111111        ;(10 times)
mov edx, 0
idiv  bx

Supposedly I want to get the following results:

edx = 1

eax = 111111111 (9 times)

But the results I'm getting are:

edx = 7

eax = 1111098720

Does anyone know what the problem might be?

Thanks


回答1:


mov ebx, 10
mov eax, 1111111111        ;(10 times)
mov edx, 0
idiv  bx

What immediately strikes me is that you setup all registers for 32-bit operation but then perform a 16-bit division.
Changing it to the following will give the desired results:

mov  ebx, 10
mov  eax, 1111111111
cdq
idiv ebx


来源:https://stackoverflow.com/questions/37552056/idiv-in-assembly-isnt-giving-me-the-wanted-result-nasm

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