csse232_hw2_soln

csse232_hw2_soln - Fall 2009-2010 CSSE 232 CSSE 232...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Fall 2009-2010 CSSE 232 CSSE 232 – Computer Architecture I Rose-Hulman Institute of Technology Computer Science and Software Engineering Department Homework 2 Solutions 1. (10 points) Original: Loop: sll $t1, $s3, 2 # $t1 = 4*i add $t1, $t1, $s6 # $t1 = address of save[i] lw $t0, 0($t1) # $t0 = save[i] bne $t0, $s5, Exit # exit if save[i] != k addi $s3, $s3, 1 # i = i+1 j Loop # go to Loop Exit: #inst = 6 × # iterations + 4 = 64 Optimization 1: Loop: sll $t1, $s3, 2 # $t1 = 4*i add $t1, $t1, $s6 # $t1 = address of save[i] lw $t0, 0($t1) # $t0 = save[i] addi $s3, $s3, 1 # i = i+1 beq $t0, $s5, Loop # loop if save[i] == k addi $s3, $s3, -1 # fix i Exit: #inst = 5 × # iterations + 6 = 56 Optimization 2 sll $t1, $s3, 2 # $t1 = 4*i Loop: add $t1, $t1, $s6 # $t1 = address of save[i] lw $t0, 0($t1) # $t0 = save[i] addi $t1, $t1, 4 # $t1 = 4(i+1) beq $t0, $s5, Loop # loop if save[i] == k srl $s3, $t1, 2 # i = $t1/4 addi $s3, $s3, -1 # fix i Exit: #inst = 4 × # iterations + 7 = 47 20 October 2009 Page 1
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Fall 2009-2010 CSSE 232 2. (10 points) Let add , addi and sll be type A instructions and lw and bne be type B instructions. There are 4 type A instructions before the outer loop. The outer loop is executed 2500 (or $a2
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern