Write a MIPS assembly language for sorting an array of integers using non-recurs
ID: 3699341 • Letter: W
Question
Write a MIPS assembly language for sorting an array of integers using non-recursive bottom-up merge sort algorithm. Your program should print the processed array after each step of the merge sort. For example, if the input array is 14 27 13 11 49 63 17 9, your program should print each sort process: Input Array 14 27 13 11 49 63 17 9 Print After first Iteration 14 27 11 13 49 639 17 Print After second iteration 11 13 14 27 9 17 49 63 Print After third iteration 911 13 14 17 27 49 63 and so on...Explanation / Answer
# data segment
.data
size: .word 10 #Size of first array
$a0: .word 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 #First array's elements
size2: .word 10 #Size of second array
$a1: .word -1, 0, 1, -2, 0, 2, -3, 0, 3, -4 #Second array's elements
size3: .word 10 #size of third array
main:
la $t0, $a0 #$t0 points to $a0[0]
lw $t1, size #$t1 equals number of elements in $a0[]
la $t2, $a1 #$t2 points to $a1[0]
lw $t3, size2 #$t3 equals number of elements in $a1[]
la $t4, $a0 #load base address of array into register $t4
la $t5, #load base address of array into register $t5
Assigning the array's elements to temp variables:
lw $t6,0($a0)
addiu $a0,$a0,4
lw $t7,0($a0)
addiu $a0,$a0,4
lw $t8,0($a0)
addiu $a0,$a0,4
lw $t9,0($a0)
addiu $a0,$a0,4
lw $t10,0($a0)
addiu $a0,$a0,4
# exit program:
li $v0, 10 # terminate program
syscall
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.