MIPS 中的双重条件 if 语句

Double condition if statements in MIPS

我正在将以下 C 代码转换为 MIPS,isIdent 函数似乎总是 return 0。

C: full code here

int isIdent (int m[N][N], int n)
{
    for (int row = 0; row < n; row++)
        for (int col = 0; col < n; col++)
            if (row == col && m[row][col] != 1)
                return 0;
            else if (row != col && m[row][col] != 0)
                return 0;
    return 1;
}

MIPS: isIdent code here Full code here

我试过改变 if 语句的位置,例如首先检查 rowcol 但是它似乎没有什么区别。任何帮助将不胜感激!

已找到solution!正如@CraigEstey 指出的那样,我必须做的实际上是从计算出的地址中获取值。

# m[row][col] = *(&m[0][0] + (row * N) + col)
mul $t0, $s2, $s1   # % <- row * N
add $t0, $t0, $s3   #    + col
li  $t1, 4
mul $t0, $t0, $t1   #    * sizeof(word)
addu    $t0, $s0, $t0   #    + &m[0][0]
lw  $a0, ($t0)      # actually fetch m[r][c] from memory

非常感谢大家:)