my code is
however whenever I tried to print something inside the function it always gives me a bad address error, can someone please tell me why?? this is my code:
largest : #Function prologue
subu $sp, $sp, 56
sw $a1, 44($sp)
sw $a0, 40($sp)
sw $ra, 36($sp)
sw $fp, 32($sp)
sw $s7, 28($sp)
sw $s6, 24($sp)
sw $s5, 20($sp)
sw $s4, 16($sp)
sw $s3, 12($sp)
sw $s2, 8($sp)
sw $s1, 4($sp)
sw $s0, 0($sp)
addiu $fp, $sp, 56
lw $s0, 0($a0) # $t0 = first elements in the numbers array
li $s2, 1 # $t2 = 1
li $s3, 0 # $t3 = 0
iterate : #Loop Test
add $s1, $s2, $s2 # quadruple i to get offset for numbers[i]
add $s1, $s1, $s1
add $s5, $s1, $a0 # compute address of numbers[i]
lw $s7, 0($s5) # t7 = value stored at numbers[i]
addi $s2, $s2, 1 # $t2 ++
beq $s3, $a1, result # if $t3 equals to numElements then count result
addi $s3, $s3, 1 # $t3 ++
#Loop Body
slt $s4, $s0, $s7 # $t4 = 1 if $t0 is less than $t7
beq $s4, $zero, iterate # if $t5 not equal to zero then iterate again
lw $s0, 0($s5) # else $t0 = $t7
j iterate # iterate
result: add $v0, $s0, $zero # put the result of the largest number into $v0
#Function epilogue
lw $a1, 44($sp)
lw $a0, 40($sp)
lw $ra, 36($sp)
lw $fp, 32($sp)
lw $s7, 28($sp)
lw $s6, 24($sp)
lw $s5, 20($sp)
lw $s4, 16($sp)
lw $s3, 12($sp)
lw $s2, 8($sp)
lw $s1, 4($sp)
lw $s0, 0($sp)
addiu $sp, $sp, 56
jr $ra
average : #Function prologue
subu $sp, $sp, 56
sw $a1, 44($sp)
sw $a0, 40($sp)
sw $ra, 36($sp)
sw $fp, 32($sp)
sw $s7, 28($sp)
sw $s6, 24($sp)
sw $s5, 20($sp)
sw $s4, 16($sp)
sw $s3, 12($sp)
sw $s2, 8($sp)
sw $s1, 4($sp)
sw $s0, 0($sp)
addiu $fp, $sp, 56
li $s2, 0 # $s2 = 0
iterate1 : #Loop Test
add $s1, $s2, $s2 # quadruple i to get offset for numbers[i]
add $s1, $s1, $s1
add $s5, $s1, $a0
lw $s0, 0($s5)
add $s4, $s4, $s0 # s4 = total addition of the array to numbers[i]
#LoopBody
addi $s2, $s2, 1 # $s2 ++
beq $s3, $a1, result1 # if $t3 equals to numElements then count result
addi $s3, $s3, 1 # $t3 ++
j iterate1 # iterate1
result1 : div $s4, $a1
addi $a2, $a1, 0
mfhi $a1
addi $a0, $a1,
mflo $a0
jal printAverage
#Function epilogue
lw $a1, 44($sp)
lw $a0, 40($sp)
lw $ra, 36($sp)
lw $fp, 32($sp)
lw $s7, 28($sp)
lw $s6, 24($sp)
lw $s5, 20($sp)
lw $s4, 16($sp)
lw $s3, 12($sp)
lw $s2, 8($sp)
lw $s1, 4($sp)
lw $s0, 0($sp)
addiu $sp, $sp, 56
jr $ra
thanks