本文介绍了imul汇编指令-一个操作数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用运行时调试器.

I am using a run-time debugger.

EAX:0000 0023EDX:5555 5556

EAX: 0000 0023EDX: 5555 5556

imul edx

EAX:aaa aac2EDX:0000 000b

EAX: aaaa aac2EDX: 0000 000b

我很困惑,无法弄清楚这种乘法是如何工作的.这里发生了什么事?我在类似的此处的问题中注意到,虽然我不理解EDX:EAX表示法://

I am utterly confused, and can't figure out how this multiply is working. What's happening here? I notice in a similar question here that imul ebx ; result in EDX:EAX I don't understand the EDX:EAX notation though :/

推荐答案

imul的单操作数形式传递了32位参数(如您在EDX中的情况)时,它实际上表示EAX * EDX其中EAXEDX都是32位寄存器.

When the one-operand form of imul is passed a 32 bit argument (as in your case with EDX) it effectively means EAX * EDX where both EAX and EDX are 32 bit registers.

两个32位值的乘积不一定适合32位:完整的乘法结果最多可以占用64位.答案的高32位将被写入EDX寄存器,低32位将被写入EAX寄存器;用EDX:EAX表示法.

The product of two 32 bit values doesn't necessarily fit in 32 bits: the full multiply result can take up to 64 bits. The high 32 bits of the answer will be written to the EDX register and the low 32 bits to the EAX register; this is represented with the EDX:EAX notation.

如果只需要结果的低32位,请使用imul的2操作数形式;否则,使用imul.它运行速度更快,并且没有任何隐式操作数(因此您可以使用最方便的任何寄存器).

If you only want the low 32 bits of the result, use the 2-operand form of imul; it runs faster and doesn't have any implicit operands (so you can use whatever registers are most convenient).

imul ecx, esi会像您期望的那样执行ecx *= esi,而无需触摸EAXEDX.就像C,其中unsigned x=...; x *= y;具有与输入相同的结果宽度.

imul ecx, esi does ecx *= esi like you'd expect, without touching EAX or EDX. It's like C where unsigned x=...; x *= y; has the same width for the result as the inputs.

imul也具有立即数形式:imul ecx, ebx, 1234执行ecx = ebx * 1234.许多汇编程序会接受imul ecx, 1234作为imul ecx, ecx, 1234的简写.

imul also has an immediate form: imul ecx, ebx, 1234 does ecx = ebx * 1234. Many assemblers will accept imul ecx, 1234 as short-hand for imul ecx, ecx, 1234.

这些32x32 => 32位形式的imul可以正确地用于有符号或无符号;单操作数mulimul的结果仅在上半部分(在EDX中)不同,而下半部分EAX的输出则没有.

These 32x32 => 32-bit forms of imul work correctly for signed or unsigned; the results of one-operand mul and imul only differ in the upper half (in EDX), not the low-half EAX output.

请参见 imul 的英特尔指令参考手册.

See Intel's instruction reference manual entry for imul.

这篇关于imul汇编指令-一个操作数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 11:35