Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

WHAT is the User WILLING to PAY?

Answered: 1 week ago

Question

1. What would you do if you were Jennifer, and why?

Answered: 1 week ago