I am learning how to code in assembly so i am a noob. I wrote this code where it adds the 3 first elements in the array and saves it to the 4th element in the array however i am getting an error however i don't understand its meaning and what i have done incorrectly.
this is the error line 19: Runtime exception at 0x00400040: address out of range 0x00000018
.text .globl main main: la $t0, i la $s0, sum la $t3, array la $t5, k lw $t0, 0($t0) lw $s0, 0($s0) lw $t3, 0($t3) lw $t5, 0($t5) Loop: add $s0, $s0,$t3, # adds sum with element in array addi $t3, $t3, 4 # add 4 to array to get next element addi $t0, $t0, 1 #add + to i bne $t5, $t0, Loop # if k !=i back to loop sw $s0, 12($t3) #store sum in 4th element of array nop .data 0x10010000 i: .word 0 k: .word 3 sum: .word 0 array: .word 0:2
I don't recognize this assembly at all and considering the overwhelming responses I think nobody else does either but after some inspection I think you are mixing values and addresses!
add $s0, $s0,$t3, # adds sum with element in array
you use $t3 with the value from the array
addi $t3, $t3, 4 # add 4 to array to get next element
you expect $t3 to contain an address. You can't have both at the same time.
User contributions licensed under CC BY-SA 3.0