I am working on quicksort in the x86 assembly, and I need to swap two elements of the array A [pivot] and A [j], but I can't even assign a value to the index of the array, not replace the elements.
An array is assigned as such:
A: .long 2,1,8,6,12
My initial exchange scheme did not work at all, so I reduced it to this in order to understand where my problem was. I tried many ways to get the right results, but all either result in the wrong value or segmentation error.
movl A(,%ebx,4), %eax
This snippet returns:
A[pivot] = 2 A[j] = -143535296
A [pivot] = A [0] = 2, so that's right, but A [j] = A [1] = 1
Is this the correct way to reference array elements when% ebx and% edi are two indexes of the array to view their contents or change their values.
I canโt understand what I'm doing wrong, any help would be appreciated.
edit: Also, if I use A (, [index], 4) as the printf argument, it displays the correct values.
edit1: I understand why my printf statements were incorrect, I changed the code and returned what seems to be the correct memory addresses. addr [A] = 134513652 and addr [A + 1] = 134513656. My original problem of changing array values โโstill exists, but I continue to get a segmentation error when doing this:
leal A(,%ebx,4), %ecx
source share