any ideas? Why i am getting:Runtime exception at 0x00400020: fetch attend to not aligned on word border 0x00000007Problem line is: lw $s1,0($a1) #copy arg2 = dimension 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 = resolve of array lw $a1,size #a1 = dimension of array lw $a2,search #$a2 = search key COUNT: lw $s0,0($a0) #copy arg1 = deal with array addi $s1,$zero,7 lw $s1,0($a1) #copy arg2 = size of array lw $s2,0($a2) #copy arg3 = search an essential (n) addi $s2,$zero,30 COUNTLOOP: include $v0,$zero,$zero #v0 = res add $t0,$zero,$zero #$t0 = init i to 0 slt $t1,$t0,$s1 #check if i > dimension of array beq $t1,$zero,DONECOUNT #i is n for this reason end sll $t2,$s0,2 #$t2 = acquire off set for a lw $t3,0($t2) #$t3 = gain value that a bne $t3,$s2,CLOOPBTM #check if a == seach key addi $v0,$v0,1 #if above then increment res CLOOPBTM: addi $t0,$t0,1 j COUNTLOOP DONECOUNT:
The trouble with the password is, the you"re not using the deal with where the size is stored but the size itself:

Here you load the address into A0 and the dimension (7) into A1:

la $a0,array lw $a1,size #a1 = dimension of array Here you pack the an initial word stored in ~ your selection (that will load a 10). This is not what you"ve intended.

You are watching: Fetch address not aligned on word boundary

lw $s0,0($a0) #copy arg1 = attend to array addi $s1,$zero,7 Here you pack the very first word save at ar 0x000007. (your size). Thisis probably also not intended and also will cause an exception because the resolve is no aligned:

lw $s1,0($a1) #copy arg2 = dimension of array and so on.

It seems to me, the you have actually a misunderstanding what the LW indict does. That reads a storage location right into a register.

See more: Is Maluma Y Su Novia Embarazada, Maluma Recibe Curioso Mensaje En Día Del Padre

What you desire in the prolog of your loop is to make duplicates of a register.

To execute so you deserve to use the relocate pseudo instruction if her assembler support it. Otherwise use the OR instruction come copy registers favor this:

COUNT: or $s0, $a0, $a0 #copy arg1 = attend to array addi $s1, $zero,7 or $s1, $a1, $a1 #copy arg2 = size of array or $s2, $a2, $a2 #copy arg3 = search an essential (n) addi $s2, $zero,30 COUNTLOOP: ... for a complete example that a straight search loop shot this (untested and expects the the assembler cares about the delay slots)

main: la $a0,array # $a0 = attend to of array lw $a1,size # $a1 = dimension of array lw $a2,search # $a2 = find key beq $a1, $zero, NOTFOUND # manage the size==0 case.. or $v0, $zero, $zero # init counter to zero LOOP: lw $s0, 0($a0) # pack element beq $s0, $a2, found # branch if vital found: addiu $a0, $a0, 4 # increment array pointer addiu $v0, $v0, 1 # increment loop counter bne $v0, $a1, LOOP # repeat until we've handle the array. NOTFOUND: # -------------------------------------- # if you with this, crucial does not exist: # -------------------------------------- li $v0, -1 # fill a -1 to signal key not found. jr $lr # return to caller FOUND: # ----------------------------------------- # v0 now has the position of the key. # ----------------------------------------- jr $lr