Computer composition and design work04 ——fifth verson

Computer Composition and Design Homework 4

2.26

Consider the following MIPS loop:

    LOOP:   slt $t2, $0, $t1    # 0<t1则t2=1 else 0
    beq     $t2, $0, DONE       # t2==0则跳转到DONE
    subi    $t1, $t1, 1         # t1 = t1 - 1
    addi    $s2, $s2, 2         # s2 = s2 + 2
    j       LOOP                # 跳到LOOP
    DONE:

2.26.1 [5] <§2.7> Assume that the register $t1 is initialized to the value 10. What is the value in register $s2 assuming $s2 is initially zero?

s 2 = 20 s2=20 s2=20

2.26.2 [5] <§2.7> For each of the loops above, write the equivalent C code routine. Assume that the registers $s1, $s2, $t1, and $t2 are integers A, B, i, and temp, respectively

转换成等效的C语言为

int i = 10, B = 0;
while(i > 0)
{
   
    i--;
    B+=2;
}

如果需要一一对应的话

int B = 0;
for(int i = 10; (A = i > 0); i--)
{
   
    //这里的判定条件是先让 i>0赋值给A再由A判定
    B += 2;
}

2.26.3 [5] <§2.7> For the loops written in MIPS assembly above, assume that the register $t1 is initialized to the value N. How many MIPS instructions are executed

N每次成功-1说明做了5个语句,N==0执行第二行语句进行跳转
所以应该为
N ∗ 5 + 2 N*5+2 N5+2


2.27

[5] <§2.7>
Translate the following C code to MIPS assembly code. Use a minimum number of instructions. Assume that the values of a, b, i, and j are in registers $s0, $s1, $t0, and $t1, respectively. Also, assume that register $s2 holds the base address of the array D.

for(i=0; i<a; i++)
    for(j=0; j<b; j++
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值