I am trying to swap 2 pointers in that are passed by reference to a sub-routine. Here is what I have:
.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
The point where I get confused is right after the swap_pointers: label. I can't figure out how to swap the 2 pointers. Any ideas on what I'm doing wrong?
See Question&Answers more detail:os