Question: Exercise 2.18 For these problems, the table holds some C code. You will be asked to evaluate these C code statements in MIPS assembly code.
Exercise 2.18 For these problems, the table holds some C code. You will be asked to evaluate these C code statements in MIPS assembly code.
a. for(i=0; i<10; i++)
a += b;
b. while (a < 10){
D[a] = b + a;
a += 1;
}2.18.1 [5] <2.7> For the table above, draw a control-fl ow graph of the C code.
2.18.2 [5] <2.7> For the table above, translate the C code to MIPS assembly code.
Use a minimum number of instructions. Assume that the value
a, b, i, j are in registers $s0, $s1, $t0, $t1, respectively. Also, assume that register $s2 holds the base address of the array D.
2.18.3 [5] <2.7> How many MIPS instructions does it take to implement the C code? If the variables a and b are initialized to 10 and 1 and all elements of D are initially 0, what is the total number of MIPS instructions that is executed to complete the loop?
For these problems, the table holds MIPS assembly code fragments. You will be asked to evaluate each of the code fragments, familiarizing you with the different MIPS branch instructions.
a. addi $t1, $0, 100 LOOP: lw $s1, 0($s0)
add $s2, $s2, $s1 addi $s0, $s0, 4 subi $t1, $t1, 1 bne $t1, $0, LOOP
b. addi $t1, $s0, 400 LOOP: lw $s1, 0($s0)
add $s2, $s2, $s1 lw $s1, 4($s0)
add $s2, $s2, $s1 addi $s0, $s0, 8 bne $t1, $s0, LOOP 2.18.4 [5] <2.7> What is the total number of MIPS instructions executed?
2.18.5 [5] <2.7> Translate the loops above into C. Assume that the C-level integer i is held in register $t1, $s2 holds the C-level integer called result, and $s0 holds the base address of the integer MemArray.
2.18.6 [5] <2.7> Rewrite the loop in MIPS assembly to reduce the number of MIPS instructions executed.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
