简体   繁体   English

汇编语言中的32位除法

[英]32 bit division in assembly language

I'm learning assembly language programming in my college course (80386 programming). 我正在大学课程(80386编程)中学习汇编语言编程。 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. 目前,我正在使用EDX和EAX寄存器分别存储余数和商来学习32位除法的来龙去脉。 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. 程序不运行或输出错误。

Relevant source code: 相关源代码:

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

I will post the full code if needed. 如果需要,我将发布完整代码。

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 . 当使用DIV与一个32位操作数,它将分在64位值EDX:EAX (高DWORD在EDX ,低DWORD在EAX由操作数),并把在商数EAX和在其余EDX

Therefore you should clear EDX prior to the division if the value you want to divide is 32 bits (fits in EAX alone). 因此,如果要除法的值是32位(仅适用于EAX ),则应在除法之前清除EDX Failure to do so will result in incorrect results, or a division overflow if the quotient doesn't fit in EAX . 否则将导致错误的结果,或者如果商不适合EAX则除法溢出。

32-bit div actually divides edx:eax by the specified value. 32位div实际上将edx:eax除以指定值。 If edx has random garbage in it, you'll get garbage results. 如果edx中包含随机垃圾,您将获得垃圾结果。 There's no option to divided JUST with eax... 没有选择用eax划分JUST ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM