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

l. read Data: This function is to read the input and store it into the array. No

ID: 3795607 • Letter: L

Question

l. read Data: This function is to read the input and store it into the array. Notice that there is one parameter (use Sa0 for this) and one return value (use $v0 for this). You may access the array using subscripts or pointers through the parameters but you must not access the global data directly. Also, you must use$s registers for the variables count and i (below). As these are saved registers, you must save these registers on the stack at the beginning of the function and restore them at the end. This function does not call another function. You do not have to error check on the value of count. int read Data (int list int count; cout How many values to read? cin count; for (int i 0; i count i cin list Iij //read into listli] return count 2. print: This function is to print the contents of the array. Notice that there are two parameters (Sa0 for the array address and Sal for the count). You may access the array elements using subscripts or pointers through the parameters but you must not access the global data directly. Use a temporary register for the variable i.This function does not call another function. void print (int array t], int count) for (int i 0; i K count i++) cout list tij 3. sort: The code below is for the bubble sort. This function must call the function swap correctly. Notice that there are two parameters ($a0 for the array address and Sal for the count). You may use access the array elements using subscripts or pointers through the parameters but you must not access the global data directly. Use temporary registers for the variables i and j. void sort (int list, int count) for (int i (count 1) i 0; i--) for (int j 1; j i: j++) if (list [j-1] list [j]) swap (list [j-l], list [j]) Specifics Do not use any pseudo-instructions.

Explanation / Answer

Answer 1. ReadData

.LC0:
   .string   "how many values to read? "
   .text
   .globl   _Z8readDataPi
   .type   _Z8readDataPi, @function
_Z8readDataPi:
.LFB1456:
   .cfi_startproc
   pushq   %rbp
   .cfi_def_cfa_offset 16
   .cfi_offset 6, -16
   movq   %rsp, %rbp
   .cfi_def_cfa_register 6
   subq   $32, %rsp
   movq   %rdi, -24(%rbp)
   movq   %fs:40, %rax
   movq   %rax, -8(%rbp)
   xorl   %eax, %eax
   leaq   .LC0(%rip), %rsi
   leaq   _ZSt4cout(%rip), %rdi
   call   _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
   leaq   -16(%rbp), %rax
   movq   %rax, %rsi
   leaq   _ZSt3cin(%rip), %rdi
   call   _ZNSirsERi@PLT
   movl   $0, -12(%rbp)
.L3:
   movl   -16(%rbp), %eax
   cmpl   %eax, -12(%rbp)
   jge   .L2
   movl   -12(%rbp), %eax
   cltq
   leaq   0(,%rax,4), %rdx
   movq   -24(%rbp), %rax
   addq   %rdx, %rax
   movq   %rax, %rsi
   leaq   _ZSt3cin(%rip), %rdi
   call   _ZNSirsERi@PLT
   addl   $1, -12(%rbp)
   jmp   .L3
.L2:
   movl   -16(%rbp), %eax
   movq   -8(%rbp), %rcx
   xorq   %fs:40, %rcx
   je   .L5
   call   __stack_chk_fail@PLT
.L5:
   leave
   .cfi_def_cfa 7, 8
   ret
   .cfi_endproc
.LFE1456:
   .size   _Z8readDataPi, .-_Z8readDataPi
   .globl   main
   .type   main, @function
main:
.LFB1457:
   .cfi_startproc
   pushq   %rbp
   .cfi_def_cfa_offset 16
   .cfi_offset 6, -16
   movq   %rsp, %rbp
   .cfi_def_cfa_register 6
   movl   $0, %eax
   popq   %rbp
   .cfi_def_cfa 7, 8
   ret
   .cfi_endproc
.LFE1457:
   .size   main, .-main
   .type   _Z41__static_initialization_and_destruction_0ii, @function
_Z41__static_initialization_and_destruction_0ii:
.LFB1896:
   .cfi_startproc
   pushq   %rbp
   .cfi_def_cfa_offset 16
   .cfi_offset 6, -16
   movq   %rsp, %rbp
   .cfi_def_cfa_register 6
   subq   $16, %rsp
   movl   %edi, -4(%rbp)
   movl   %esi, -8(%rbp)
   cmpl   $1, -4(%rbp)
   jne   .L10
   cmpl   $65535, -8(%rbp)
   jne   .L10
   leaq   _ZStL8__ioinit(%rip), %rdi
   call   _ZNSt8ios_base4InitC1Ev@PLT
   leaq   __dso_handle(%rip), %rdx
   leaq   _ZStL8__ioinit(%rip), %rsi
   movq   _ZNSt8ios_base4InitD1Ev@GOTPCREL(%rip), %rax
   movq   %rax, %rdi
   call   __cxa_atexit@PLT
.L10:
   nop
   leave
   .cfi_def_cfa 7, 8
   ret
   .cfi_endproc
.LFE1896:
   .size   _Z41__static_initialization_and_destruction_0ii, .-_Z41__static_initialization_and_destruction_0ii
   .type   _GLOBAL__sub_I__Z8readDataPi, @function
_GLOBAL__sub_I__Z8readDataPi:
.LFB1897:
   .cfi_startproc
   pushq   %rbp
   .cfi_def_cfa_offset 16
   .cfi_offset 6, -16
   movq   %rsp, %rbp
   .cfi_def_cfa_register 6
   movl   $65535, %esi
   movl   $1, %edi
   call   _Z41__static_initialization_and_destruction_0ii
   popq   %rbp
   .cfi_def_cfa 7, 8
   ret
   .cfi_endproc

2. print

.LC0:
   .string   " "
   .text
   .globl   _Z5printPii
   .type   _Z5printPii, @function
_Z5printPii:
.LFB1456:
   .cfi_startproc
   pushq   %rbp
   .cfi_def_cfa_offset 16
   .cfi_offset 6, -16
   movq   %rsp, %rbp
   .cfi_def_cfa_register 6
   subq   $32, %rsp
   movq   %rdi, -24(%rbp)
   movl   %esi, -28(%rbp)
   movl   $0, -4(%rbp)
.L3:
   movl   -4(%rbp), %eax
   cmpl   -28(%rbp), %eax
   jge   .L4
   movl   -4(%rbp), %eax
   cltq
   leaq   0(,%rax,4), %rdx
   movq   -24(%rbp), %rax
   addq   %rdx, %rax
   movl   (%rax), %eax
   movl   %eax, %esi
   leaq   _ZSt4cout(%rip), %rdi
   call   _ZNSolsEi@PLT
   leaq   .LC0(%rip), %rsi
   movq   %rax, %rdi
   call   _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
   addl   $1, -4(%rbp)
   jmp   .L3
.L4:
   nop
   leave
   .cfi_def_cfa 7, 8
   ret
   .cfi_endproc
.LFE1456:
   .size   _Z5printPii, .-_Z5printPii
   .globl   main
   .type   main, @function
main:
.LFB1457:
   .cfi_startproc
   pushq   %rbp
   .cfi_def_cfa_offset 16
   .cfi_offset 6, -16
   movq   %rsp, %rbp
   .cfi_def_cfa_register 6
   movl   $0, %eax
   popq   %rbp
   .cfi_def_cfa 7, 8
   ret
   .cfi_endproc
.LFE1457:
   .size   main, .-main
   .type   _Z41__static_initialization_and_destruction_0ii, @function
_Z41__static_initialization_and_destruction_0ii:
.LFB1896:
   .cfi_startproc
   pushq   %rbp
   .cfi_def_cfa_offset 16
   .cfi_offset 6, -16
   movq   %rsp, %rbp
   .cfi_def_cfa_register 6
   subq   $16, %rsp
   movl   %edi, -4(%rbp)
   movl   %esi, -8(%rbp)
   cmpl   $1, -4(%rbp)
   jne   .L9
   cmpl   $65535, -8(%rbp)
   jne   .L9
   leaq   _ZStL8__ioinit(%rip), %rdi
   call   _ZNSt8ios_base4InitC1Ev@PLT
   leaq   __dso_handle(%rip), %rdx
   leaq   _ZStL8__ioinit(%rip), %rsi
   movq   _ZNSt8ios_base4InitD1Ev@GOTPCREL(%rip), %rax
   movq   %rax, %rdi
   call   __cxa_atexit@PLT
.L9:
   nop
   leave
   .cfi_def_cfa 7, 8
   ret
   .cfi_endproc
.LFE1896:
   .size   _Z41__static_initialization_and_destruction_0ii, .-_Z41__static_initialization_and_destruction_0ii
   .type   _GLOBAL__sub_I__Z5printPii, @function
_GLOBAL__sub_I__Z5printPii:
.LFB1897:
   .cfi_startproc
   pushq   %rbp
   .cfi_def_cfa_offset 16
   .cfi_offset 6, -16
   movq   %rsp, %rbp
   .cfi_def_cfa_register 6
   movl   $65535, %esi
   movl   $1, %edi
   call   _Z41__static_initialization_and_destruction_0ii
   popq   %rbp
   .cfi_def_cfa 7, 8
   ret
   .cfi_endproc

3. sort

.LFB0:
   .cfi_startproc
   pushq   %rbp
   .cfi_def_cfa_offset 16
   .cfi_offset 6, -16
   movq   %rsp, %rbp
   .cfi_def_cfa_register 6
   movl   %edi, -4(%rbp)
   movl   %esi, -8(%rbp)
   nop
   popq   %rbp
   .cfi_def_cfa 7, 8
   ret
   .cfi_endproc
.LFE0:
   .size   _Z4swapii, .-_Z4swapii
   .globl   _Z4sortPii
   .type   _Z4sortPii, @function
_Z4sortPii:
.LFB1:
   .cfi_startproc
   pushq   %rbp
   .cfi_def_cfa_offset 16
   .cfi_offset 6, -16
   movq   %rsp, %rbp
   .cfi_def_cfa_register 6
   subq   $32, %rsp
   movq   %rdi, -24(%rbp)
   movl   %esi, -28(%rbp)
   movl   -28(%rbp), %eax
   subl   $1, %eax
   movl   %eax, -8(%rbp)
.L7:
   cmpl   $0, -8(%rbp)
   js   .L8
   movl   $1, -4(%rbp)
.L6:
   movl   -4(%rbp), %eax
   cmpl   -8(%rbp), %eax
   jg   .L4
   movl   -4(%rbp), %eax
   cltq
   salq   $2, %rax
   leaq   -4(%rax), %rdx
   movq   -24(%rbp), %rax
   addq   %rdx, %rax
   movl   (%rax), %edx
   movl   -4(%rbp), %eax
   cltq
   leaq   0(,%rax,4), %rcx
   movq   -24(%rbp), %rax
   addq   %rcx, %rax
   movl   (%rax), %eax
   cmpl   %eax, %edx
   jle   .L5
   movl   -4(%rbp), %eax
   cltq
   leaq   0(,%rax,4), %rdx
   movq   -24(%rbp), %rax
   addq   %rdx, %rax
   movl   (%rax), %edx
   movl   -4(%rbp), %eax
   cltq
   salq   $2, %rax
   leaq   -4(%rax), %rcx
   movq   -24(%rbp), %rax
   addq   %rcx, %rax
   movl   (%rax), %eax
   movl   %edx, %esi
   movl   %eax, %edi
   call   _Z4swapii
.L5:
   addl   $1, -4(%rbp)
   jmp   .L6
.L4:
   subl   $1, -8(%rbp)
   jmp   .L7
.L8:
   nop
   leave
   .cfi_def_cfa 7, 8
   ret
   .cfi_endproc
.LFE1:
   .size   _Z4sortPii, .-_Z4sortPii
   .globl   main
   .type   main, @function
main:
.LFB2:
   .cfi_startproc
   pushq   %rbp
   .cfi_def_cfa_offset 16
   .cfi_offset 6, -16
   movq   %rsp, %rbp
   .cfi_def_cfa_register 6
   movl   $0, %eax
   popq   %rbp
   .cfi_def_cfa 7, 8
   ret
   .cfi_endproc