Question: Write a function in assembly language that implements the selection sort algorithm shown below. Use the swap and strlen functions you wrote in the previous
Write a function in assembly language that implements the selection sort algorithm shown below. Use the swap and strlen functions you wrote in the previous steps. Remember, all functions must follow the standard conventions of preserving selected registers onto the stack.
Write a main function that calls your selectionsort function several times with various nullterminated strings preloaded in memory. Your main function should print the original string to the console before you call the selection sort function and then print the sorted string to the console after you call the function.
void selectionsort char message
int length strlen message ;
for int i ; i length; i
int indexofmin i;
for int ji; j length; j
if messageindexofmin messagej
indexofmin j;
swap message, i indexofmin ;
Can this be done in MIPS assemby? These are my swap and strlen functions if you can implement them
swap:
# Load char at index: char temp messageindex
add $t $a $a
lbu $t$t
# Load char at index and store at index: messageindex messageindex
add $t $a $a
lbu $t$t
sb $t$t
# Store temp char at index: messageindex temp
sb $t$t
jr $ra
strlen:
# Initialize counter i to
li $t
loop:
# Load character at messagei
add $t $a $t
lbu $t$t
# Check if character is null terminator.
beq $t $zero, end
# Increment counter i
addi $t $t
j loop
end:
# Set return value.
move $v $t
jr $ra
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
