Computer Systems Organization (Tietokoneen toiminta ) Summer -99

Exercise 4 (11.8. )


1. Answer the following questions:
a) Why is the environment pointer FP needed? How is it used?
b) How is the stack used with subroutines ? How else could parameters be passed?
c) What operations should be carried out in conjunction with a subroutine call?
d) Which of these operations are automatically done by the CALL and EXIT operations?
e) What is the difference between call-by-value and call-by-reference? How do functions and procedures differ? What are methods?

2. Four bit strings were found from the main memory of the Koksi simulator. Below they are represented as hexadecimal numbers.

    01 A0 00 A0
    18 47 00 01
    13 31 FF FF
    02 80 FF FE
Give the instructions in TTK-91 assembly language (hint: make a conversion into bit strings at first). What do the instructions do?

3. Write the statements below using the TTK-91 assembly language. Remember to encode also the instructions for static memory allocation, i.e. the necessary DC and DS instructions.

         int lkm = 77; 
         int Summa, i, j; 
         int Taulu[lkm]; 

         if (i > j) i = -1 else  i = 54321; 

         Summa = 0; 
         for (i = lkm/2; i > 0; i--)   Summa = Summa + Taulu[i]; 

         Summa = 0; 
         do {  Summa = Summa +360} 
               while (Summa >= j); 

4. Write an assembly language subprogram which swaps the values of its two parameters:

   
                   temp = X; 
                   X =  Y; 
                   Y =  temp; 
Pass the parameters in an activation record and write a simple main program to do the calling. In addition, draw a picture of the stack.

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