Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 嵌套for循环、MIPS程序集中的数组_Arrays_Loops_Assembly_Mips - Fatal编程技术网

Arrays 嵌套for循环、MIPS程序集中的数组

Arrays 嵌套for循环、MIPS程序集中的数组,arrays,loops,assembly,mips,Arrays,Loops,Assembly,Mips,我得到了要在MIPS程序集中实现的以下C代码 for(i=0; i<16, i++){ for(i=0; j<16, j++){ C[i][j] = A[i][j] = B[j][i] } } 正在加载计数器: addi $t0, $t0, 16 move $t1, $zero move $t2, $zero la $t3, A la $t4, B la $t5, C 和[i][j]的逻辑,使用公式基+字长*(行*最大大小+列): sllv $t6,

我得到了要在MIPS程序集中实现的以下C代码

for(i=0; i<16, i++){
  for(i=0; j<16, j++){
    C[i][j] = A[i][j] = B[j][i]
  }
}
正在加载计数器:

addi $t0, $t0, 16

move $t1, $zero
move $t2, $zero

la $t3, A
la $t4, B
la $t5, C
和[i][j]的逻辑,使用公式基+字长*(行*最大大小+列)

    sllv $t6, $t0, $t1 #Row, shift 16 by current counter -> 32 -> 64..
    addu $t6, $t6, $t2 #Column, add column counter.
    sll $t6, $t6, 2 #Shift entire count by word length.
    addu $t6, $t6, $t3 #Add A base address.
    lw $t7, ($t6) #Load word from that address.
完整代码:

    addi $t0, $t0, 16

    move $t1, $zero
    move $t2, $zero

    la $t3, A
    la $t4, B
    la $t5, C

First:
    bge $t1, $t0, Exit
        Second:
            bge $t2, $t0, Continue

            ###

            #Zero out counters first.
            move $t6, $zero
            move $t7, $zero
            move $t8, $zero
            move $t9, $zero

            sllv $t6, $t0, $t1 #Row, shift 16 by current counter -> 32 -> 64..
            addu $t6, $t6, $t2 #Column, add column counter.
            sll $t6, $t6, 2 #Shift entire count by word length.
            addu $t6, $t6, $t3 #Add A base address.
            lw $t7, ($t6) #Load word from that address.

            sllv $t7, $t0, $t2 #Row, shift 16 by current counter -> 32 -> 64..
            addu $t7, $t7, $t1 #Column, add column counter.
            sll $t7, $t7, 2 #Shift entire count by word length.
            addu $t7, $t7, $t4 #Add B base address.
            lw $t8, ($t7) #Load word from that address.

            addu $t9, $t7, $t8 #add A and B results.

            addu $t7, $t6, $t5 #add C base address, reuses $t7, copies $t6 from *A* array.

            sw $t9, 0($t7)  #store above result to C.

            ###

            addi $t2, $t2, 1
        j Second
    Continue:
    addi $t1, $t1, 1
    j First
Exit:

我收到一个错误的地址错误,但我似乎无法找出错误所在。

至少有三个错误:

  • 您正在覆盖
    $t6
    ,其偏移量应为A和C,基址为A
  • 您正在覆盖
    $t7
    ,它应该包含地址为B[j][i]的A[i][j]的内容
  • 您计算错了行偏移量。应该将行移动4次(实际上是行乘以16),而不是移动16次
你可以改变

sllv $t6, $t0, $t1 #Row, shift 16 by current counter -> 32 -> 64..
   ...
addu $t6, $t6, $t3 #Add A base address.
lw $t7, ($t6) #Load word from that address.
   ...
sllv $t7, $t0, $t2 #Row, shift 16 by current counter -> 32 -> 64..
   ...
addu $t9, $t7, $t8 #add A and B results


嗨,cs2100同学
sllv $t6, $t0, $t1 #Row, shift 16 by current counter -> 32 -> 64..
   ...
addu $t6, $t6, $t3 #Add A base address.
lw $t7, ($t6) #Load word from that address.
   ...
sllv $t7, $t0, $t2 #Row, shift 16 by current counter -> 32 -> 64..
   ...
addu $t9, $t7, $t8 #add A and B results
sll $t6, $t1, 4   # Row
   ...
addu $t7, $t6, $t3 #Add A base address.
lw $t9, ($t7) #Load word from that address.
   ...
sll $t7, $t2, 4  # Row
   ...
addu $t9, $t9, $t8 #add A and B results.