所以是的另一个家庭作业问题。但是我真的以为我这次钉了它..无论如何我得到了4个错误,对我来说似乎没有任何意义O_O或者也许这只是我的盲目眼光或我对代码的可怜借口但是是的。我收到了这些错误
mp5.s:70: error: invalid combination of opcode and operands
mp5.s:77: error: invalid combination of opcode and operands
mp5.s:83: error: invalid combination of opcode and operands
mp5.s:90: error: invalid combination of opcode and operands
此次赋值是使汇编代码进行矩阵乘法。我将粘贴我的代码并突出显示第70,77,83和90行
我可能会粘贴一大堆代码,但我需要知道的是为什么我会收到这些错误。它应该是同一类型,我不知道它为什么不起作用......
extern printf
segment .data
test1 db 'M','i','s','m','a','t','c','h',0
test2 db 'h','e','l','l','o','!',0
sout db "%s", 10, 0
segment .text
global matMul
matMul:
enter 12,0
mov eax, 0
mov [ebp-04], eax ;i=0
mov [ebp-08], eax ;j=0
mov [ebp-12], eax ;k=0
mov eax, [ebp+24]
mov ebx, [ebp+28]
cmp eax, ebx
je start
;; When The Matrices can't b multiplied It prints out "Mismatch" then exits
push test1
push sout
call printf
jmp done
;;; start with I loop
start:
iloop:
mov eax, [ebp-04]
mov ebx, [ebp+20]
cmp eax, ebx ;while i < xrow keep looping
je done
inc eax
mov [ebp-04], eax ;increments i++
jloop:
;; j loop starts here
mov eax, [ebp-8]
mov ebx, [ebp+32]
cmp eax, ebx ;while j < ycol keep looping
je resetJ
inc eax
mov eax, [ebp-08] ;increments j++
kloop:
;; k loop starts here
mov eax, [ebp-12]
mov ebx, [ebp+24]
cmp eax, ebx ;while k < xcol keep loopinbg
je resetK
;; operation starts
mov esi, [ebp+8] ;address of the matrix 1
mov edi, [ebp+12] ;address of matrix 2
mov eax, [ebp-04]
mov ebx, [ebp-12]
mov ecx, [ebp+24]
**mul ecx, eax ;xcol * i**
add ecx, ebx ;xcol * i + k
add esi, ecx ;esi + shift now esi have the location for x[col*i+k]
mov eax, [ebp-12]
mov ebx, [ebp-08]
mov ecx, [ebp+32]
**mul ecx, eax ;ycol * k**
add ecx, ebx ;ycol * k + j
add edi, ecx ;edi + shift now esi have the location for y[col*k + j]
mov edx, [esi] ;edx <- have the value we need
mov eax, [edi] ;eax <- have the 2nd value we need
**mul edx, eax ;x[xcol * i + k] * y[ycol * 1 + k] = edx**
mov esi, [ebp+16] ;esi now have the first location of the 3rd matrix
mov eax, [ebp-04]
mov ebx, [ebp-08]
mov ecx, [ebp+28]
**mul ecx, eax ;yrow * i**
add ecx, ebx ;yrow * i + j
add esi, ecx ;esi + shift now esi have the location for z[yrow * i + j]
mov eax, [esi] ;eax <- [esi]
add eax, edx ;z[yrow * i + j] + x[xcol * i + k] * y[ycol * k + j] = eax;
mov [esi], edx
;; operation end
mov eax, [ebp-12]
inc eax
mov eax, [ebp-12] ;increment k++
jmp kloop ;k loop
jmp jloop ;j loop
jmp iloop ;i loop back to start
resetJ:
mov eax, 0
mov [ebp-08], eax
jmp iloop
resetK:
mov eax, 0
mov [ebp-12], eax
jmp jloop
done:
leave
ret
testing:
push test2
push sout
call printf
jmp done
第70,77,83和90行是里面** **我不知道为什么,但我试图让它们粗体字体所以它是显而易见的:(我不知道它为什么不无论如何,这整个代码基本上都是我的C矩阵乘法程序的重写
我将在此处粘贴
void mm(int *x, int *y, int *z, int xrow, int xcol, int yrow, int ycol){
if(xcol == yrow){
int i,j,k;
for(i = 0; i < xrow; i++){
for(j = 0; j < ycol; j++){
for(k = 0; k < xcol; k++){
z[yrow * i + j] = z[yrow * i + j] + x[xcol * i + k] * y[ycol * k + j];
}
}
}
}
else{
printf("Size Mismatch. Can't Multiply.\n");
}
}
答案 0 :(得分:2)
MUL
,无符号乘法,具有以下形式(英特尔语法):
MUL r/m8
AX ← AL∗ r/m8
MUL r/m16
DX:AX ← AX ∗ r/m16
MUL r/m32
EDX:EAX ← EAX ∗ r/m32
MUL r/m64
RDX:RAX ← RAX ∗ r/m64
答案 1 :(得分:1)
我编码80x86汇编程序已经有一段时间了,但是MUL操作码不只占用一个操作数,而隐式使用累加器(EAX)作为术语之一,而EAX + EDX存储结果? (当然,当我在汇编时进行编码时,它只是普通的老式AX和DX:对我们来说,没有这些奇特的32或64位的东西!)