Arrays 通过MIPs中的数组递增以添加内容

Arrays 通过MIPs中的数组递增以添加内容,arrays,mips,Arrays,Mips,现在我正在尝试将两个数组的所有内容相加,并将它们存储到各自的变量中。我需要为两个数组使用一个函数。现在,我最大的问题实际上是增加数组以实际添加内容。我将数组、大小和总和的变量移动到$a0、a1和$a2中。在函数中,我找不到任何方法来增加数组以向和中添加下一个值 .data array1: .word 2,4,6,8 size1: .word 16 array2: .word 1,3,5 size2: .word 12 sum1: .word 0 sum2: .w

现在我正在尝试将两个数组的所有内容相加,并将它们存储到各自的变量中。我需要为两个数组使用一个函数。现在,我最大的问题实际上是增加数组以实际添加内容。我将数组、大小和总和的变量移动到$a0、a1和$a2中。在函数中,我找不到任何方法来增加数组以向和中添加下一个值

.data

array1: .word   2,4,6,8
size1:  .word   16
array2: .word   1,3,5
size2:  .word   12
sum1:   .word   0
sum2:   .word   0

.text
.globl main

main: 
lw  $a0, array1
lw  $a1, size1
lw  $a2, sum1

jal sumArr




sumArr:
beq $t0,$a1,main    # Branch to main if the size of the array and the pointer are equal

add $a2,$a2,$a0 # Add the element in the array to the corresponding sum
addi    $t0,$t0,4   # Add 4 to the pointer in order to view the next element of the array
j   sumArr

这就是我目前所掌握的。

你似乎误解了如何从记忆中阅读。您应该使用la将array1的地址加载到$a0中:

$a0现在可以说是指向array1的第一个元素。要阅读该元素,请使用lw,因为每个元素都是单词:

要使$a0指向下一个元素,请将单词的大小添加到$a0:


现在再做一次lw$t0,$a0将得到第二个元素,依此类推。

请通过编辑您的问题发布您的代码
la  $a0, array1
lw $t0, ($a0)
addiu $a0, $a0, 4