【发布时间】:2023-03-17 14:14:01
【问题描述】:
虽然我只使用 long 进行乘法,但不知道为什么operand size is wrong:
.type _square, @function
_square:
pushl %ebp
movl %esp, %ebp
subl $4, %esp #room for the local variable
movl 8(%ebp), %ecx #the first and only argument
movl $1, %eax
_finding_loop:
incl %eax
movl %eax, %ebx
imull %ebx, -4(%ebp) #storing the result in local var
cmpl -4(%ebp), %ecx #compare with the argument
je _found #epilogue and returning
jmp _finding_loop
【问题讨论】:
-
你的意思可能是 imull %ebx,存储结果需要额外的 movl
-
我不明白。第一个操作数应该是我想乘以 %eax 的内容(例如,我想乘以 %ecx 或 %ebx)——这是第一个操作数。我应该去哪里存储结果。如果我没有记错的话。那你到底是什么意思?
-
AT&T 语法颠倒了。第一个操作数是源,第二个操作数是目标。 Intel:“目标操作数是通用寄存器,源操作数是立即数、通用寄存器或内存位置”。您不能将内存 (
-4(%ebp)) 定义为目标。 -
没有目标是内存的 imul 指令——所以最后一个操作数(目标和第一个源)必须是寄存器。第一个操作数(第二个源)可以是寄存器或内存。
-
只有一个操作数felixcloutier.com/x86/imul时,imul的目的地只能是内存