0

我正在尝试交换通过引用传递给子例程的 2 个指针。这是我所拥有的:

.data
    firstInputPrompt                BYTE 'Enter First String: ',0
    secondInputPrompt               BYTE 'Enter Second String: ',0

    firstString                     BYTE 16 DUP(0)              ;string buffers
    secondString                    BYTE 16 DUP(0)

    firstPointer                    DWORD OFFSET firstString    ;pointers
    secondPointer                   DWORD OFFSET secondString

.code

compare PROC

    push        ebp                 ;readying stack for use
    mov         ebp, esp

    push        eax                 ;used for comparing chars
    push        ebx                 
    push        ecx                 

    mov         ebx, [ebp+12]       ;ebx now a pointer to firstString
    mov         ecx, [ebp+8]        ;ecx now a pointer to secondString
    mov         ebx, [ebx]
    mov         ecx, [ecx]


;iterate over strings
iterate:    
    mov         al, [ebx]           ;compare characters
    cmp         al, [ecx]
    ja          swap_pointers
    jb          end_method

    mov         al, [ebx]
    cmp         al, 0
    je          end_method
    mov         al, [ecx]
    cmp         al, 0
    je          end_method  

    inc         ebx
    inc         ecx 

    jmp         iterate

swap_pointers:
    ;mov            ecx, [ebp+12]       ;get pointers again
    ;mov            ebx, [ebp+8]


    lea         ebx, dword ptr [ebp+12]
    lea         ecx, dword ptr [ebp+8]



end_method:
    ;pop used registers
    pop         ecx
    pop         ebx
    pop         eax
    pop         ebp
    ret
compare ENDP

我感到困惑的地方就在 swap_pointers: 标签之后。我不知道如何交换两个指针。关于我做错了什么的任何想法?

4

2 回答 2

2
...
;load registers with pointers 
mov ebx, firstPointer
mov ecx, secondPointer
;save pointers from register, swapping content
mov firstPointer, ecx
mov secondPointer, ebx
;finis
于 2013-06-11T01:59:51.830 回答
-2

xor 在需要时交换寄存器值

 load registers with pointers 
 mov ebx, firstPointer
 mov ecx, secondPointer

 xor ebx,ecx
 xor ecx ebx
 xor ebx,ecx

于 2013-06-11T09:49:51.590 回答