MIPS Exception 4 and 5 errors
I am trying to make function AVA where x1[i] = y1[i] + z1[i] using the stack except I am getting these errors:
Exception 5 [Address error in store] occurred and ignored
Exception 5 [Address error in store] occurred and ignored
Exception 5 [Address error in store] occurred and ignored
Exception 5 [Address error in store] occurred and ignored
Exception 5 [Address error in store] occurred and ignored
Exception 4 [Address error in inst/data fetch] occurred and ignored
0
Exception 4 [Address error in inst/data fetch] occurred and ignored
0
Exception 4 [Address error in inst/data fetch] occurred and ignored
0
Exception 4 [Address error in inst/data fetc开发者_运维技巧h] occurred and ignored
0
Exception 4 [Address error in inst/data fetch] occurred and ignored
0
Heres my code:
.data
newline: .asciiz "\n"
x1: .space 20
y1: .word 1, 2, 3, 4, 5
z1: .word -5, -4, -3, -2, -1
x2: .space 40
y2: .word -1, 3, -5, 7, -9, 2, -4, 6, -8, 10
z2: .word 1,2,3,4,5,6,7,8,9,10
#######################################################
.globl main
.text
main:
#$a0-a3 for passing to functions
#$v0-v1 for storing return values from functions
addiu $sp, $sp, -16 #allocate stack space
la $t0, x1 #AVA(x1,y1,z1,5)
sw $t0, 0($sp)
la $t0, y1
sw $t0, 4($sp)
la $t0, z1
sw $t0, 8($sp)
li $t0, 5
sw $t0, 12($sp)
jal AVA
addiu $sp, $sp, 16 #deallocate stack space
#############################
la $t0, x1 #t0 = x
li $t2, 0 #iterator
li $t3, 5 #array size
For:
bge $t2, $t3, endFor # loop while element <= arraysize
lw $t1, 0($t0) # get word from x array
li $v0, 1 # 'print' command code
move $a0, $t1 # needs value in $a0
syscall # print it
# print newline
li $v0, 4
la $a0, newline
syscall
addi $t0, $t0, 4 # move to next entry in array x
addi $t2, $t2, 1 # increment iterator number
b For # go to Loop
endFor:
#############################
li $v0, 10 #exit
syscall
AVA:
li $t0, 0 #iterator
lw $t1, 0($sp) #x[i]
lw $t2, 4($sp) #y[i]
lw $t3, 8($sp) #z[i]
lw $t4, 12($sp) #n
loop:
bge $t0, $t4, return # loop while iterator < n
lw $t5, 0($t2)
lw $t6, 0($t3)
add $t5, $t5, $t6 #y[i] + z[i]
sw $t5, 0($t1) #x[i] = y[i] + z[i]
addi $t0, $t0, 1 #increment iterator
addi $t1, $t1, 4 #increment x
addi $t2, $t2, 4 #increment y
addi $t3, $t3, 4 #increment z
b loop
return:
sw $t1, 0($sp)
jr $ra
#######################################################
and my full log: http://pastie.org/1583460
You are missing a .align
directive before your arrays. The newline
constant is two bytes long, and thus it makes x1
, y1
, and z1
start at unaligned addresses. Try adding .align 2
(align to multiple of 2^2 bytes) before the definition of x1
.
精彩评论