3 操作数 imul 指令在 ia-32 汇编中到底起什么作用?

发布于 2024-09-26 01:58:51 字数 134 浏览 4 评论 0原文

我正在阅读说明

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薄情伤 2024-10-03 01:58:51

(我知道并且更喜欢 Intel/MASM 语法,所以我将使用它。请注意,操作数的顺序在 AT&T 中是相反的。)

您的指令实际上是一个双操作数 imul,在 Intel 中语法为:

imul eax, DWORD PTR [ebp + ebx*4 + 0FFFFFFD4h]

其中eax 是目标操作数,内存位置是源操作数。双操作数 imul 执行源操作数和目标操作数的乘法,并将结果存储在目标中。与 1 操作数不同,它不会在任何地方写入高半部分,因此相同的指令适用于有符号和无符号,例如 add 和左移。

该指令将寄存器乘以数组中的整数。这很可能出现在循环中,并且数组是局部变量(在从 ebp-44 开始的堆栈上)。


三操作数 imul 指令是:

imul dest, source1, immediate
imul reg,  r/m,   imm           ; showing what kind of operand is allowed

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:

imul eax, DWORD PTR [ebp + ebx*4 + 0FFFFFFD4h]

Where eax is the destination operand and the memory location is the source operand. The two-operand imul 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 with add 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:

imul dest, source1, immediate
imul reg,  r/m,   imm           ; showing what kind of operand is allowed

The source1 operand (either a memory location or a register) is multiplied by the immediate operand (either an 8-bit or 16/32-bit constant) and the result is stored in the dest operand (a 16, 32 or 64-bit register).

See Intel's manual entry for imul: https://www.felixcloutier.com/x86/imul

云淡月浅 2024-10-03 01:58:51

AT&T 汇编基础/索引语法万岁!它根本不是 3 操作数乘法。这与您所熟悉和喜爱的 2 操作数相同,只是第一个操作数有点复杂。它的意思是:

%ebp + (4 * %ebx) + 0xffffffd4

或者:

%ebp + (4 * %ebx) - 44

更清楚一点(以 10 为基数)。 AT&T 基本/索引语法分解为:

offset(base, index, multiplier)

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:

%ebp + (4 * %ebx) + 0xffffffd4

Or:

%ebp + (4 * %ebx) - 44

To be a bit clearer (and in base 10). The AT&T base/index syntax breaks down as:

offset(base, index, multiplier)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文