0

错误出现在“mov [esi], [edi]”行的 AfterLoop 范围内。我该如何解决这个问题?; 节点移除函数(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
4

2 回答 2

4

在大多数情况下,x86 指令最多可以使用一个内存操作数。对于内存-内存移动,请使用临时寄存器:

mov [reg1], [reg2] # illegal

mov tmp, [reg2] # ok
mov [reg1], tmp
于 2013-12-17T11:40:02.330 回答
3

mem, mem不是有效的操作数组合。使用寄存器作为中间体,例如:

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

或者,如果您可以交换esi并且edi可以使用movsd

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

(注意:+= 4假设方向标志是明确的,则为真。否则它将是-= 4。在你的情况下应该没关系,因为你pop esiedi之后立即)。

于 2013-12-17T11:41:16.573 回答