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 Unpack3, which
stores three numbers to a memory segment as described below.
The subroutine has no return value, it receives its call parameters
via registers and it must keep all the values in all the registers unchanged.
You may assume that the parameters have reasonable values.
Register R3 contains a positive constant integer or zero.
Three digits -- a value from 000 to 999 -- are given in R4.
Depending of whether the value in R3 is zero, three numbers are
calculated according to and in the same order as the three digits in R4
as follows:
R3==0: | each digit becomes the same number 0..9 directly |
R3!=0: | each digit is multiplied by three and then the value in R3 is added to the product. |
call parameters memory after the call R3:0 R4:456 R5:100 ==> 100:4 101:5 102:6 R3:50 R4:103 R5:200 ==> 200:53 201:50 202:59 R3:80 R4:072 R5:355 ==> 355:80 356:101 357:86