Computer Systems Organization (Tietokoneen toiminta ) Autumn -99

Exercise 4 (15.-19.11.)


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. Each of the memory location 100-200 contains the address of the previous memory location (location 200 contains 199, location 199 contains 198, ...). What is the result of the following instructions sequence?

       LOAD R2,@150 
       LOAD R3,10(R2)
       LOAD R2,@10(R2)  

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.

6. Write a TTK-91 assembly language subroutine random, which fills an array with random numbers between 1-n. The address of the array and n given as parameters are passed in the stack. To achieve randomness use the instruction SVC SP, =TIME, which gives the time in hours, minuts and seconds. Write also a main program that calls the subroutine to fill a lotto array of seven items with random numbers between 1 and 39.