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
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
Get step-by-step solutions from verified subject matter experts
