Question: I am a beginner of MIPS programming and I have some problems on my homework I was given this C++ program and I need to
I am a beginner of MIPS programming and I have some problems on my homework
I was given this C++ program and I need to finish the sort function in MIPS.


I need to finish sortarray function in the below program. I have tried it, but I don't know what mistakes I made.
Would you please help me to solve the problem or give me some hints, thank you!!!!
#------- Data Segment ----------
.data
# Define the string messages and the array
msg1: .asciiz "The original list of random points are "
msg2: .asciiz " The ascending sorted point array are "
space: .asciiz " "
newline: .asciiz " "
leftbracket: .asciiz "("
rightbracket: .asciiz ")"
# x y
# point: .word 20 20
# x_1 y_1 x_2 y_2 x_3 y_3 x_4 y_4 x_5 y_5 x_6 y_6 x_7 y_7 x_8 y_8 x_9 y_9 x_10 y_10
# point_array: .word 20 3 35 173 0 68 0 0 650 456 124 124 16 45 23 14 16 15 20 1
point_array: .word 0:20
#------- Text Segment ----------
.text
.globl main
main:
# $s1 is the array size
addi $s1,$zero,20
# set random seed
li $v0, 30
syscall
addi $a1, $a0, 0
li $a0, 0
li $v0, 40
syscall
# load the starting address of the pointarray to $s0
la $s0, point_array
addi $t0, $zero, 0
# fill the array with $s1 random elements within range [1, 100]
array_filling:
jal random_number_generate
sll $t1, $t0, 2
add $t1, $s0, $t1
sw $v1, 0($t1)
addi $t0, $t0, 1
bne $t0, $s1, array_filling
# Print the original array
jal printoriginal
# Sort array
jal sortarray # sortarry function is what you should implement
# Print the sorted array
jal printresult
# Terminate the program
li $v0, 10
syscall
# Implement sortarray function
# What sortarray should do: Sort the point_array
# $s1 stores the array size =n
# $s0 stores the starting address of the point_array
sortarray:
addi $sp, $sp, -12
sw $s0 ,8($sp)
sw $s1, 4($sp)
sw $ra, 0($sp)
# TODO below:
#addi $sp, $sp, -12
#sw $ra, 0($sp)
addi $t0, $zero, 0 #i
addi $t7,$s1,-1 #n-2
add $t8,$t7,$t0 #n-2-i
addi $t9,$zero,0 #j
loop1:
slt $t5,$t0,$t7
# beq $t0,$t7,end_loop1
beq $t5,$zero,end_loop1
sll $t1, $t0, 2
add $t1, $s0, $t1
loop2:
slt $t5,$t9,$t8
beq $t5,$zero,end_loop2
sll $t5,$t9,2 #offset of j
add $t5,$t5,$s0 #t6 =a[j]
lw $s2,4($t5) #a[j+1]
lw $s3,8($t5) #a[j+2]
lw $s4,12($t5) #a[j+3]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
