Computer Systems Organization (Tietokoneen toiminta ) Autumn 1999

Exercise 5 (22.-26.11. )


1. Answer the following questions:
a) What are the different phases included in the execution of a machine language instruction?
b) To what amount these phases could be performed simultaneusly / overlapping?
c) What situations cause interrupts? How is an interrupt noticed? What actions are taken in an interrupt situation?
d) Why is compilation made in two phases?
e) For what tasks are linkers and loaders needed?

2. Describe, showing the contents of the registers, how the following instructions are carried out. Draw some pictures.

    a) MUL  R2,@5 
    b) DIV  R2,@R5 
    c) SUB  R5,5(R5) 
    d) JPOS R5,100  

3. Would it be possible to use subprograms in the TTK-91 computer without the commands CALL and EXIT? That is, could you create and use activation records properly with the other TTK-91 commands? Explain how this would be possible or why it couldn't be done.

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. How could you represent large sets (like sets of integers for example) in the computer memory in an efficient way?

6. Below is a program that counts the Fibonaccin numbers (main program and a recursive subroutine; F0 = 1, F1 = 1, Fn = F(n-1)+F(n-2). Does the program function correctly? If not then fix it. If it works, simulate it. How many times is the function F actually called if m=3?


                 m   DS 1

           1: CountF IN    R1, =KBD            
                                               
           2:        STORE R1, m               
           3:        PUSH  SP, =0              
           4:        PUSH  SP, R1              
           5:        CALL  SP, F              
           6:        POP   SP, R2              
           7:        OUT   R2, =CRT            
                                               
                 N   EQU   -2                  
               F_RET EQU   -3                  
                                               
           8: F      LOAD  R1, N(FP)          
           9:        JNZER R1, *+4             
          10:        ADD   R1, =1                 
          11:        STORE R1, F_RET(FP)
          12:        JUMP  END
          13:        COMP  R1, =1
          14:        JNEQU *+3
          15:        STORE R1, F_RET(FP)
          16:        JUMP  END
          17:        LOAD  R2, R1
          18:        SUB   R2, =1
          19:        LOAD  R3, R2
          20:        SUB   R3, =1
          21:        PUSH  SP, =0
          22:        PUSH  SP, R2
          23:        CALL  SP, F
          24:        POP   SP, R2
          25:        PUSH  SP, =0
          26:        PUSH  SP, R3
          27:        CALL  SP, F
          28:        POP   SP, R3
          29:        ADD   R2, R3
          30:        STORE R2, F_RET(FP)
          31: END    EXIT  SP, =1