3 操作数 imul 指令在 ia-32 汇编中到底起什么作用?
我正在阅读说明
imul 0xffffffd4(%ebp, %ebx, 4), %eax
,但我对它的具体作用感到困惑。我知道 imul
相乘,但我无法弄清楚语法。
I'm reading the instruction
imul 0xffffffd4(%ebp, %ebx, 4), %eax
and I'm baffled by what it's doing exactly. I understand that imul
multiplies, but I can't figure out the syntax.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
(我知道并且更喜欢 Intel/MASM 语法,所以我将使用它。请注意,操作数的顺序在 AT&T 中是相反的。)
您的指令实际上是一个双操作数
imul
,在 Intel 中语法为:其中
eax
是目标操作数,内存位置是源操作数。双操作数imul
执行源操作数和目标操作数的乘法,并将结果存储在目标中。与 1 操作数不同,它不会在任何地方写入高半部分,因此相同的指令适用于有符号和无符号,例如add
和左移。该指令将寄存器乘以数组中的整数。这很可能出现在循环中,并且数组是局部变量(在从
ebp-44
开始的堆栈上)。三操作数
imul
指令是:source1
操作数(内存位置或寄存器)乘以立即数
操作数(可以是8 位或 16/32 位常量),结果存储在dest
操作数(16、32 或 64 位寄存器)中。请参阅 Intel 的
imul
手册条目:https://www.felixcloutier.com/ x86/imul(I know and prefer Intel/MASM syntax, so I will use that. Note that the order of operands is reversed in AT&T.)
Your instruction is actually a two-operand
imul
, which in Intel syntax is:Where
eax
is the destination operand and the memory location is the source operand. The two-operandimul
performs a multiplication of the source and destination operands and stores the result in the destination. Unlike 1-operand, it doesn't write a high half anywhere, so the same instruction works for signed and unsigned, like withadd
and left shift.This instruction is multiplying a register by the integer in an array. Most likely this appears in a loop and the array is a local variable (on the stack starting at
ebp-44
).The three-operand
imul
instruction is:The
source1
operand (either a memory location or a register) is multiplied by theimmediate
operand (either an 8-bit or 16/32-bit constant) and the result is stored in thedest
operand (a 16, 32 or 64-bit register).See Intel's manual entry for
imul
: https://www.felixcloutier.com/x86/imulAT&T 汇编基础/索引语法万岁!它根本不是 3 操作数乘法。这与您所熟悉和喜爱的 2 操作数相同,只是第一个操作数有点复杂。它的意思是:
或者:
更清楚一点(以 10 为基数)。 AT&T 基本/索引语法分解为:
Hooray for AT&T assembly base/index syntax! It's not a 3-operand multiply at all. It's the same 2-operand one you know and love, it's just that the first one is a bit complicated. It means:
Or:
To be a bit clearer (and in base 10). The AT&T base/index syntax breaks down as: