32位除法汇编语言 [英] 32 bit division in assembly language

查看:1660
本文介绍了32位除法汇编语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在学习汇编语言编程在我的大学课程(80386编程)。目前,我正在学习用EDX和EAX 32位除法的来龙去脉寄存器分别存储剩余时间和智商。我想知道,为什么我不能当我不包括得到正确的输出

I'm learning assembly language programming in my college course (80386 programming). Currently, I'm learning the ins and outs of 32 bit division using the EDX and EAX registers to store the remainder and quotient respectively. I want to know, why do I not get the correct output when I don't include

mov edx, 00000000h

在我的计划。该方案要么不运行或给出错误的输出。

in my program. The program either doesn't run or gives the wrong output.

相关来源$ C ​​$ C:

Relevant source code:

mov edx, 00000000h
mov eax, 1234567Ah
div 11111111h ; now EDX=remainder, EAX=quotient

如果需要的话,我将发布完整的code。

I will post the full code if needed.

推荐答案

在使用 DIV 具有32位运算,这将分在64位值 EDX:EAX (在 EDX ,低DWORD在 EAX )由操作数,并把在 EAX 商和在 EDX 。

When using DIV with a 32-bit operand, it will divide the 64-bit value in EDX:EAX (high DWORD in EDX, low DWORD in EAX) by the operand and put the quotient in EAX and the remainder in EDX.

因此​​,你应该清楚 EDX 之前的分工,如果你想要分割的值是32位(适合于 EAX 单独)。如果不这样做,将导致不正确的结果,或者分区溢出如果商不适合在 EAX

Therefore you should clear EDX prior to the division if the value you want to divide is 32 bits (fits in EAX alone). Failure to do so will result in incorrect results, or a division overflow if the quotient doesn't fit in EAX.

这篇关于32位除法汇编语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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