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

Implement in ARM assembly language for sorting with a linkedlist. In the main fu

ID: 3827004 • Letter: I

Question

Implement in ARM assembly language for sorting with a linkedlist. In the main function, open a file to read a sequence of unsorted integers. For the first input integer, create a root node (8 bytes), holding the integer and one empty pointer. For each of the following input integers, build a link (call it X) containing the number and insert it to the linked list such that for any link with smaller integer should go before X and any link with integer of bigger or equal value should go after X. After all integers are inserted, the program would traverse the linked list and print out the sorted integers separated by space onto the screen. Specification: you should write Insert as a recursive function.

Explanation / Answer

CODE:.

LFB2:
   .cfi_startproc
   pushq   %rbp
   .cfi_def_cfa_offset 16
   .cfi_offset 6, -16
   movq   %rsp, %rbp
   .cfi_def_cfa_register 6
   subq   $112, %rsp
   movq   %fs:40, %rax
   movq   %rax, -8(%rbp)
   xorl   %eax, %eax
   movl   $.LC0, %esi
   movl   $.LC1, %edi
   call   fopen
   movq   %rax, -88(%rbp)
   movl   $0, -100(%rbp)
   jmp   .L2
.L3:
   leaq   -80(%rbp), %rax
   movl   -100(%rbp), %edx
   movslq   %edx, %rdx
   salq   $2, %rdx
   addq   %rax, %rdx
   movq   -88(%rbp), %rax
   movl   $.LC2, %esi
   movq   %rax, %rdi
   movl   $0, %eax
   call   __isoc99_fscanf
   addl   $1, -100(%rbp)
.L2:
   cmpl   $15, -100(%rbp)
   jle   .L3
   movq   $0, -96(%rbp)
   movl   $0, -100(%rbp)
   jmp   .L4
.L5:
   movl   -100(%rbp), %eax
   cltq
   movl   -80(%rbp,%rax,4), %edx
   leaq   -96(%rbp), %rax
   movl   %edx, %esi
   movq   %rax, %rdi
   call   Insertbegin
   addl   $1, -100(%rbp)
.L4:
   cmpl   $5, -100(%rbp)
   jle   .L5
   movl   $.LC3, %edi
   movl   $0, %eax
   call   printf
   movq   -96(%rbp), %rax
   movq   %rax, %rdi
   call   PrintLinkedList
   movq   -96(%rbp), %rax
   movq   %rax, %rdi
   call   BUbble_Sort_linkedlist
   movl   $.LC4, %edi
   movl   $0, %eax
   call   printf
   movq   -96(%rbp), %rax
   movq   %rax, %rdi
   call   PrintLinkedList
   call   getchar
   movl   $0, %eax
   movq   -8(%rbp), %rcx
   xorq   %fs:40, %rcx
   je   .L7
   call   __stack_chk_fail
.L7:
   leave
   .cfi_def_cfa 7, 8
   ret
   .cfi_endproc
.LFE2:
   .size   main, .-main
   .globl   Insertbegin
   .type   Insertbegin, @function
Insertbegin:
.LFB3:
   .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   $16, %edi
   call   malloc
   movq   %rax, -8(%rbp)
   movq   -8(%rbp), %rax
   movl   -28(%rbp), %edx
   movl   %edx, (%rax)
   movq   -24(%rbp), %rax
   movq   (%rax), %rdx
   movq   -8(%rbp), %rax
   movq   %rdx, 8(%rax)
   movq   -24(%rbp), %rax
   movq   -8(%rbp), %rdx
   movq   %rdx, (%rax)
   leave
   .cfi_def_cfa 7, 8
   ret
   .cfi_endproc
.LFE3:
   .size   Insertbegin, .-Insertbegin
   .section   .rodata
.LC5:
   .string   "%d "
   .text
   .globl   PrintLinkedList
   .type   PrintLinkedList, @function
PrintLinkedList:
.LFB4:
   .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   -24(%rbp), %rax
   movq   %rax, -8(%rbp)
   movl   $10, %edi
   call   putchar
   jmp   .L10
.L11:
   movq   -8(%rbp), %rax
   movl   (%rax), %eax
   movl   %eax, %esi
   movl   $.LC5, %edi
   movl   $0, %eax
   call   printf
   movq   -8(%rbp), %rax
   movq   8(%rax), %rax
   movq   %rax, -8(%rbp)
.L10:
   cmpq   $0, -8(%rbp)
   jne   .L11
   leave
   .cfi_def_cfa 7, 8
   ret
   .cfi_endproc
.LFE4:
   .size   PrintLinkedList, .-PrintLinkedList
   .globl   BUbble_Sort_linkedlist
   .type   BUbble_Sort_linkedlist, @function
BUbble_Sort_linkedlist:
.LFB5:
   .cfi_startproc
   pushq   %rbp
   .cfi_def_cfa_offset 16
   .cfi_offset 6, -16
   movq   %rsp, %rbp
   .cfi_def_cfa_register 6
   subq   $48, %rsp
   movq   %rdi, -40(%rbp)
   movq   $0, -8(%rbp)
   cmpq   $0, -16(%rbp)
   jne   .L13
   jmp   .L12
.L13:
   movl   $0, -20(%rbp)
   movq   -40(%rbp), %rax
   movq   %rax, -16(%rbp)
   jmp   .L15
.L17:
   movq   -16(%rbp), %rax
   movl   (%rax), %edx
   movq   -16(%rbp), %rax
   movq   8(%rax), %rax
   movl   (%rax), %eax
   cmpl   %eax, %edx
   jle   .L16
   movq   -16(%rbp), %rax
   movq   8(%rax), %rdx
   movq   -16(%rbp), %rax
   movq   %rdx, %rsi
   movq   %rax, %rdi
   call   Swap_node
   movl   $1, -20(%rbp)
.L16:
   movq   -16(%rbp), %rax
   movq   8(%rax), %rax
   movq   %rax, -16(%rbp)
.L15:
   movq   -16(%rbp), %rax
   movq   8(%rax), %rax
   cmpq   -8(%rbp), %rax
   jne   .L17
   movq   -16(%rbp), %rax
   movq   %rax, -8(%rbp)
   cmpl   $0, -20(%rbp)
   jne   .L13
.L12:
   leave
   .cfi_def_cfa 7, 8
   ret
   .cfi_endproc
.LFE5:
   .size   BUbble_Sort_linkedlist, .-BUbble_Sort_linkedlist
   .globl   Swap_node
   .type   Swap_node, @function
Swap_node:
.LFB6:
   .cfi_startproc
   pushq   %rbp
   .cfi_def_cfa_offset 16
   .cfi_offset 6, -16
   movq   %rsp, %rbp
   .cfi_def_cfa_register 6
   movq   %rdi, -24(%rbp)
   movq   %rsi, -32(%rbp)
   movq   -24(%rbp), %rax
   movl   (%rax), %eax
   movl   %eax, -4(%rbp)
   movq   -32(%rbp), %rax
   movl   (%rax), %edx
   movq   -24(%rbp), %rax
   movl   %edx, (%rax)
   movq   -32(%rbp), %rax
   movl   -4(%rbp), %edx
   movl   %edx, (%rax)
   popq   %rbp
   .cfi_def_cfa 7, 8
   ret
   .cfi_endproc
.LFE6:
   .size   Swap_node, .-Swap_node

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote