Please do all three parts and give answer in detail. Consider the following C-co
ID: 3562962 • Letter: P
Question
Please do all three parts and give answer in detail.
Consider the following C-code fragment:
for (i=0; i<10; i++)
{
a[i] = b[i] + c[i];
}
Assume that
- a, b, and c are arrays of 32-bit words,
- The machine code for this fragment is stored in memory starting from location 00000100 Hex.
a- Convert this code to MIPS. You must provide the numeric offset for each branch or jump instruction that you use.
b- Assume that the CPIs for MIPS instructions are as listed below:
a. lw : 5 cycles
b. R-type, addi, sw, and other immediate Arithmetic instruction : 4 Cycles
c. beq, bne, and j: 3 cycles
How many clock cycles does it take to execute the C-code fragment?
c- Assume that this code is executed by a 2.5 GHz system. What is the cpu execution time for the code?
Explanation / Answer
down vote favorite
Here's the C code:
Here's my take at converting into MIPS:
I understand that in a basic while loop such as: i = $s1, 5 = $s3
I'm just having trouble, or having a hard time comprehending a slightly more difficult loop where sum+= A[i++]; and sum*= 2; are introduced.
down vote favorite
Here's the C code:
int A[10]; int sum = 0; int i = 0; while (i<10){ sum += A[i++]; sum *= 2; } Here's my take at converting into MIPS:
**Reg. Allocation Table: A = $s1 sum = $s2 i = $s3 10 = $s4** loop: beq $s3, $s4, endloop "here's where i get stuck, inside the while loop." j: loop endloop:
I understand that in a basic while loop such as: i = $s1, 5 = $s3
i=0; while(i != 5) i=i+1; addi $s1, $zero, 0 #i=0 loop: beq $s1, $s3, endloop add $s1, $s1, 1 j loop: endloop:
I'm just having trouble, or having a hard time comprehending a slightly more difficult loop where sum+= A[i++]; and sum*= 2; are introduced.