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

Using assem. mips processor write a program that swaps values in an array in a s

ID: 644407 • Letter: U

Question

Using assem. mips processor write a program that swaps values in an array in a subroutine.

cannot make additional array. Take the original array "array" and swap the values and save them into the same array in a subroutine.

array = 3 6 9 12 15 18

after sub:

18 15 12 9 5 3

model in psuedo

reverseArray(int arraySize)

{

   head = first index of the array

   tail = last index of the array

swap:   if (head <=tail)

   {

   swap the content of head and tail (array[head] and array[tail] with each other

   increment the head value by one word

   decrement tail by one word

   go to swap

   }

}

Explanation / Answer

la   $t0 array
addi $t1 $t0 20 #last element of array

lw $t2 0($t0)
lw $t3 0($t1)
sw $t2 0($t1)
sw $t3 0($t0)

addi $t0 $t0 4
addi $t1 $t1 -4
blt $t0 $t1 loop

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