There is nothing wrong with your algthm. It works as expected (except that 3*16 = 48
). I suspect your are setting up your algthm wrong or printing out the array for verification incorrectly.
The following is a program using your algthm that works as expected and prints 2 12 48 40
:
.data
array1: .word 2,6,16,10
array2: .word 0,0,0,0
.text
main:
la $a1 array1
la $a2 array2
li $t0 1
li $s0 4
multing:
bgt $t0,$s0,jump #t0=i , $s0=dimention
lw $t1,0($a1) #a1=address of first array , t1=matrix[i]
mul $t2,$t1,$t0 #t2=t1*t0
sw $t2,0($a2) #store the element
addi $t0,$t0,1 #i=i+1
addi $a1,$a1,4 #next address in first array
addi $a2,$a2,4 #next address in second array
b multing #repeat loop
jump:
move $t0 $zero
la $a1 array2
li $t1 4
printLoop:
lw $a0 0($a1)
li $v0 1
syscall
li $a0 ' '
li $v0 11
syscall
addi $a1 4
addi $t0 1
blt $t0 $t1 printLoop
jr $ra