any ideas? Why I am getting: Runtime exception at 0x00400020: fetch address not aligned on word boundary 0x00000007 Problem line is: lw $s1,0($a1) #copy arg2 = size of array
.data
.align 4 #added this, didnt work
size: .word 7
.align 4 #added this, didnt work
search: .word 30
.align 4 #added this,didnt work
array: .word 10,20,30,40,50,60,70
.align 4
.text
main:
la $a0,array #$a0 = address of array
lw $a1,size #a1 = size of array
lw $a2,search #$a2 = search key
COUNT:
lw $s0,0($a0) #copy arg1 = address array
addi $s1,$zero,7
lw $s1,0($a1) #copy arg2 = size of array
lw $s2,0($a2) #copy arg3 = search key (n)
addi $s2,$zero,30
COUNTLOOP:
add $v0,$zero,$zero #v0 = res
add $t0,$zero,$zero #$t0 = init i to 0
slt $t1,$t0,$s1 #check if i > size of array
beq $t1,$zero,DONECOUNT #i is n so end
sll $t2,$s0,2 #$t2 = get off set for a[i]
lw $t3,0($t2) #$t3 = get value of a[i]
bne $t3,$s2,CLOOPBTM #check if a[i] == seach key
addi $v0,$v0,1 #if above then increment res
CLOOPBTM:
addi $t0,$t0,1
j COUNTLOOP
DONECOUNT: