CS/COE 447 Homework 2 Due Wednesday February 21, 2007 ====================================================== PLEASE BE SURE TO INCLUDE YOUR NAME ON YOUR ANSWERS. Please submit directly to the grader's mailbox: Grader: Michel Hanna - 6th floor mail room, SENNOTT SQUARE -------------------------------------------------------------------- (1)[10pts] Exercise 2.6 -------------------------------------------------------------------- (2).A[5pts] (based on Exercise 2.14) The MIPS translation of the C segment while (save[i] == k) i += 1; on page 74 executes both a conditional branch instruction and an unconditional jump instruction each time through the loop. Only poor compilers would produce code with this loop overhead. Rewrite the assembly code so that it uses at most one branch or jump each time through the loop. **Don't make any other changes to the code.** Assuming the number of iterations of the loop is 10, how many instructions are executed by the original version, and how many instructions are executed by your new version? Assume: $s3 -- i $s5 -- k $s6 -- base address of the array Original Code: loop: sll $t1,$s3,2 add $t1,$t1,$s6 lw $t0,0($t1) bne $t0,$s5,exit addi $s3,$s3,1 j loop exit: (2).B[5pts] Make your code even more efficient, by initializing $t1 to the address of array[i] before the loop, and then replacing the first two instructions of the loop by one instruction. How many total instructions are executed (including your new initialization), assuming that the number of iterations of the loop is 10? -------------------------------------------------------------------- (3)[10pts] Exercise 2.30 -------------------------------------------------------------------- (4)[10pts] Exercise 2.31 -------------------------------------------------------------------- (5)[10pts] Exercise 2.37 -------------------------------------------------------------------- (6)[30pts] Exercises 3.1,3.2,3.3,3.4,3.5,3.6 -------------------------------------------------------------------- (7)[10pts] Exercise 3.7 Include comments explaining how your code segment accomplishes the task. Your comments should show you understand your solution. -------------------------------------------------------------------- (8)[10pts] Exercise 3.10 Note that this method can be used to detect unsigned overflow. --------------------------------------------------------------------