CS325 - Spring 2004 - NMG

February 14, 2004

Homework Assignment 3, corrected 2/17/04

Due Monday, 2/23/04 after class

Problems related to chapter 4. This is a mixture of problems from the end of chapter 4 with modifications and some other problems.

1. (Based on Text Prob. 4.14) (5 points):

What is a main difference between a number as it is defined in a computer and a “real world” number?

Given the bit pattern: 1000 1111 1110 1111 1100 0000 0000 0000 (spaces inserted for readability). What does it represent assuming that it is:

(a)a two’s complement integer?

(b)an unsigned integer?

(c )a single precision floating point number?

(d)a MIPS instruction?

2. (5 points) Using the IEEE 754 standard notation, show the MIPS binary floating-point formats in single precision and double precision for 10 (base 10).

3. (5 points) This exercise is similar to 2 above, but this time replace the number 10 (base 10) with 10.5 (base 10).

4. (5 points) Why doesn’t MIPS have a subtract immediate instruction?

5. (15 points) Find the shortest sequence of “essential” MIPS instructions to determine the absolute value of a two’s complement integer. This is essentially translating the following pseudo instruction (accepted by the MIPS assembler). See p. A-55.

abs $10, $11

Code this pseudo instructions using the MIPS subset given in chapter 3 and 4 (summarized on the back cover of the text). Using “essential instructions” does not apply to setup of the registers or exiting the routine ( about 4 instructions). Test it with SPIM and submit appropriate hardcopy of the screens.

6. (Text 4.17) (20 points) - Find the shortest sequence of “essential” MIPS instructions to determine if there is a carry out from the addition of two registers, say $11 and $12. Place a 0 or 1 in register $10 if carry out is 0 or 1 respectively.

My solution resulted in 7 instructions in the essential part of the program (not including setup of the registers or exiting the routine, etc.). You get full credit if you do the essentials in 7 instructions and an extra point if you do better than 7! Test it with SPIM and submit appropriate hardcopy of the screens.

7. (Text 4.18) - (25 points) Find the shortest sequence of “essential” MIPS Instructions to perform double precision integer addition. Assume that one 64-bit, two’s complement integer is in register $12 and $13, and another is in registers $14 and $15. The sum is to be placed in registers $10 and $11. In this example, the most significant word of the 64-bit integer is found in the even-numbered registers, and the least significant word is found in the odd-numbered registers....

Use the results of Problem 4.17. Test it with SPIM and submit appropriate hardcopy of the screens.

8. (Text 4.23) (10 points) - The ALU supported set on less than (slt) using just the sign bit of the adder. Let’s try a set-on-less-than operation using the values -7 and 6 (both base 10). To make it simpler to follow the example, let’s limit the binary representations to 4 bits: 1001 and 0110 (both base 2). With this binary representation the subtraction: -7 - (+6) in our binary representation would be:

1001 - 0110 = 1001 + 1010 = 0011, a positive number.

This result would suggest that -7>6, which is clearly wrong. Hence, we must factor in overflow in the decision. Modify the 1-bit ALU in Fig. 4.17 on page 238 to handle slt correctly. You may make your changes on a photocopy of this figure to save time.

9. (Text 4.22) (10 points) - Some Computers have explicit instructions to extract an arbitrary field from a 32-bit register and place it in the least significant bits of a register. The figure below shows the desired operation:
register $16
bit position: 31 j i 0

31 – j bits / j – i bits / i + 1 bits

|______|
|
|__copy______

register $17 

32 – (j – i) bits / j – i bits

Find the shortest “essential” sequence of MIPS instructions that extracts a field for the constant values i = 7 and j = 19 from register $16 and places it in register $17 (least significant place). Hint: It can be done in two instructions.