# merge sort .text .globl main main: la $a0, array1 la $a1, array2 la $a3, array3 jal merge # store the amount of elements to be printed add $t0, $0, $0 add $t1, $0, $v0 sll $t1, $t1, 2 #print the number of elements first add $a0, $v0, $0 li $v0, 1 syscall #print the elements of the array loop2: li $v0, 4 la $a0, str syscall lw $a0, array3($t0) li $v0, 1 syscall add $t0, $t0, 4 bne $t0, $t1 loop2 j finish ## merge function merge: add $t0, $a0, 0 # t0 indexes array1 add $t1, $a1, 0 # t1 indexes array2 add $t2, $a3, 0 # t2 indexes array3 lw $t3, ($t0) # the amount of ints in array lw $t4, ($t1) add $v0, $t3, $t4 # the value to be returned add $t0, $t0, 4 # point to the real start of add $t1, $t1, 4 # both arrays sll $t3, $t3, 2 # the amount of bytes in array sll $t4, $t4, 2 # add $t3, $t0, $t3 # the final location in array add $t4, $t1, $t4 # jw: these now point past the last element loop: lw $t5, ($t0) # load the values from the arrays lw $t6, ($t1) # slt $t7, $t5, $t6 # bne $t7, 1 else # if (t5