Assignment 10, due Nov 7

Part of the homework for 22C:60, Fall 2008
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

Remember to write your name on what you turn in! Homework must be turned in on paper and in class!

Homework

  1. Background: Consider the problem of designing class "rational". There are several possible implementations of rational numbers, so this is a polymorphic class. The potential implementations include fixed-point binary, perhaps using a 32-bit integer part and a 32-bit fractional part, floating point, perhaps using a 32-bit mantissa and a 32-bit exponent, as well as a 32-bit numerator and a 32-bit denominator for the classical rational representation. For short, we'll call these fixrat, floatrat and ratiorat.

    a) Enumerate the files you would plan on writing for an assembly language implementation the class rational and the subclasses listed above. Do not enumerate machine-generated files such as object files. Only list the files you would write directly. With each file, very briefly describe its contents. (0.4 points)

    b) Assume we are using a tag-descriptor implementation of polymorphism. Which of the above files would contain the declaration of the structure of the class descriptor used for operating on objects of type rational. (0.3 points)

    c) As in part b, assume we are using a tag-descriptor implementation of polymorphism. Which of the above files would contain the actual SMAL code to create a each of the class descriptors? (0.3 points)

  2. Background: Consider the problem of designing a floating point representation for the historic PDP-8 computer. This machine had a 12-bit word, so a practical floating point representation would use some multiple of 12 bit words for each number. Since the machine had no floating-point hardware, the fields of the floating point number should be aligned on word boundaries. Consider the following 36-bit floating point format:

    With this format, we have no hidden bits. The mantissa runs from 0.99999 on the positive side to -1.00000 on the negative side It would be sensible to normalize the fraction so that the absolute value of the mantissa is greater than or equal to 0.5. In this format, give the representation for each of the following decimal values: (0.2 points each)

    a) 1.0
    b) -10.0
    c) 100.0
    d) 0.1
    e) 0.01

  3. A problem: Consider the problem of computing the distance between two points a and b in the Cartesian plane. Each point is an ordered pair, so a is <ax, ay> Given that R3 contains ax, R4 contains ay, R5 contains bx and R6 contains by, write code to compute the straight-line distance from a and b in R3. Assume that your Hawk machine has a floating point coprocessor, and assume that the processor is initially off and that it is to be turned off when you are done. (1.0 points)