Spring 06 CS61C Homework 3

C and MIPS

Corresponding Reading


Create a directory named hw3 and copy all files from ~cs61c/hw/03/files to that directory. These files will help you finish question 1 to 4.


Question 1

Complete Exercise 2-3 on page 46 of K&R by filling in the code in q1.c.

Question 2

Rewrite the bitcount function shown on page 50 of K&R such that it doesn't use any conditional statements such as if, switch, ?: expression. Fill in the code in q2.c.

Question 3

Complete Exercise 6-5 on page 145 of K&R. See the comments in q3.c for return values of your undef function.

Question 4

Convert the MIPS code in from Exercise 2.29 of P&H into C statements. Then fill in the corresponding spaces in q4.c with your C statements so that it will produce the correct output. $a0, $a1 and $v0 contains the integers a and b and out respectively.

Question 5

Do Exercise 2.30 from P&H. Save your answer in a file called q5.txt.

Question 6

Complete P&H Exercise 2.32 and save your answer in a file called q6.txt.

Question 7

Complete P&H Exercise 2.33 and save your answer in a file called q7.s.

Question 8

Complete P&H Exercise 2.36 and save your answer in a file called q8.s.

Submission (Updated 2/7/06)

Save all your files (q1.c, q2.c, q3.c, q4.c, q5.txt, q6.txt, q7.s, q8.s) in a directory named hw3. From the directory hw3, run:

submit hw3