CS611
Programming Assignment 5
Fall 1998


Extend the sim611 virtual machine by providing C implementations of the following operations: add (ADDF), negate (NEGF), compare (CMPF), and clear (CLRF).

The floating point data type contains 16 bits. Bit 15 is the sign bit. Bits 14 through 10 are the exponent. Bits 9 through 0 are the significand.

If the sign bit is set, the floating point number is negative. If the sign bit is clear, the floating point number is non-negative.

The exponent is a biased exponent. Subtract 15 from the stored exponent to get the actual exponent. A stored exponent of all zeros indicates that the floating point number containing the exponent has the value zero.

Floating point numbers are normalized to have one digit to the left of the radix point. Since this digit must always be one, it is not stored in the significand.

The ADDF (2C) opcode should be implemented with two extra bits on the right for better rounding results. This opcode takes two registers operands and is a 2-byte instruction: ADDF Ri,Rj : Ri <- Ri + Rj. When normalizing, fill with 0 bits from the right, if necessary. After normalizing, if the two extra bits are 10 or 11 then round up by adding 1 to the rightmost bit position of the result.

If the result of an ADDF instruction overflows or underflows, then the behavior is undefined. That is, it is the user's responsibility to avoid overflow and underflow. If they occur, then the emulation code can do whatever it wants. There are no particular requirements for how the emulation code should respond in these exceptional cases.

The NEGF (2D) opcode should simply flip the sign bit in the single register operand. It is a 2-byte instruction: NEGF Ri : Ri <- -Ri.

The CMPF (2E) opcode should set the C0 and C1 bits of the PSB in the same manner that the CMP instruction does for integer types. This opcode takes two registers operands and is a 2-byte instruction: CMPF Ri,Rj : C0 <- 1 if Ri == Rj; C0 <- 0 otherwise; C1 <- 1 if Ri < Rj, C1 <- 0 if Ri > Rj.

The CLRF (2F) opcode should clear all bits in the single register operand. It is a 2-byte instruction: CLRF Ri : Ri <- 0.0.

Each floating point opcode will be worth 25 points (but they are not of equal difficulty!).

You should implement the floating point opcodes by completing the function DoFloatingPoint in the file fp.c in the directory ~cs611/public/prog5. Use the distributed Makefile to link with the distributed exec.o, which contains a solution to Program 4.

You may lose points if your program is not properly structured or adequately documented.

Your programs will be graded using an Alpha machine (e.g. alberti) so be sure to test in that environment.

Your programs should be submitted for grading from either alberti, hopper, or christa. To turn in this assignment, type:

~cs611/bin/submit prog5 fp.c

Notes:

Submissions can be checked by typing:

~cs611/bin/scheck prog5

To receive full credit for the assignment, you must turn in your files prior to 8am on Monday November 16. Late submissions will be accepted at the penalty of 5% per day up to one week late.

Remember: as always you are expected to do your own work on this assignment.


Last modified on October 19, 1998.

Comments and questions should be directed to pjh@cs.unh.edu