组装中的IDIV并没有给我想要的结果(NASM) [英] IDIV in assembly isn't giving me the wanted result (NASM)

查看:68
本文介绍了组装中的IDIV并没有给我想要的结果(NASM)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试进行简单的划分:

I'm trying to do a simple division:

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

我想得到以下结果:

edx = 1

eax = 111111111(9次)

eax = 111111111 (9 times)

但是我得到的结果是:

edx = 7

eax = 1111098720

eax = 1111098720

有人知道这个问题可能是什么吗?

Does anyone know what the problem might be?

谢谢

推荐答案

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

我立即想到的是,您为 32 位操作设置了所有寄存器,然后执行了 16 位除法.
将其更改为以下内容将得到所需的结果:

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

这篇关于组装中的IDIV并没有给我想要的结果(NASM)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆