For the assignment I am doing for my Computer Orgainzation and Assembly class, we are to print a given array, using the selection sort. Then, for bonus points, we are to print the array after it is sorted 5 per line. I am stuck on this part. My codes sorts the array, but I don't know how to get it to print 5 per line. Can anyone help?
.data
size: .word 20
array: .word 99,23,45,42,09,34,71,64,88,42,12,37,33,36,83,78,17,04,52,46
before: .asciiz "Before sort:\n"
space: .asciiz " "
after: .asciiz "\n\nAfter Sort\n"
newLine: .asciiz "\n"
.text
.globl main
main: li $v0, 4 # system call
la $a0, before # to print before string
syscall
jal print # subroutine prints all elements in array
li $t5, 0 # t5 is k = 0
la $t7, size
lw $t7, 0($t7) # t7 = size
addi $t8, $t7, -1 # t8 = size - 1
la $t6, array # t6 = address of the array
outer: slt $t0, $t5, $t8 # if k < size - 1 t0 = 1
beq $t0, $zero, endOuter # k >= (size - 1)
add $t9, $zero, $t5 # t9 is min = k
addi $t1, $t5, 1 # t1 is j = k + 1
inner: slt $t0, $t1, $t7 # if j < size t0 = 1
beq $t0, $zero, endInner
add $s3, $t9, $t9 # s3 = 2 * min
add $s3, $s3, $s3 # s3 = 4 * min
add $s3, $t6, $s3 # s3 is address of list[min]
lw $t2, 0($s3) # t2 is list[min]
add $s0, $t1, $t1 # s0 = 2 * j
add $s0, $s0, $s0 # s0 = 4 * j
add $s0, $t6, $s0 # s0 is address of list[j]
lw $t3, 0($s0) # t3 is list[j]
slt $t0, $t3, $t2 # if list[j] < list[min] t0 = 1
beq $t0, $zero, secondIF # skip min = j & ++j and jump to secondIF
add $t9, $zero, $t1 # min = j
j secondIF
secondIF: beq $t9, $t5, incrementJ # if min != k swap, else goto incrementJ
# BEGIN SWAP :
add $s0, $t9, $t9 # s0 = 2 * min
add $s0, $s0, $s0 # s0 = 4 * min
add $s0, $s0, $t6 # s0 = address of list[min]
lw $t4, 0($s0) # t4 is temp = list[min]
add $s1, $t5, $t5 # s1 = 2 * k
add $s1, $s1, $s1 # s1 = 4 * k
add $s1, $t6, $s1 # s1 = address of list[k]
lw $s3, 0($s1) # s3 = list[k]
sw $s3, 0($s0) # list[min] = list[k]
sw $t4, 0($s1) # list[k] = temp
addi $t1, $t1, 1 # ++j
add $t9, $zero, $t5 # t9 is min = k
# END SWAP
j inner
incrementJ: addi $t1, $t1, 1 # ++j
j inner
endInner: addi $t5, $t5, 1 # ++k
j outer
endOuter: li $v0, 4 # system call
la $a0, after # to print after string
syscall
jal print # subroutine prints all elements in array
j exitProgram
print: li $t5, 0 # k = 0
la $t6, array # t6 = address of the array
la $t7, size
lw $t7, 0($t7) # t7 = size
loop: slt $t0, $t5, $t7 # if k < size t0=1
beq $t0, $0, printExit # if k >= 10 exit
li $v0, 1 # print an integer
lw $a0, 0($t6) # address of integer in a0
syscall
addi $t6, $t6, 4 # increment address of array by 4(next int)
addi $t5, $t5,1 # k++
li $v0, 4 # print a newline after each int
la $a0, space # address of space string
syscall
j loop
printExit: jr $ra
exitProgram: li $v0, 10 # system call to
syscall # terminate program