Architecture 从MIPS到C的翻译问题

Architecture 从MIPS到C的翻译问题,architecture,mips,computer-architecture,Architecture,Mips,Computer Architecture,我试图解决这项家庭作业,但没能想出解决办法。下面是问题 将以下MIPS代码翻译成高级语言程序。 假设$t0、$t1和$t2包含数组A、B的基址 和C 指示 这是我尝试过的,但是我还没有找到256的位置 int *temp4 = 0; while(1) { *int temp5 = temp4 +B[0]; a: *int temp6 = temp5; temp5 = C[0] + temp4; *temp7 = temp5;

我试图解决这项家庭作业,但没能想出解决办法。下面是问题

将以下MIPS代码翻译成高级语言程序。 假设$t0、$t1和$t2包含数组A、B的基址 和C

指示

这是我尝试过的,但是我还没有找到
256
的位置

int *temp4 = 0;
while(1)
{
    *int temp5 = temp4 +B[0];
    a:
        *int temp6 = temp5;
        temp5 = C[0] + temp4;
        *temp7 = temp5;
        temp6 = temp6 + temp7;
        temp5 = temp4 + A[0];
        temp6 = temp5;
        temp4 += 4;
        if(temp5 < temp4)
            goto __;
        if(temp5 != 0)
            goto a;
}
int*temp4=0;
而(1)
{
*int temp5=temp4+B[0];
a:
*int temp6=temp5;
temp5=C[0]+temp4;
*temp7=temp5;
temp6=temp6+temp7;
temp5=temp4+A[0];
temp6=temp5;
temp4+=4;
如果(temp5
我认为你想得太多了

代码的作用是这样的

for (int i =0 ; i< 64; i++){

   A[i] = B[i] + C[i];

}
for(int i=0;i<64;i++){
A[i]=B[i]+C[i];
}
我不打算解释原因,因为这看起来很像是家庭作业

这是我尝试过的,但我还没有找到256的位置

你把事情搞混了。查看
slti
末尾的
i
?这意味着它使用中间操作数,在本例中为
256
。因此,如果
$t4
的内容低于256,则
slti$t5、$t4、256指令所做的是在寄存器
$t5
中设置
1
。否则,
$t5
将获得
0


因此,循环将需要256/4次迭代,因为只有当
$t4
的内容大于
256

时,
bne
才会失效(即不跳跃)

int *temp4 = 0;
while(1)
{
    *int temp5 = temp4 +B[0];
    a:
        *int temp6 = temp5;
        temp5 = C[0] + temp4;
        *temp7 = temp5;
        temp6 = temp6 + temp7;
        temp5 = temp4 + A[0];
        temp6 = temp5;
        temp4 += 4;
        if(temp5 < temp4)
            goto __;
        if(temp5 != 0)
            goto a;
}
代码的作用是这样的

for (int i =0 ; i< 64; i++){

   A[i] = B[i] + C[i];

}
for(int i=0;i<64;i++){
A[i]=B[i]+C[i];
}
我不打算解释原因,因为这看起来很像是家庭作业

这是我尝试过的,但我还没有找到256的位置

你把事情搞混了。查看
slti
末尾的
i
?这意味着它使用中间操作数,在本例中为
256
。因此,如果
$t4
的内容低于256,则
slti$t5、$t4、256指令所做的是在寄存器
$t5
中设置
1
。否则,
$t5
将获得
0


因此,循环将需要256/4次迭代,因为只有当
$t4
的内容大于
256

时,
bne
才会失效(即不跳转)。在语句中,add$t5、$t4、$t1、t1未初始化为值。你能详细说明它包含什么吗?
$t1
包含数组B的基址。这是一个假设。在mips中,就像在语句中添加$t5、$t4、$t1一样简单,t1没有初始化为值。你能详细说明它包含什么吗?
$t1
包含数组B的基址。这是一个假设。在mips中,简单到
la$t1,arrayB
int *temp4 = 0;
while(1)
{
    *int temp5 = temp4 +B[0];
    a:
        *int temp6 = temp5;
        temp5 = C[0] + temp4;
        *temp7 = temp5;
        temp6 = temp6 + temp7;
        temp5 = temp4 + A[0];
        temp6 = temp5;
        temp4 += 4;
        if(temp5 < temp4)
            goto __;
        if(temp5 != 0)
            goto a;
}