University of California at Berkeley
College of Engineering
Department of Electrical Engineering and Computer Science

CS61C, Spring 2010

HW 3

[TA] Eric Chang - And other, more ancient ones

Due Thursday, Feb 18, 2010 @ 11:59:59pm

Last updated Wednesday, Feb. 17, 2010 @ 6:00pm

Goals

This assignment will give you practice of C and MIPS. By the end of the homework assignment, you should be able to translate C to MIPS code and back with ease.

Submitting your Solutions

Submit your solution by creating a directory named hw3 that contains files named hw3.txt. (Note that capitalization matters in file names; the submission program will not accept your submission if your file names differ at all from those specified.) From within that directory, type "submit hw3". This is not a partnership assignment; hand in your own work.

Problem 1

Do questions 2.15.1, 2.15.2, 2.15.4, and 2.15.5 (both part a and b) from the book (4th edition)

Problem 2

Do question 2.18.5 (again, both part a and b) from the book

Problem 3

Show the single MIPS instruction or minimal sequence of instructions for the following C statements:

Assume that
a
corresponds to register
$t0
and
b
corresponds to register
$t1
.
Also assume that the array
x
has a base address of 6,400,000ten that's stored in the
$t3
register.

Problem 4

Lets try a MIPS->C question. In this problem,
$a0
is an integer argument while
$a1
is a pointer to (ie: the address of) a large array. The value in
$a0
can be any integer and the size of the array that
$a1
points to is big enough (as long as you don't dereference memory before $a1, you won't be accessing memory that isn't yours) for the code to work correctly.

Add comments to the code and then briefly explain what it does. Specifically, what is in the array as the function returns?

Also, convert this MIPS code to C (you may find it easier to understand if you do this first!).

addi$t1 $zero 31
addi$t0 $zero 31
loop:srlv$t3 $a0 $t1
andi$t3 $t3 1
addi$t3 $t3 48
sub$t4 $t0 $t1
add$t2 $a1 $t4
sb$t3 0($t2)
beq$t1 $zero done
subi$t1 $t1 1
jloop
donesb$zero 1($t2)
jr$ra