CS61C Fall 2012 HW4

TA: Ravi Punj

Due Sunday, Sep 30, 2012 @ 23:59:59


This assignment is designed to give you some practice with IEEE 754 numbers and MIPS


Create a directory named “hw4” inside your working repository and put your solutions in a file named hw4.txt. It is important that you place your submission for hw4 inside this directory and not somewhere else, as when we pull submissions, we will look for your submission there. Then run these commands from inside the hw4 directory:

git add −A
git commit −m “hw4 submission”
git tag −f hw4
git push --tags origin master

Problem 1

What floating point numbers are represented by the following bit patterns? Give answer in decimal system, not scientific notation.

a) 0x00000000

b) 0xBFE00000

c) 0x7F800000

d) 0x40380000

Problem 2

Write a function in C that converts unsigned integers into a single precision floating point representation using only integer operations. Don’t worry about imprecision in rounding the mantissa.

float unsignedToFloat( unsigned int x ) {

	unsigned int result = 0;

	/* Your code here. Don’t use
	  “float” and “double” types! */

	/* read the result as float and return*/

	return *(float*)&result;

For example, if x = 357, it should return 357.0 and result = 0x43B28000.

Problem 3

What MIPS instructions are represented by the following bit patterns?

a) 0x02AA5A00

b) 0x21A8FFF9

c) 0xAF8B0008

d) 0x02298DE5

e) 0x31127001

f) 0x3D35FFFF

g) 0x36B5F2AB

Problem 4

Encode the following instructions into MIPS machine code:

Address   Machine code           Instruction

                     (fill in)        


0x400000                                 jal mul


0x401000                           mul: addu $a0, $a0, $a1

0x401004                                   addiu $a2, $a2, -1

0x401008                                   bne $a2, $0, mul

0x40100c                                   add $v0, $a0, $0

0x401010                                    jr $ra