error A2070: invalid instruction operands

5.4k views Asked by At

the error is in AfterLoop skope in the line " mov [esi], [edi]" . how can I resolve this issue? ; The function for node removing (headptr, nodeToremove)

removeNode proc

headPtr = 8
nodeToRemove = headPtr + 4

push ebp
mov ebp, esp
push esi
push edi
push ebx

mov esi, headPtr[ebp]               ; esi = head of list
mov edi, [esi]                  ; edi = second item
cmp esi, nodeToRemove[ebp]              ; head = nodeToRemove?
jne NextNode

mov edi, esi                    ; edi ( = currNode) = head
mov esi, [esi]                  ; new head = head->next
jmp AfterLoop

NextNode:

cmp edi, nodeToRemove[ebp]                  ; currNode = node to remove?
je AfterLoop

mov esi, edi                    ; prev node = currNode
mov edi, [edi]                  ; currNode = currNode->next 
jmp NextNode            

AfterLoop:  

    mov [esi], [edi]            ; error!!! prev->next = curr->next
    pop ebx
    pop edi
    pop esi
    pop ebp
    ret 8
removeNode endp
2

There are 2 answers

0
Michael On BEST ANSWER

mem, mem is not a valid combination of operands. Use a register as an intermediate, e.g.:

mov eax,[edi]
mov [esi],eax

Alternatively, if you can swap esi and edi you could use movsd:

movsd        ; dword [edi] = dword [esi]; esi += 4; edi += 4

(Note: the += 4 is true assuming that the direction flag is clear. Otherwise it will be -= 4. Shouldn't matter in your case since you pop esi and edi immediatly afterwards).

0
gsg On

For the most part, x86 instructions may use at most one memory operand. For a memory-memory move, use a temporary register:

mov [reg1], [reg2] # illegal

mov tmp, [reg2] # ok
mov [reg1], tmp