Reputation: 435
.data
string1:.asciiz "Enter number\n"
matrix:.space 100
i: .word 0
k: .word 0
.text
main:
lw $t1,i
lw $t2,k
la $s0,matrix
jal Build_matrix
j exit
Build_matrix:
li $t3,25
li $t4,0
li $a1,0
Scanning:
bge $t1,$t3,Return #if i>=25,stop
li $v0,4
la $a0,string1
syscall
add $t4,$t2,$t2 #2j
add $t4,$t4,$t4 #4j
add $a1,$s0,$t4
li $v0,5
syscall
sw $v0,0($a1)
addi $t1,$t1,1
addi $t2,$t2,1
j Scanning
Return:
jr $ra
#**** End of Build_matrix method ****
exit:
This is the code to take 25 numbers as input from user(asks a number 25 times) and store them in memory.There are no compile time errors.But during runtime,this message-"Exception 5 [Address error in store] occurred and ignored" is displayed everytime after Enter number is displayed?what is my mistake.....Thanks
Upvotes: 0
Views: 3685
Reputation: 22585
The problem you are facing is that the matrix is not word-aligned, which is needed by sw
instructions.
You have to add a .align 2
directive after the matrix label:
matrix:
.align 2 # ensure matrix is properly aligned
.space 100
Upvotes: 1