Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

// C code to be converted to x86 assembly int j; int iMin; int temp; // advance

ID: 643910 • Letter: #

Question

// C code to be converted to x86 assembly

   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 < arraySize-1; j++) {

       // find the index of min element in the unsorted a[j .. n-1] //
        iMin = find_min_index (arrayOfIntegers, j, arraySize);

       if(iMin != j) {
           temp = arrayOfIntegers[iMin];
           arrayOfIntegers[iMin] = arrayOfIntegers [j];
           arrayOfIntegers   [j] = temp;  
       }
   }

Explanation / Answer

.Ltext0:

                                    .comm j,4,4

                                    .comm iMin,4,4

                                    .comm temp,4,4

                        .Letext0:

0019 C745F801                      movl    $1, -8(%rbp)

     000000

0020 E9920000                       jmp      .L3

     00

                        .L5:

0025 8B45F8                          movl    -8(%rbp), %eax

0028 4898                   cltq

002a 48C1E002                      salq      $2, %rax

002e 488D50FC                     leaq      -4(%rax), %rdx

0032 488B45E8                      movq   -24(%rbp), %rax

0036 4801D0                          addq    %rdx, %rax

0039 8B10                  movl    (%rax), %edx

003b 8B45F8                          movl    -8(%rbp), %eax

003e 4898                   cltq

0040 488D0C85                     leaq      0(,%rax,4), %rcx

     00000000

0048 488B45E8                      movq   -24(%rbp), %rax

004c 4801C8                           addq    %rcx, %rax

004f 8B00                   movl    (%rax), %eax

0051 39C2                  cmpl    %eax, %edx

0053 7E5E                  jle        .L4

                        .L5:

0025 8B45F8                          movl    -8(%rbp), %eax

0028 4898                   cltq

002a 48C1E002                      salq      $2, %rax

002e 488D50FC                     leaq      -4(%rax), %rdx

0032 488B45E8                      movq   -24(%rbp), %rax

0036 4801D0                          addq    %rdx, %rax

0039 8B10                  movl    (%rax), %edx

003b 8B45F8                          movl    -8(%rbp), %eax

003e 4898                   cltq

0040 488D0C85                     leaq      0(,%rax,4), %rcx

     00000000

0048 488B45E8                      movq   -24(%rbp), %rax

004c 4801C8                           addq    %rcx, %rax

004f 8B00                   movl    (%rax), %eax

0051 39C2                  cmpl    %eax, %edx

0053 7E5E                  jle        .L4

                        .L5:

0025 8B45F8                          movl    -8(%rbp), %eax

0028 4898                   cltq

002a 48C1E002                      salq      $2, %rax

002e 488D50FC                     leaq      -4(%rax), %rdx

0032 488B45E8                      movq   -24(%rbp), %rax

0036 4801D0                          addq    %rdx, %rax

0039 8B10                  movl    (%rax), %edx

003b 8B45F8                          movl    -8(%rbp), %eax

003e 4898                   cltq

0040 488D0C85                     leaq      0(,%rax,4), %rcx

     00000000

0048 488B45E8                      movq   -24(%rbp), %rax

004c 4801C8                           addq    %rcx, %rax

004f 8B00                   movl    (%rax), %eax

0051 39C2                  cmpl    %eax, %edx

0053 7E5E                  jle        .L4

                        .L5:

0025 8B45F8                          movl    -8(%rbp), %eax

0028 4898                   cltq

002a 48C1E002                      salq      $2, %rax

002e 488D50FC                     leaq      -4(%rax), %rdx

0032 488B45E8                      movq   -24(%rbp), %rax

0036 4801D0                          addq    %rdx, %rax

0039 8B10                  movl    (%rax), %edx

003b 8B45F8                          movl    -8(%rbp), %eax

003e 4898                   cltq

0040 488D0C85                     leaq      0(,%rax,4), %rcx

     00000000

0048 488B45E8                      movq   -24(%rbp), %rax

004c 4801C8                           addq    %rcx, %rax

004f 8B00                   movl    (%rax), %eax

0051 39C2                  cmpl    %eax, %edx

0053 7E5E                  jle        .L4

.L4:

00b3 8345F801                       addl     $1, -8(%rbp)

                        .L3:

00c3 836DF401                      subl      $1, -12(%rbp)

00b7 8B45F8                          movl    -8(%rbp), %eax

00ba 3B45F4                          cmpl    -12(%rbp), %eax

00bd 0F8E62FF                      jle        .L5

     FFFF

                        .L2:

00c7 837DF400                      cmpl    $0, -12(%rbp)

00cb 0F8F48FF                      jg         .L6

     FFFF

00d1 5D                      popq    %rbp

                                    .cfi_def_cfa 7, 8

00d2 C3                      ret

                                    .cfi_endproc

                        .LFE0:

                        .Letext0: