I am still very much a newbie once it comes to MIPS programming so bear with me. I am trying to write a function that goes through a 10 element array and returns the max and minimum values of the array. So far I have:
.data
X .word 31, 17, 92, 46, 172, 208, 13, 93, 65, 112
N .word 10
minValue .asciiz "Minimum Value: "
maxValue .asciiz "\nMaximum Value: "
values .asciiz "\nValues divisible by 4: "
.text
main:
la $a0, X
la $a1, N
jal MaxMin
MaxMin:
lw $t0, 0($a0)
swap:
move $t0, $s0
move $s0, $s1
move $s0, $t0
The MaxMin function is supposed to return the maximum and minimum values of the X array for me to print out. My plan is to go through the array and if an element is greater than or less than another element, they get swapped using the swap function. The problem is I have no idea how to go about doing this because I do not really know the syntax that you are supposed to use when dealing with arrays. If anyone could help I would appreciate it.
Here an idea of how to read and print elements of an array through a function. Would make comparisons and make the swap.
.data
space: .asciiz " "
X: .word 31, 17, 92, 46, 172, 208, 13, 93, 65, 112
N: .word 10
.text
main: la $a0, X #$a0=load address of array X
lw $a1, N #$a1=10 --number elements
jal readArray #call readArray
li $v0, 10 #exit program
syscall
readArray:
li $t0, 0 #$t0=0
li $t1, 0 #$t1=0
buc: bge $t0, $a1, final #if $t0 >= $a1 then goto final
lw $a0, X($t1) #$a0 = X(i)
li $v0, 1 #Print integer
syscall
la $a0, space #load a space: " "
li $v0, 4 #print string
syscall
addi $t1, $t1, 4 #Every 4 bytes there is an integer in the array
addi $t0, $t0, 1 #$t0=$t0+1
b buc #goto buc
final:
jr $ra #return