hw1sol - EE108B Spring 2003-2004 Prof. Kozyrakis EE108b -...

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

View Full Document Right Arrow Icon
EE108B Prof. Kozyrakis Spring 2003-2004 EE108b -- Problem Set #1 Solutions (Total 100 points) This homework assignment helps you to be familiar with MIPS assembly language. A full reference guide for MIPS instructions is available in section A.10 (Appendix A) of the textbook. A short summary of MIPS instructions is available on the back cover page. Problem 1 [Total 40 points]: The following code fragment processes an array and produces two values in registers $v0 and $v1: add $v0, $a1, $zero add $a1, $a1, $a1 add $a1, $a1, $a1 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, $v0, $t5 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. [8 points] Describe in one sentence what this code does. Specifically, what will be returned in $v0 and $v1? The code determines the least 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
EE108B Prof. Kozyrakis Spring 2003-2004 b. [12 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 in the worst case repeats 5000 × 5000 times Thus, the number of instructions for the inner loop is: 6 instructions/iteration x (5000 x 5000) iterations = 150 x 10 6 instructions The total number of instructions that are executed in this piece of code is: 5 x 10 4 + 150 x 10 6 ~ 150 x 10 6 instructions c. [8 points] Assume that the code fragment is run on a machine with a 500-MHz clock that requires the following number of cycles for each instruction:
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.

Page1 / 8

hw1sol - EE108B Spring 2003-2004 Prof. Kozyrakis EE108b -...

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