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 selection_sort function several times with various null-terminated strings pre-loaded 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 selection_sort( char *message )
{
int length = strlen( message );
for( int i =0; i < length; i++)
{
int index_of_min = i;
for( int j=i; j < length; j++)
{
if( message[index_of_min]> message[j])
{
index_of_min = j;
}
}
swap( message, i, index_of_min );
}
}
Can this be done in MIPS assemby? These are my swap and strlen functions if you can implement them
swap:
# Load char at index1: char temp = message[index1]
add $t0, $a0, $a1
lbu $t1,0($t0)
# Load char at index2 and store at index1: message[index1]= message[index2]
add $t2, $a0, $a2
lbu $t3,0($t2)
sb $t3,0($t0)
# Store temp char at index2: message[index2]= temp
sb $t1,0($t2)
jr $ra
strlen:
# Initialize counter i to 0.
li $t0,0
loop:
# Load character at message[i]
add $t1, $a0, $t0
lbu $t2,0($t1)
# Check if character is null terminator.
beq $t2, $zero, end
# Increment counter i.
addi $t0, $t0,1
j loop
end:
# Set return value.
move $v0, $t0
jr $ra

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!