Question: #include #define SIZE 10 typedef struct Node studentNode; void swap(studentNode *arr, int i, int j); void selectionSort(studentNode *arr, int i, int n); void printArray(studentNode *arr,

#include #define SIZE 10 typedef struct Node studentNode; void swap(studentNode *arr, int i, int j); void selectionSort(studentNode *arr, int i, int n); void printArray(studentNode *arr, int n); struct Node { char name[6]; int studentid; int coursenum; }; studentNode studentlist[SIZE] = { {"Dougy", 13, 2122}, {"Timmy", 15, 2122}, {"Emily", 18, 2123}, {"Jimmy", 14, 2120}, {"Kimmy", 11, 2123}, {"Carlo", 19, 2123}, {"Vicky", 22, 2120}, {"Anton", 12, 2322}, {"Brady", 10, 2120}, {"Sonya", 16, 2123} }; int main() { int n = SIZE; selectionSort(studentlist, 0, n); printArray(studentlist, n); return 0; } /* Utility function to swap values at two indices in an array*/ void swap(studentNode arr[], int i, int j) { studentNode temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } /* Recursive function to perform selection sort on subarray `arr[in-1]` */ void selectionSort(studentNode arr[], int i, int n) { /* find the minimum element in the unsorted subarray `[in-1]` // and swap it with `arr[i]` */ int j; int min = i; for (j = i + 1; j < n; j++) { /* if `arr[j]` is less, then it is the new minimum */ if (arr[j].studentid < arr[min].studentid) { min = j; /* update the index of minimum element */ } } /* swap the minimum element in subarray `arr[in-1]` with `arr[i] */ swap(arr, min, i); if (i + 1 < n) { selectionSort(arr, i + 1, n); } } /* Function to print `n` elements of array `arr` */ void printArray(studentNode arr[], int n) { int i; for (i = 0; i < n; i++) { printf("%d ", arr[i].studentid); printf("%s ", arr[i].name); printf("%d ", arr[i].coursenum); } }

Part 2: Struct Array Selection Sort

Part 2 requires that you expand your example to sort an array of structs based on the value of one of the struct elements. A complete program in C is provided in structSort.c.

Compile and execute the C program so you understand what the behavior looks like.

Examine the program so you understand the code.

Translate the selectionsort, swap and printarray functions in structsort.c to assembly

Do not modify structmain.asm

You can modify structmain.asm for debug and testing purposes.

Your code in structsort.asm must not depend on any edits you made to structmain.asm for proper operation.

Your code must be in structsort.asm.

Completely provide the selectionsort, swap and printarray functions in structsort.c to assembly structsort.asm

Here's the asm code I have right now, but please using the provide c code to fixed my asm code, and provide the selectionsort, swap and printarray functions in structsort.asm, you dont need to translate the mian function.

# Declare studentlist array .data student: name: .space 6 studentid: .word coursenum: .word studentlist: .word 10 .word student1, student2, student3, student4, student5, student6, student7, student8, student9, student10

# Initialize studentlist student1: .string "Brady" .word 10 .word 2120 student2: .string "Kimmy" .word 11 .word 2123 student3: .string "Anton" .word 12 .word 2322 student4: .string "Dougy" .word 13 .word 2122 student5: .string "Jimmy" .word 14 .word 2120 student6: .string "Timmy" .word 15 .word 2122 student7: .string "Sonya" .word 16 .word 2123 student8: .string "Emily" .word 18 .word 2123 student9: .string "Carlo" .word 19 .word 2123 student10: .string "Vicky" .word 22 .word 2120

# Define utility functions .globl swap swap: addi sp, sp, -16 sw s0, 0(sp) sw s1, 4(sp) sw s2, 8(sp) sw s3, 12(sp)

la s0, studentlist lw s1, 0(a1) # i lw s2, 0(a2) # j slli t0, s1, 3 # sizeof(struct student) is 8 bytes

add t0, t0, s0 # address of student i lw t1, 4(a1) # student i's ID lw t2, 8(a1) # student i's course lw t3, 0(t0) # student i's name slli t4, s2, 3

add t4, t4, s0 # address of student j lw t5, 4(a2) # student j's ID lw t6, 8(a2) # student j's course lw t7, 0(t4) # student j's name sw t5, 0(t0) # swap ID sw t6, 4(t0) # swap course sw t7, 0(t4) # swap name sw t1, 4(t4) # swap ID sw t2, 8(t4) # swap course

lw s0, 0(sp) lw s1, 4(sp) lw s2, 8(sp) lw s3, 12(sp) addi sp, sp, 16 jr ra

# Recursive function to perform selection sort on subarray `arr[i...n-1]` .globl selectionSort selectionSort: # Save callee-save registers to the stack addi sp, sp, -32 lb s0, 0(sp) lb s1, 8(sp) lb s2, 16(sp) lb s3, 24(sp)

# Load array pointer la s5, 0(a1)

# Base case: if only one element is left sub t0, a3, a2 li t1, 2 ble t0, t1, end

# Recursively call function on subarray addi a3, a3, -1 jal selectionSort addi a3, a3, 1

# Load i-th student add a2, a2, a2 addi a2, a2, 32 add a2, a2, a1

# Find minimum student lw s0, 0(a2+student.studentid) lw s1, 0(a2+student.coursenum) addi a3, a2, 32 li s2, 1

innerloop: # Check if j < n blt s2, t0, loopcheck j endinnerloop

loopcheck: # Load j-th student add a3, a3, a3 addi a3, a3, 32 add a3, a3, a1

#

.globl printArray printArray:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!