Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

.text .globl_start _start: la $a0, array lw $a1, count # in the jal statement ja

ID: 666706 • Letter: #

Question

.text
.globl_start
_start:

la $a0, array
lw $a1, count # in the jal statement
jal sort #jump to "sort:"
j print           #jump to "print:"

   #start subrouten
sort: sw $ra, -4($sp)   #load the return address in to the stack pointer
move $t6, $a1 #outter counter
outter: sub $t6, $t6, 1 #sub the outter counter
move $t7, $a0 #save the address for "array" into $t7
move $t5, $a1 #inner counter

inner: sub $t5, $t5, 1 #sub 1 from inner counter
lw $s0,($t7)   #load the two variables
lw $s1,4($t7)   #to be tested

ble $s0, $s1, next   #if $s0 <$s1 branch
sw $s1,($t7)       #else switch the two
sw $s0,4($t7)

next:add $t7, $t7, 4   #add 4 to the saved address for next loop
bnez $t5, inner       #if the inner counter is not 0 then branch
bnez $t6, outter   #if the outter counter is not 0 then branch

lw $ra, -4($sp)   #if outter counter is 0 load top
jr $ra       #stack point and exit subrouten

print: #print out the final memory locations
la $t7,array
lw $t0,($t7)
lw $t1,4($t7)
lw $t2,8($t7)

.data
array: .word 3,2,1
count: .word 3
## end of file
      


      

1) Observe the registers/Memory locations values after each Step Run. Record the final values.

2) Use $t0, $t1, and $t2 to hold the numbers after the ascending sort. What are the final values of $t0, $t1, and $t2?

Explanation / Answer

1)Final value recorded would 3 2 and 1

2)Final values of $t0, $t1, and $t2- should be 1,2 and 3 respectively.