what is the translation for this from C to 8086 assembly language with inte nota
ID: 3676638 • Letter: W
Question
what is the translation for this from C to 8086 assembly language with inte notation?
int findMinIndex (int integer_array[], int i, int j)
{
int iMin = i;
// test against elements after i and before j to find the smallest
for ( i ; i < j; i++) {
// if this element is less, then it is the new minimum
if (integer_array[i] < integer_array[iMin]) {
// found new minimum; remember its index
iMin = i;
}
}
return iMin;
}
void selectionSort (int integer_array[], int array_size)
{
int j;
int iMin;
int temp;
// advance the position through the entire array //
// (could do j < n-1 because single element is also min element) //
for (j = 0; j < array_size-1; j++) {
// find the index of min element in the unsorted a[j .. n-1] //
iMin = findMinIndex (integer_array, j, array_size);
if(iMin != j) { // swap values
temp = integer_array[iMin];
integer_array[iMin] = integer_array [j];
integer_array[j] = temp;
}
}
}
Explanation / Answer
findMinIndex(int*, int, int):
cmpl %edx, %esi
jge .L5
movslq %esi, %rax
leaq (%rdi,%rax,4), %rcx
movl %esi, %eax
.L4:
movslq %eax, %r8
movl (%rdi,%r8,4), %r9d
cmpl %r9d, (%rcx)
cmovl %esi, %eax
addl $1, %esi
addq $4, %rcx
cmpl %esi, %edx
jne .L4
rep ret
.L5:
movl %esi, %eax
ret
selectionSort(int*, int):
cmpl $1, %esi
jle .L8
leal -1(%rsi), %r11d
movq %rdi, %r10
xorl %r9d, %r9d
.L14:
cmpl %r9d, %esi
jle .L10
movq %r10, %rcx
movl %r9d, %edx
movl %r9d, %eax
.L12:
movslq %edx, %r8
movl (%rdi,%r8,4), %r8d
cmpl %r8d, (%rcx)
cmovl %eax, %edx
addl $1, %eax
addq $4, %rcx
cmpl %eax, %esi
jne .L12
cmpl %edx, %r9d
je .L10
movslq %edx, %rdx
movl (%r10), %ecx
leaq (%rdi,%rdx,4), %rax
movl (%rax), %edx
movl %ecx, (%rax)
movl %edx, (%r10)
.L10:
addl $1, %r9d
addq $4, %r10
cmpl %r11d, %r9d
jne .L14
.L8:
rep ret
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.