Using nasm with 32bit assembler code yields an unexpected result for my current attempts to write a loop which basically swaps elements of a vector. Given that ESI and EDI point to two different vectors (storing double values) and ECX the number n describing to swap the first n elements from [ESI] with the first n elements from [EDI] my attempts so far look like this:
; c-call: dswap(int n, double* dx, int unused1, double* dy, int unused2)
_dswap:
push ebp
mov ebp, esp
pusha
mov esi, [ebp+12] ; dx
mov edi, [ebp+20] ; dy
mov ecx, [ebp+8] ; n
; unused1 and unused2 obviously unused for the moment
mainLoop:
cmp ecx, 0
je exitFunction
mov eax, [esi + 4 * ecx]
mov ebx, [edi + 4 * ecx]
mov [esi + 4 * ecx], ebx
mov [edi + 4 * ecx], eax
dec ecx
jmp mainLoop
exitFunction:
popa
mov esp, ebp
pop ebp
ret
I am getting some unexpected behavior. Calling dswap on (1,2,3) with (4,5,6) and n=3 only swaps the first two elements in both vectors thus making me think what I did wrong here.