Code:
.text
main:
la $t5, ArrayB # Put address of ArrayB into $t5
lw $t6, 0($t5) # $t6 = B[0]
lw $t7, 4($t5) # $t7 = B[1]
addi $t5, $t5, 8 # Offset + base into $t5
la $t1, ArrayA # Put address of ArrayA into $t1
addi $t0, $t1, 176 # 176 = (45 - 1) * 4
lw $t2, 0($t1) # $t2 = A[0]
li $t4, 4 # Offset for A[1].
add $t4, $t4, $t1 # Offset + base into $t4
addi $t3, $t2, 3 # $t3 = A[1] = A[0] + 3
sw $t3, 0($t4) # Store A[1].
Loop: # Compute series
addi $t3, $t3, 3 # Mathematical operation
addi $t4, $t4, 4 # Increase offset for ArrayA
addi $t2, $t3, 0 # Copy $t3 to $t2. $t21 now holds A[i-1] for the next itteration
sw $t2, 0($t4) # Store A[i]
add $t8, $t7, $t6 # B[i] = B[i-1] + B[i-2]
addi $t8, $t8, 1 # B[i] = B[i] + 1
addi $t6, $t7, 0 # Copy $t7 to $t6. Now $t6 = B[i-1] and $t7 = B[i-1]
addi $t7, $t8, 0 # Copy $t8 to $t7. Now $t8 = B[i], $t6 = B[i-1] and $t7 = B[i]
sw $t8, 0($t5) # Store B[i]
addi $t5, $t5, 4 # Increase offset for ArrayB
blt $t4, $t0, Loop # Loop through the elements
sub $t5, $t5, 4 # OffsetB--
Loop2:
add $t7, $t2, $t8 # Addition
sub $t6, $t2, $t8 # Subtraction
sw $t6, 0($t5) # Store B[i]
sub $t5, $t5, 4 # OffsetB--
lw $t8, 0($t5) # Load B[i]. Counter now is already decreased
sw $t7, 0($t4) # Store A[i]
sub $t4, $t4, 4 # OffsetA--
lw $t2, 0($t4) # Load A[i]. Counter now is already decreased
bgt $t4, $t1, Loop2 # Loop all elements
sub $t6, $t2, $t8 # Subtraction
sw $t6, 0($t5) # Store B[0]. A[0] is ok already.
################### For testing ################
#li $v0, 4
#la $a0, string1
#syscall
#la $t1, ArrayA
#la $t3, ArrayB
#addi $t5, $t1, 180
#Test:
# lw $t2, 0($t1)
# addi $t1, $t1, 4
# lw $t4, 0($t3)
# addi $t3, $t3, 4
# li $v0, 1
# move $a0, $t2
# syscall
# li $v0, 4
# la $a0, string1
# syscall
# li $v0, 1
# move $a0, $t4
# syscall
# li $v0, 4
# la $a0, string1
# syscall
# blt $t1, $t5, Test
#####################################################
li $v0, 10
syscall # Ciao
.data
string1: .asciiz "\n"
ArrayA: .word 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
ArrayB: .word 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
Any ideas to improve this? Or any comments on the value I already have..