Answered step by step
Verified Expert Solution
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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started