Question: Part 3 : Linked List Selection Sort - Extra Credit Part 3 requires that you sort a linked list of structs based on the value
Part : Linked List Selection Sort Extra Credit
Part requires that you sort a linked list of structs based on the value of one of the struct elements. A complete program in C is provided in listSort.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 function from listSort.c to assembly using listsort.og as a starting point.
The provided listsort.ogcontains the c code as comments, labels, and other helpful comments to help you structure your code.
Rename listsort.og to listsort.asm
Translate any missing helper functions.
Do not modify listmain.asm
You can modify listmain.asm for debug and testing purposes.
Your code in listsort.asm must not depend on any edits you made to listmain.asm for proper operation.
Your code must be in listsort.asm. The listmain.asm file: text
globl main
main:
li spxffffe
addi spsp
# studentlist createListstudentArr SIZE;
li a
la a studentArr
jal createList
sw asp
# sort&studentlist;
addi asp
jal sort
# printListstudentlist;
lw asp
jal printList
# return
li a
ecall
globl addStudent
# asm is nutty as the struct was passed in the registers.
addStudent:
addi spsp
sw rasp
sw ssp
sw ssp
mv sa
mv sa
li a
jal malloc
lw as
lw as
lw as
lw as
sw aa
sw aa
sw aa
sw aa
sw sa
lw rasp
lw ssp
lw ssp
addi spsp
jr ra
globl createList
createList:
blez aendcreateList
addi spsp
sw rasp
sw ssp
sw ssp
mv sa
slli sa
add ssa
slli ss
add sas
li a
cloop:
lw as
lw as
lw as
lw as
lw as
sw asp
sw asp
sw asp
sw asp
sw asp
mv asp
jal addStudent
addi ss
bne sscloop
lw rasp
lw ssp
lw ssp
addi spsp
jr ra
endcreateList:
li a
ret
globl printList
printList:
beqz aendprintList
addi spsp
sw rasp
sw ssp
mv sa
lw as
jal printint
li ax
jal printchar
mv as
jal printstring
li ax
jal printchar
lw as
jal printint
li a
jal printchar
lw as
jal printList
lw rasp
lw ssp
addi spsp
jr ra
endprintList:
ret
#essentially swizzles the next pointers of the args.
globl swapNodes
swapNodes:
sw aa
sw aa
lw aa
lw aa
sw aa
sw aa
ret
globl sort
sort:
addi spsp
sw rasp
sw ssp
mv sa
lw aa
beqz asortbasecase
jal recurSelectionSort
sw as
sortbasecase:
lw rasp
lw ssp
addi spsp
jr ra
globl malloc
malloc:
# loosely simulates sbrk system call
# a amount of memory in bytes
# a address to the allocated block
li a
ecall
ret
globl printchar
printchar:
li a
ecall
ret
globl printint
printint:
li a
ecall
ret
globl printstring
printstring:
li a
ecall
ret
globl studentArr
data
studentArr:
string "Dougy"
word
word
word
string "Timmy"
word
word
word
string "Emily"
word
word
word
string "Jimmy"
word
word
word
string "Kimmy"
word
word
word
string "Carlo"
word
word
word
string "Vicky"
word
word
word
string "Anton"
word
word
word
string "Brady"
word
word
word
string "Sonya"
word
word
word I need the listsort.asm file. The one I made was not sorting the list in order I kept getting: Sonya
Anton
Carlo
Vicky
Brady
Kimmy
Jimmy
Emily
Timmy
Dougy
