Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Rearrange the code instructions to avoid stalls due to data hazards and wasted cycles. Hints: rename registers, remove instructions, or duplicate instructions for efficiency. (Duplicating
Rearrange the code instructions to avoid stalls due to data hazards and wasted cycles.
Hints: rename registers, remove instructions, or duplicate instructions for efficiency. (Duplicating instructions can be very useful in setting up the first or last loop pass.) You must have branch delay slots at the appropriate points, but you may fill them with useful work.
# This code copies data values into a destination array. # The data values are copied from either the 'left' #array or the right array. # For each element position, a "Selector' array tells us which #value to copy into the destination array. # Assume $a0 is selector addr # Assume Sal is left addr #Assume Sa2 is right addr # Assume Sa3 is dest addr # $t0 is an index for keeping an array index # There are 1,000 elements in each ar ray nor $t0, $zero, $zero # set index to -1 j LoopTest nop # Branch delay slot (assume jumps also need it Loop: sll $t1, $te, 2 add \t2, $a0, St1 Multiply the index by 4, we'll use it several places # Compute the selector address # Load the value from the selector array beq $zero, $t2, UseRightValue # If the selector is zero, copy from right array nop # Branch delay slot UseLeftValue $t2, $t3, $a1, $a3, $t1 $t1 # Compute the left address # Compute the dest address # Load the value from the left array # Store the value to the right array # Jump to LoopTest # Branch delay slot Cassume jumps also need it) add add sw $t2, 0CSt3) j LoopTest nop UseRightValue: add $t2, $a2, $t1 add $t3, $a3, $t1 lw $t2, 0CSt2) sw $t2, 0(St3) # Compute the right address # Compute the dest address Load the value from the right array # Store the value to the right array LoopTest addi $t0, St0, 1 slti $t1, $t, 1000 # See if the index is less than one thousand bne $zero, $t1, Loop # If we're not done yet, loop again nop # Advance the index Branch delay slot Exit: # Code is done at this point
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started