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

Write a procedure that follows this EXACT algoritm in MIPS: Arguments: # $a0 - s

ID: 3633744 • Letter: W

Question

Write a procedure that follows this EXACT algoritm in MIPS:
Arguments:
# $a0 - starting address of the list
# $a1 - list length

h = 1;
while ( (h*3+1) < length ) {
h = 3 * h + 1;
}
while ( h>0 ) {
for (i = h-1; i < length; i++) {
tmp = lst[i];
j = i;
for ( j=i; (j>=h) && (lst[j-h]>tmp); j = j-h) {
lst[j] = lst[j-h];
}
lst[j] = tmp;
}
h = h / 3;
}



Here is what I have, but it is not working:
la $t0, ($a0)
move $t1, $a1
li $s4, 1 # h = 1


firstwhile:
mul $s4, $s4, 3
add $s4, $s4, 1
blt $s4, $t1, firstwhile


secondwhile:

ble $t4, 0, finished

forloopone:
subu $s2, $s4, 1
bgt $s2, $t1, firstloopdone

mul $s2, $s2, 4
add $s2, $s2, $a0
lw $s5, ($s2)

move $s3, $s2

forloop2:
blt $s3, $s4, forloop2done
sub $s6, $s3, $s4
mul $s6, $s6, 4
add $s6, $s6, $a0
lw $s7, ($s6)
ble $s7, $s5, forloop2done

mul $s3, $s3, 4
add $s3, $s3, $a0
lw $s8, ($s3)

subu $s3, $s3, $s4
b forloop2

forloop2done:

sw $s5, ($s3)
b forloopone


firstloopdone:

add $s2, $s2, 1
bge $t4, 0, geth

geth:
div $s4, $s4, 3
b secondwhile


finished:


Explanation / Answer

check these links.... http://mescal.imag.fr/membres/vania.marangozova-martin/TEACHING/NACHOS/NACHOS_DOC/CA225b.html http://programmedlessons.org/AssemblyTutorial/ http://www.scribd.com/doc/3577342/MIPS-Assembly-Language-Programming

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote