错误在AfterLoop skope中的行“mov [esi],[edi]”中。我该如何解决这个问题? ;节点删除功能(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
答案 0 :(得分:3)
在大多数情况下,x86指令最多可以使用一个内存操作数。对于内存内存移动,请使用临时寄存器:
mov [reg1], [reg2] # illegal
mov tmp, [reg2] # ok
mov [reg1], tmp
答案 1 :(得分:3)
mem, mem
不是操作数的有效组合。使用寄存器作为中间符,例如:
mov eax,[edi]
mov [esi],eax
或者,如果您可以交换esi
和edi
,则可以使用movsd
:
movsd ; dword [edi] = dword [esi]; esi += 4; edi += 4
(注意:假设方向标志是明确的,+= 4
为真。否则它将是-= 4
。因为你pop
{{1}因此在你的情况下无关紧要然后立即esi
。