- #1
trouty323
- 24
- 0
Hello. My task here is to store hard-code data directly into an array, find the largest in the array, then put that number at the end of the array. My code that I have is below, but I am getting an error. The error is:
"Exception occurred at PC=0x0040003c"
"Bad address in data/stack read = 0x2002003c"
Any ideas?
"Exception occurred at PC=0x0040003c"
"Bad address in data/stack read = 0x2002003c"
Any ideas?
Code:
.data
.word 7
.word 39
.word 42
.word 16
.word 15
.word 21
.word 3
.word 2
.word 37
.word 11
.word 32
.word 28
.word 40
.word 27
.word 20
.text
.globl main
main:
lui $s0, 0x1001 # base address
add $t0, $t0, $zero # index count
add $t1, $t1, $zero # max element, $t1 = 0
addi $t5, $t5, 15 # number of elements
add $t2, $t2, $s0 # offset plus base
Loop:
beq $t0, $t5, Exit # branch if counter is equal to number of elements in array
lw $t3, 0($t2) # reading first element
addi $t0, $t0, 1 # increment counter by 1
addi $t2, $t2, 4 # increment offset by 4
slt $t4, $t1, $t3 # $t4 = 1 if $t1 is less than $t3, otherwise $t4 = 0
beq $t4, $zero, Loop # branch to loop if value in $t4 is equal to value in $zero
add $t1, $t3, $zero #
j Loop
Exit:
sw $t1, 0($t2) # store highest back into array
li $v0, 10 # syscall to terminate
syscall