Bgt t0 t1 swap jumps to the swap function b

This preview shows page 4 - 7 out of 7 pages.

bgt $t0, $t1, swap# jumps to the swap function b swapreturn: addi $sp, $sp, -20# moves stack point back to orginal position a lw $a0, 4($sp)# loads the address of the array into a0 lw $a1, 8($sp)# loads the value of the count into a1 lw $t2, 12($sp)# loads the count of second for loop runs to t2 addi $t2, $t2, 1# increments the count of the for loop2 sw $t2, 12($sp)# stores the incremented value on the stack j topfor2# jumps to the first for loop endfor2: addi $a1, $a1, -1# decrements the count of the for loop1 sw $a1, 8($sp)# saves decremented value. j topfor1 j endfor1: jr $ra j #--------------------------------------------------------------------------- # Function swap # Description: It will swap the numbers to order them in numerical order. # Parameters:$a0 = address of th #$a1 = address of the count variable # return $v0 = N/A swap: lw $t0, ($a0)# loads the j-1 value into $t0 lw $t1, ($a1)# loads the j value into $t1
Sheet1 Page 5 add $t2, $t0, $0# places the first number into a temporay place to prepare for switch add $t0, $t1, $0# places $t0 into $t1 add $t1, $t2, $0# finishes the swap by placing the value into t1 a sw $t0, ($a0)# store the j-1 value into $t0 sw $t1, ($a1)# store the j value into $t1 s j swapreturn# returns to the function sort j #--------------------------------------------------------------------------- # Function average # Description: It will take the average of the numbers in the array # Parameters:$a0 = address of the array #$a1 = the value of the count variable # return $f0 = the average of the numbers in the array average: li $t0, 0# loads the desire floating value as a integer mtc1 $t0, $f4# loads the integer value into floating point m Averforloop: bge $t0, $a1, countiszero # if incrementing index is greater than count than jump to countzero b sll $t1, $t0, 2# multiplies the incremeting index by 4 to get the address add $t2, $t1, $a0# address of the value to be added to total a lw $t2, ($t2)# loads the value in array into $t2 mtc1 $t2, $f6# loads the integer value into floating point m add.s $f4, $f4, $f6# adds the total with the element in array a addi $t0, $t0, 1# adds one to the increment index a j Averforloop countiszero: bne $a1, $0, averdone# if count is not equal to zero jump to averdone li $t0, 0# loads the desire floating value as a integer mtc1 $t0, $f4# loads the integer value into floating point mov.s $f0, $f4# places the floating point into a return register jr $ra j
Sheet1 Page 6 averdone: a mtc1 $a1, $f6# loads the integer value of count into floating point div.s $f0, $f4, $f6# total / count jr $ra j #--------------------------------------------------------------------------- # Function print # Description: It will print the numbers in the ordered array and the difference with the mean # Parameters:$a0 = the address of the array #$a1 = the value of count #$f12 = the value of the average # return N/A print: sw $ra, ($sp)# saves the return address on the stack pointer s sll $a1, $a1, 2# multiplies the count by four to change it to the number of bits in memory

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture