A RISC processor implements a subroutine call using a link register (i.e., the return address is saved in the link register).The cost of a call is 2 cycles and the return costs 1 cycle. If a subroutine is called from another subroutine (i.e., the subroutine is nested), the contents of the link register must be saved and later restored. The cost of saving the link register is 6 cycles and the cost of restoring the link register is 8 cycles. Assume that a certain instruction mix contains 20% subroutine calls and returns (i.e., 10% calls, 10% returns). The probability of a single subroutine call and return without nesting is 60%. The probability that a subroutine call will be followed by a single nested call is 40%. Assume that the probability of further nesting is vanishingly small. What is
the overall cost of subroutine calls? The average call of all other instructions is 1.5 cycles. What is the average number of cycles per instruction?
What will be an ideal response?
There are five possibilities: an instruction is not a subroutine call or return, it is a single call, it is a nested call, it is
a single return, it is a nested return. Note that when a subroutine is nested, it has the unnested call return plus
the extra save/return time. The probabilities and costs are:
You might also like to view...
Suppose you design a computer called the Big Looper 2000 that will never be used to call procedures and that will automatically jump back to the beginning of memory when it reaches the end. Do you need a program counter? Justify your answer.
What will be an ideal response?
Which of the following statements is true?
``` public class TestA { public static void main(String[] args) { int x = 2; int y = 20 int counter = 0; for (int j = y % x; j < 100; j += (y / x)) { counter++; } } } public class TestB { public static void main(String[] args) { int counter = 0; for (int j = 10; j > 0; --j) { ++counter; } } } ``` a. The value of counter will be different at the end of each for loop for each class. b. The value of j will be the same for each loop for all iterations c. Both (a) and (b) are true. d. Neither (a) nor (b) is true.