Computer Systems Organization (Tietokoneen toiminta ) Summer -99

Exercise 5 (Friday 13.8. )


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?

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. Write a subroutine which copies the contents of n successive memory locations from one memory area (Source) into another memory area (Destin). Pass ther parametres Source, Destin and n in the stack. Write also a main program which copies the contents of one hundred memory locations beginning from the memory location Old to the memory area which begins from the memory location New.

4.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.

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