I would like to ask for help!
The c code is
void bubble_sort(int a[], int n) {
int i = 0, j = 0, tmp;
for (i = 0; i < n; i++) {
for (j = 0; j < n - i - 1; j++)
if (a[j] > a[j + 1]) {
tmp = a[j];
a[j] = a[j + 1];
a[j + 1] = tmp;
}
}
}
}
My Assembly code so far from the main part is :
main:
push ebp //func prologue
mov ebp, esp
mov esi, [ebp + 8] // array address
mov edi, [ebp + 12] //array length
mov eax, 0 //i
mov ecx, 0 //j
outerloop:
inc eax // i++
cmp eax, edi // comparing i with length
jge end
insideloop:
mov edx, edi
sub edx, eax
dec edx
inc ecx
cmp ecx, edx
je outerloop
comparison:
I'm lost at this comparison part, I've been doing research the past day about how would I do it, but I simply don't get how would I do this part:
if (a[j] > a[j + 1]) {
tmp = a[j];
I'm really confused as to how I move my j value into the array, then check if everytime a[j] is higher than a[j +1], and then move a[j] into tmp, any help or tips are appreciated, thanks!