Assembly Intel/NASM error (invalid Combination of opcode and operands)

Asked

Viewed 191 times

1

When assembling the code below, I am getting the error error: invalid combination of opcode and operands on lines 16, 26 and 28.

SECTION .data

maior: db 0


SECTION .text

global retorna_numeros

retorna_numeros:
    push ebp
    mov ebp, esp

    mov ebx, [ebp+12] ;ebx = L = 3
    mov esi, [ebp+8]  ;esi = matriz 3x3
    mov maior, [esi]  ;*** linha 16 ***

    mov ecx, 0 ;i = 0

loop:
    mov eax, ecx ;eax = i
    mul ebx ;3*i
    add eax, eax ;eax = 3*i+i

    lea edx, [esi + 4*eax]   ;carregando endereço do elemento atual da matriz em edx
    cmp maior, [edx]         ;*** linha 26 ***
    jae end_loop             ;se a variável 'maior' for maior ou igual que o elemento atual da matriz, pula para o final do loop
    mov maior, [edx]         ;*** linha 28 ***

end_loop:
    inc ecx
    cmp ecx, ebx
    jb loop

    mov eax, maior

end:
    mov esp, ebp
    pop ebp
    ret

Would anyone know why?

1 answer

2


You can’t do operations mov and cmp with both operands pointing to memory. Also, the destination address needs to be in brackets.

So, in short, you need to first move the contents of the memory to a logger and then the logger to memory.

; ...
mov eax, [esi]
mov [maior], eax
; ...

The same thing needs to be done for the operator cmp.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.