Computer Systems Organization (Tietokoneen toiminta ) Summer -99

Exercise 6 (Monday 16.8. )


1. Answer the following questions:
a) Why compilation is made in two phases?
b) Consider the process states:

2. Compile the following recursive program into TTK-91 machine language.

        static long Duo(int n) { 
            if n < 1 then return 1 else 
            return Duo(n-1)+n+1; 
         } 
Write also a main program, that calls method Duo.

3. Write an assembly program which consists of a function MValue and a main program. The function MValue has two parameters. The first one is the address of the first word of an array and the second is the size of the array. The array has been stored in the static data part of the program. The function returns the mean value of the integers in the array. The main program reserves 100 words for the array, reads the size of the array ( < 100) and the elements and calculates the mean value of the elements with the help of the function and outputs it.

4.Show using pictures how memory is allocated for two instances of the following Java-class. It is assumed that the allocation starts from location 10000 in the central memory and the size of a memory location is 32 bits. Integers are represented using 32 bits and boolean values by one bit.

               class DataStructures{
                     int i = 0;
                     static int j;
                     private int k; 
                     boolean [] A = new boolean[15000]; 
                     int[][] B = new int[4][3]};

5. Explain in detail the tasks of the CPU and the operating system when the time slice for the running process terminates. Your explanation should answer at least to the following questions:

6. When an interrupt has been handled, it's possible that the process which was running before the interrupt is not continued, at least not immediately. Give examples of this kinds of situations. On the other hand, when is it sensible to continue running the same process?