hw1_sol_rev2

hw1_sol_rev2 - K. Olukotun / M.T. Le Winter 2003-2004...

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

View Full Document Right Arrow Icon
K. Olukotun / M.T. Le Handout #13 Winter 2003-2004 EE108b EE108b -- Problem Set #1 Solutions (Total 20 points) 1. (Total 10 points) The following code fragment processes an array and produces two values in registers $v0 and $v1: add $a1, $a1, $a1 add $a1, $a1, $a1 add $v0, $zero, $zero add $t0, $zero, $zero outer: add $t4, $a0, $t0 lw $t4, 0($t4) add $t5, $zero, $zero add $t1, $zero, $zero inner: add $t3, $a0, $t1 lw $t3, 0($t3) bne $t3, $t4, skip addi $t5, $t5, 1 skip: addi $t1, $t1, 4 bne $t1, $a1, inner slt $t2, $t5, $v0 bne $t2, $zero, next add $v0, $t5, $zero add $v1, $t4, $zero next: addi $t0, $t0, 4 bne $t0, $a1, outer Assume that: The array consists of 5000 indexed 0 through 4999 Its base address is stored in $a0 Its size (5000) is stored in $a1 a. (2 points) Describe in one sentence what this code does. Specifically, what will be returned in $v0 and $v1? The code determines the most frequent word appearing in the array and returns it in $v1  and its multiplicity in $v0. 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
K. Olukotun / M.T. Le Handout #13 Winter 2003-2004 EE108b b. (3 points) What is the total number of instructions that are executed in this piece of code? Briefly explain the number of instructions executed in each loop (e.g. There are 5 instructions that are executed once before loop outer , there are 8 instructions in loop inner that are executed 10 times, etc.). First, we ignore the 4 instructions before the loops. Next we consider the outer loop, it: iterates 5000 times has 4 instructions before the inner loop has 6 instructions after the inner loop in the worst case. Thus, the number of instructions for the outer loop is: (4 + 6) instructions/iteration x 5000 iterations = 5 x 10 4 instructions Now we examine the inner loop, it: has 6 instructions per iteration repeats 5000
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/18/2011 for the course EE 108A taught by Professor Dally during the Winter '04 term at Stanford.

Page1 / 5

hw1_sol_rev2 - K. Olukotun / M.T. Le Winter 2003-2004...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online