Question: In MIPS can someone fill in the #comments .data # declare string prompts for the user .text #Accept from the user a number representing the
In MIPS can someone fill in the #comments
.data
# declare string prompts for the user
.text
#Accept from the user a number representing the Array Size
#Assign the number to a temp register
#Init the array's base address
# Create a Loop based on the Array Size to get numbers from user and store in memory
# --------- START LOOP FOR ENTERING ARRAY INTO MEMORY ------------
loop:
move $t3, $v0 #Move the number read from the user to $t3
sw $t3, 0($s0) #Store the value in Array
# Increase the size of the Array by 1 element or 4-bytes
# Increment the loop by 1
# check to see if the counter is less than the number of elements to store
# --------- END LOOP FOR ENTERING ARRAY INTO MEMORY ------------
# Now start an Outer Loop for comparing the numbers to begin sort
add $t1, $zero, $zero # j counter = 0
add $s0, $sp, $zero
outerLoop:
move $t3, $t1 # Set $t3 to the first element of array
addi $t2, $t1, 1 # Set inner index to outer + 1
innerLoop:
#Determiine the ith address of the array
move $a0, $t2
jal memoryAddress
lw $t5, 0($v0)
#Read the element from the array
# check if a[i] < a[iMin]
# $t5 holds the number in ith element of the array
# $t6 holds the current min value
bge $t5, $t6, endIf
move $t3, $t2 # $t3 now has the element index of the new min value iMin = ith element
endIf:
# Add 1 to the inner loop counter $t2
# check to see if it is not greater than the array size
# branch back up to innerLoop
#------ Swap Element Logic ------
# Locate the memory address of the iMin element
# Move the address to $t9
# t9 = address of a[iMin]
move $a0, $t3
jal memoryAddress
move $t9, $v0
# Locate the memory address of the current Min element a[j]
# Move that to s2 = address of a[j]
lw $s3, 0($t9) # $s3 now holds $t9, address of the ith element i.e. the new minimum number
lw $s4, 0($s2) # $s4 now hold $s2, the address of the jth element i.e. the old min number
sw $s4, 0($t9) # put the old min number at jth location into the location where the ith number was
sw $s3, 0($s2) # $s3 the old jth number location gets the new min number
# --- End Swap Element Logic ----
# Add 1 to the outer loop counter $t1
# check to see if it is not greater than the array size
# branch back up to innerLoop
# Print the array by looping through
exit:
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
