Assume that X consists of three bits, X2 X1 X0. Write four logic functions that are true if and only if
Optional Exercise: Write a program that will accept a floating-point number from the user and which prints the binary representation of each field of the IEEE-754 encoding of the number, for both single-precision and double-precision representations. There must be no limit on the numbers the user types in other than the limits imposed by the iEEE-754 format itself.
I will accept this as the equivalent of doing one extra homework exercise until Halloween midnight.
Answers: 0x42F6E979 and 0x405EDD2F1A9FBE77. Solution: 123.456 is 7B.74BC6A7EF9DB22D... in hexadecimal. [Calculator trick: instead of multiplying by 2 to get each bit, multiply by 16 to get each hexadecimal digit of the fraction.] Move the binary point 6 places to the left, and you get: 1.111011011101001011110001101010011111101111100111011011001000101101 The leftmost 1 will be dropped when forming the encoded value; it's implicit. The single-precision exponent is 127 + 6, or 133 = 10000101 as an 8-bit binary number, so the answer in binary is: 0*100 0010 1*111 0110 1110 1001 0111 1001 (rightmost bit is rounded) I used '*' to separate the fields and blanks to separate the hex digits. The double-precision exponent is 1023 + 6 or 1029 = 10000000101 as an 11-bit binary number, and the answer in binary is: 0*100 0000 0101*1110 1101 1101 0010 1111 0001 1010 1001 1111 1011 1110 0111 0111 Again, the rightmost binary digit has been rounded up.
Note: The SPIM simulator (for Windows 3.x, Windows 95, or Windows NT) is available for download if you click here. That is a copy on Dr. Vickery's computer. You can go to the site mentioned in the textbook if you prefer, but it often seems to be too busy. You can try it if you click here.
Using the simulator is not required for this course, but if you do want to use it, follow these instructions:
The file you downloaded is named spimwin.exe, and is a
self-extracting zip file. Run it from Windows or using WinZip
(You can get WinZip for free
if you click here.) It will give you instructions for
setting it up to run on your computer. There will be an icon
for the executable file (pcSpim.exe). Before you run the
simulator, you should prepare an assembly language program
using any text editor you wish. I suggest that you create a
directory for your programs, perhaps a subdirectory of the one
where you installed pcspim. Use a .s
extension
for the assembly language file. Be sure the first statement of
your program has the label main: at the beginning. Here is a
sample program you can use that loads a word of data into
register 3, and stops:
main: lw $3, alpha # Load 123 into reg. 3 li $2, 10 # Setup to exit syscall # Exit .data alpha: .word 123 # Data to load .endRun the simulator, and use its "Window" menu to tile all the display windows. If your program uses the print routine described in Appendix A, be sure to display the "console" window too. Load your
.s
file using the File
menu, and then single-step through your program using the F10
key.
The Text Segment window shows the program as you wrote it on
the right, the equivalent "pure" assembly language in the
middle, the machine language to the left of that, and the
memory addresses for the program all the way to the left. The
assembly language you type may use standard mnemonics for
register names, and may use extended op code names; the pure
assembly language shows what these mnemonics and register names
are actually equivalent to. For example, the lw
instruction above is translated into a lui
instruction followed by a lw
instruction.
As you single step through the program, the Messages window will show each line of the Text Segment after it has been executed, and the Registers window will show you the contents of the CPU's registers as the program progresses.
Good luck with the simulator, it can be very instructive!
Note: Because of problems getting the textbook, I am giving the textbook exercises here: 2.10 We are interested in two implementations of a machine, one with and one without special floating-point hardware. Consider a program, P, with the following mix of operations: floating-point multiply 10% floating-point add 15% floating-point divide 5% Integer instructions 70% Machine MFP (Machine with Floating Point) has floating-point hardware and can therefore implement the floating-point operations directly. It requires the following number of clock cycles for each instruction class: floating-point multiply 6 floating-point add 4 floating-point divide 20 Integer instructions 2 Machine MNFP (Machine with N Floating Point) has no floating-point hardware and so must emulate the floating-point operations using integer instructions. The integer instructions all take 2 clock cycles. The number of integer instructions needed to implement each of the floating-point operations is as follows: floating-point multiply 30 floating-point add 20 floating-point divide 50 Both machines have a clock rate of 100 MHz. Find the native MIPS ratings for both machines. 2.11 If the machine MFP in Exercise 2.10 needs 300,000,000 instructions for this program, how many integer instructions does the machine MNFP require for the same program? 2.12 Assuming the instruction counts from Exercise 2.11, what is the execution time (in seconds) for the program in Exercise 2.10 run on MFP and MNFP? 2.13 Assuming that each floating-point operation counts as 1, and that MFP executes 300,000,000 instructions, find the MFLOPS rating for both machines in Exercise 2.10