【问题标题】:Problem in translating from MIPS to C从 MIPS 转换为 C 的问题
【发布时间】:2011-08-10 14:02:52
【问题描述】:

我试图解决这个家庭作业,但无法提出解决方案。下面是问题,

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

add $t4, $zero, $zero
Loop:
add $t5, $t4, $t1
lw $t6, 0($t5)
add $t5, $t4, $t2
lw $t7, 0($t5)
add $t6, $t6, $t7
add $t5, $t4, $t0
sw $t6, 0($t5)
addi $t4, $t4, 4
slti $t5, $t4, 256
bne $t5, $zero, Loop
Also find the decimal value in the offset field of bne

说明。

这是我尝试过的,但我还没有找到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;
}

【问题讨论】:

    标签: architecture mips computer-architecture


    【解决方案1】:

    我觉得你想多了。

    这段代码的作用是这样的

    for (int i =0 ; i< 64; i++){
    
       A[i] = B[i] + C[i];
    
    }
    

    不打算解释原因,因为这个看起来很像是家庭作业。

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

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

    因此,循环将进行 256/4 次迭代,因为仅当 $t4 的内容大于 256 时,bne 才会失败(即不跳转)。

    【讨论】:

    • 语句中,add $t5, $t4, $t1, t1 未初始化为值。你能详细说明它会持有什么吗?
    • $t1 包含数组 B 的基地址。这是一个假设。在 mips 中,简单到 la $t1,arrayB
    猜你喜欢
    • 2012-05-06
    • 1970-01-01
    • 1970-01-01
    • 2020-07-28
    • 1970-01-01
    • 1970-01-01
    • 2019-05-13
    • 2013-09-28
    • 1970-01-01
    相关资源
    最近更新 更多