Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

6. [40 points] Consider the following MIPS code ADDI $11, s0, 3 2. LOOP: LW $1,

ID: 3753980 • Letter: 6

Question

6. [40 points] Consider the following MIPS code ADDI $11, s0, 3 2. LOOP: LW $1, 0($2) LW $13, 0 (S3) ADD $4, $13, $1 SLL $4, $4, 2 SW $4, 0 ($5) ADDI $2, $2, 4 ADDI $3, $3, 4 ADDI $5, $5, 4 ADDI $1, $11, -1 BNE $11, $0, LOOP ADD $11, $11, $11 10. 12 EECE 459: Hardware Design Fall 2018 Due 09/26/2018 a. List all RAW hazards in this code (ignore hazards across loop iterations). Instruction 1 Instruction 2 b. Assume the base address in memory for arrays A, B and Care stored in registers $2 3 and S5, respectively. Using high-level language or pseudocode, describe what the code is doing in terms of the three arrays? c. What is the final value of register $11?

Explanation / Answer

a. RAW hazard occurs between two immediate instructions having Read after Write dependency. So we will mention such hazard where Instruction 1 is writing something into the register from which Instruction 2 is reading. The set of such RAW dependency are:-

b.  

First instruction is assigning value 3 in register $11 which is acting as a counter of number of times, the loop will iterate. Hence the loop will iterate upto 3 times.

The 2nd and 3rd instruction is assigning the value stored at particular index(index intialized to zero) of array B and C into register $1 and $13 respectively.

Instruction 4 is adding the value of register $1 and $13 into register $4.

Instruction 5 is multiplying the value of $4 by 4 since SLL $4,$4,2 will shift the register $4 content leftwards by 2 bit which is equivalent to multiplying by 4 and then the result is stored in $4.

Instruction 6 is storing the resulf of this operation into array C.

Then instruction 7,8 and 9 is increment the index of each array by 1 since each word has size 4 byte and adding 4 will increment to next index.

Instruction 10 is decrementing the counter by 1 and instruction 11 is checking the branching condition. So the loop will continue till the value of register $11 is not equal to 0. Instruction 12 ADD $11,$11,$11 will not add any value to $11 since it is set to zero.

Hence the high level code is as below :-

counter = 3

i = 0;

while(counter != 0)

{

temp = A[i] + B[i]

temp = 2*temp;

C[i] = temp;

i++ ;

counter-- ;

}

c. The loop will keep on iterating until register $11 value will be decremented to zero. So final value of $11 will be zero. The next instruction ADD $11,$11,$11 will not add any value to $11 since it is set to zero.

d.  First instruction is assigning value 3 in register $11 which is acting as a counter of number of times, the loop will iterate. Hence the loop will iterate upto 3 times.

Please raise another request for solving part e,f,g and h.

Register Instruction 1 Instruction 2 $13 3 4 $4 4 5 $4 5 6 $11 10 11