CS560 Final Exam: May 9, 2006

James S. Plank

Answer All Questions - Note the point differential between questions, and make sure to allocate your time accordingly.


Question 1: 5 points

When you get to work one day, you find your co-worker Freddy bragging about the new C++ compiler he bought from the GSF (Gnaughty Software Foundation) for very little money. Freddy has already ordered the sysadmins to insall it on every machine in your department. Naturally, you question Freddy about the integrity of the compiler, and whether it is safe. His response:

Although Freddy's answer seems reasonable, you think about it a little more, and decide to visit your boss to explain just how unsafe Freddy's software purchase could be. What will you say to your boss?


Question 2: 16 points

Behold the following procedure:

int palcount(char *s, int len)
{
  char *e;
  int c;

  e = s+len-1;
  c = 0;
  while (s <= e) {
    if (*e == *s) c++;
    e--;
    s++;
  }
  return c;
}

The following is what happens when palcount is compiled into assembly code. (I'm using the generic jassem assembly code from CS360. If you don't know anything about jassem, just mentally map it to your favorite assmebly code. R0 and r1 are general purpose registers, fp is the frame pointer, g1 is a register whose value is always one, and gm1 is a register whose value is always minus one.

           palcount:        // s will be at fp+12, len will be at fp+16
L01:          push #8       // e will be at fp-4,  c will be at fp

L02:          ld [fp+12] -> %r0     // e = s + len-1
L03:          ld [fp+16] -> %r1
L04:          add %r0,%r1 -> %r0
L05:          add %r0,%gm1 -> %r0
L06:          st %r0 -> [fp-4]

L07:          st %g0 -> [fp]       // c = 0

           l1:
L08:          ld [fp+12] -> %r0   // while (s <= e) 
L09:          ld [fp-4] -> %r1
L10:          cmp %r0, %r1
L11:          bgt l0

L12:          ld [fp+12] -> %r0   // if (*e == *s)
L13:          ld [r0] -> %r0
L14:          ld [fp-4] -> %r1
L15:          ld [r1] -> %r1
L16:          cmp %r0 %r1
L17:          bne l2
          
L18:          ld [fp] -> %r0      // c++
L19:          add %r0, %g1 -> %r0
L20:          st %r0 -> [fp]

           l2:
L21:          ld [fp-4] -> %r0      // e--
L22:          add %r0, %gm1 -> %r0
L23:          st %r0 -> [fp-4]
              
L24:          ld [fp+12] -> %r0     // s++
L25:          add %r0, %g1 -> %r0
L26:          st %r0 -> [fp+12]
          
L27:          b l1

           l0:
L28:          ld [fp] -> %r0     // Return c
L29:          ret

Suppose instructions are 4 bytes long, integers and pointers are 4 bytes long, and pages are 1K bytes. Also suppose there is no cache or TLB to get in the way of our calculations.

Handy numbers: 1K = 0x400 in Hex. 1M = 0x100000.

Question 3: 11 points

Linus Torvalds gives his 10-year old grandson, Jimus, a miniature computer for his birthday. Although the computer comes with RedHat, Jimus is dissatisfied because RedHat uses a single-level page table. Jimus decides to write his own operating system, Jimux, which will use a two-level paging scheme.

Jimus' computer has the following features:

Suppose Jimus is running an executable with the following address layout:

Answer the following questions:

Note, 256 = 0x100 in hex.

Question 4: 6 points

Explain file organization when a file allocation table is used to store files on disk. Include in your explanation what kind of caching should be used for performance, and how this caching improves performance of both sequential reads/writes and random-access reads/writes.