Homework # 9
Due: 2008/4/15

Big-Endian or Little-Endian ?

Modify the assembly language for the method Main.big_endian to test whether the machine you run SPIM on is big-endian or little-endian:

class Main : IO is
  big_endian() : Boolean := begin
    let test : Boolean := true; in
      if test then true else false fi
    end
  end;
  Main() begin
    if big_endian() then
      out_string("big endian\\n")
    else
      out_string("little endian\\n")
    fi
  end;
end;
(Of course this implementation always prints big endian; that's why you have to modify the assembly file!)

You will need to use the lb instruction to load a byte from a specific address to test endian-ness. Please

Analysis

Consider the following class (in primes.cl)

class Sieve : IO is
  prime : Integer;
  next : Sieve;
  ...
end;
  1. How much space does each Cool Integer object take (including the eye-catcher)?
  2. How much space does a Sieve object take? Include all its attributes and also including all the words making up the integer object it refers to, but not including the words for the next Sieve object.
  3. There are also the prototype objects and dispatch tables. How many of each of these are there in a running Cool program? If we have 1000 integer objects, how much space is taken up by integer dispatch tables? By memory words that have integer dispatch table pointers in them?
  4. On more sophisticated systems, no garbage collector tag is needed and the class tag and object size can be put into the (shared) dispatch table. Furthermore, an integer can be stored ``unboxed'', that is, instead of a pointer to an integer object, we simply store the bare integer.

    How much space would a Sieve object take if this method was used?

  5. If you had 64K to use for Sieve objects, how many could you store (1) assuming the existing Cool layout (2) assuming the optimized layout?
  6. Compile primes.cl using the -g option. What happens different when you run it? Explain!



John Tang Boyland 2008-04-10