University of California at Berkeley

College of Engineering

Department of Electrical Engineering and Computer Science

 

 

EECS 61C, Spring 2005

 

HW 4

TA In Charge

Andy

Goals

This assignment will check your understanding of MIPS and Instruction Execution

Submitting Your Solution

Submit your solution online by 11:59pm on February 23. Do this by creating a directory named hw4 that contains a file named hw4.txt.  “hw4.txt” is a text file that you create containing your answers to the following questions.  (Note that capitalization matters in file names; the submission program will not accept your submission if your file name differs at all from those specified.) From within that directory, type “submit hw4”.

This is not a partnership assignment; hand in your own work.

 


1

The following code fragment processes two arrays and produces an important value in register $v0. Assume that each array consists of 2500 words indexed 0 through 2499, that the base addresses of the arrays are stored in $a0 and $a1 respectively, and their sizes (2500) are stored in $a2 and $a3, respectively. Add comments to the code and describe in one sentence what this code does. Specifically, what will be returned in $v0?

			sll		$a2, $a2, 2
			sll		$a3, $a3, 2
			add		$v0, $zero, $zero
			add		$t0, $zero, $zero
outer:			add		$t4, $a0, $t0
			lw		$t4, 0($t4)
			add		$t1, $zero, $zero
inner:			add		$t3, $a1, $t1
			lw		$t3, 0($t3)
			bne		$t3, $t4, skip
			addi		$v0, $v0, 1
skip:			addi		$t1, $t1, 4
			bne		$t1, $a3, inner
			addi		$t0, $t0, 4
			bne		$t0, $a2, outer

2

Assume that the code from problem 1 is run on a machine with a 2 GHz clock that requires the following number of cycles for each instruction:

add, addi, sll: 1 Cycle
lw, bne: 2 Cycles

In the worst case, how many seconds will it take to execute this code?


3

Show the single MIPS instruction or minimal sequence of instructions for this C statement:

b = 25 | a;


4

Given your understanding of PC-relative addressing, explain why an assembler might have problems directly implementing the branch instruction in the following code sequence:

here:			beq		$s0, $s2, there
...
there:			add		$s0, $s0, $s0

Show how the assembler might rewrite this code sequence to solve these problems.

5

Compute the decimal byte values that form the null-terminated ASCII representation of the following string:

A byte is 8 bits


Problems adapted from P&H