mul和内存masd在寄存器edx :: eax中的分配 [英] mul and memory allocation in registers edx::eax with masm

查看:148
本文介绍了mul和内存masd在寄存器edx :: eax中的分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图理解在汇编程序中使用"mul"操作数的逻辑(我正在使用Visual Studio Community和MASM). 为什么在"mul ebx"之后结果也会改变edx,而不仅是eax? 结果(MUL)存储在寄存器AX,寄存器对DX:AX或寄存器对EDX:EAX(取决于操作数大小)中,乘积的高阶位包含在寄存器AH,DX或EDX". 那么位置取决于操作数的大小吗?在哪种情况下?

I am trying to understand the logic of using the "mul" operand in the assembler(i am using Visual Studio Community and MASM). Why, after "mul ebx" the result is changing also edx, and not only the eax? "The result(of MUL) is stored in register AX, register pair DX:AX, or register pair EDX:EAX (depending on the operand size), with the high-order bits of the product contained in register AH, DX, or EDX". So is the location depending on the size of the operand?In which case?

.586
.model flat,c
.stack 100h
.data

.code

 doit proc

        ;EAX = 0062EEF0 EBX = 7EFDE000 ECX = 0029FD00 EDX = 00000000     
     mov eax,8;
        ;EAX = 00000008
     mov ebx,4
        ;EBX = 00000004 
     mov edx,23498
        ;EDX = 00005BCA 
     mul ebx
        ;EAX = 00000020 EDX = 00000000 ????  4*8 =20(hexa).So, there is no 
                                       ;overflow;why is edx changing too?


 doit endp

end 

推荐答案

是的,正如您所说,它取决于操作数的大小,而不是操作数的实际值.您总是得到两倍大小的输出,是否溢出. mul ebx是32位,因此您在edx:eax中获得64位输出,其中edx可能为零.

Yes, as you said it depends on operand size which is not the actual value of the operand. You always get double size output, overflow or not. mul ebx is 32 bit, hence you get 64 bit output in edx:eax where edx may be zero.

正如Peter Cordes指出的那样,如果您知道不需要结果的上半部分,则可以并且应该使用IMUL的2或3数立即数形式".不要被符号所迷惑,引用指令集引用:无符号操作数也可以使用二操作数和三操作数形式,因为乘积的下半部分是相同的,无论操作数是否为签名或未签名."

As Peter Cordes pointed out, if you know you won't need the top half of the result, "you can and should use the 2-operand or 3-operand immediate form of IMUL". Don't be fooled by the signedness, to quote the instruction set reference: "The two- and three-operand forms may also be used with unsigned operands because the lower half of the product is the same regardless if the operands are signed or unsigned."

这篇关于mul和内存masd在寄存器edx :: eax中的分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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