Question

In: Computer Science

For many languages, activation records form a stack at runtime. They are pushed on call and...

  • For many languages, activation records form a stack at runtime. They are pushed on call and popped on return. How can allocation and deallocation for such a stack of activation records be implemented?
  • ​​​​​​​

Solutions

Expert Solution

Activation Records :

1.Modern imperative programming languages typically have local variables.

*Created upon entry to function.

*Destroyed when function returns.

2.Each invocation of a function has its own instantiation of local variables.

*Recursive calls to a function require several instantiations to exist simultaneously.

*Functions return only after all functions it calls have returned last-in-first-out (LIFO) behavior.

* A LIFO structure called a stack is used to hold each instantiation.

3.The portion of the stack used for an invocation of a function is called the function’s stack frame or activation record.

Stack
*Used to hold local variables.
*Large array which typically grows downwards in memory toward lower addresses,shrinks upwards.
*Push(r1):
stack_pointer--;
M[stack_pointer] = r1;
*r1 = Pop():
r1 = M[stack_pointer];
stack_pointer++;
*Previous activation records need to be accessed, so push/pop not sufficient.
– Treat stack as array with index off of stack pointer.
– Push and pop entire activation records.

Consider the following example,
let
function g(x:int) =
let
var y := 10
in
x+y
end
function h(y:int):int =
y + g(y)

in
h(4)
end

Step 1: h(4) called

Chunk of memory allocated on the stack in order to hold local variables of h. The activation record (or stack frame) of h is pushed onto the stack.

Step 2: g(4) called

Activation record for g allocated (pushed) on stack.

Step 3: g(4) returns with value 14

Activation record for g deallocated (popped) from stack.

Step 4: h(4) returns with value 18

Activation record for h deallocated (popped) from stack. Stack now empty.


Related Solutions

True/False 1. An automatic storage class variable is stored in the runtime stack 2. When a...
True/False 1. An automatic storage class variable is stored in the runtime stack 2. When a value parameter is passed to a function, the function called utilizes a copy of that parameter which is internal to the function called 3. When a reference parameter is passed to a function, the function called receives the memory address of that parameter and does not make a copy of it 4. Debug flags often control extra output to be printed conditionally Multiple choice...
Guided Assignment Problem 3: Call Stack Your Tasks: Answer the following questions. Include a function stack...
Guided Assignment Problem 3: Call Stack Your Tasks: Answer the following questions. Include a function stack chart/diagram for each question to verify your answers. Use a call stack to explain the result of calling example(3). int example(int n) {   if (n == 0) return 0;   else return example(n – 1) + n * n * n; } Use a call stack to explain how many time(s) the method factorial invokes itself with an argument of 5 of factorial(5). int factorial(int...
Some languages support many modes of parameter passing. Provide 2 examples using two different programming languages...
Some languages support many modes of parameter passing. Provide 2 examples using two different programming languages which support the user of the programming language deciding which to use when creating their method. (Programming Languages)
Once the form in this file is submitted, create a new paragraph that will stack on...
Once the form in this file is submitted, create a new paragraph that will stack on top of the existing paragraphs and will contain the data entered into the textarea. Each new paragraph should have the class 'tweet' applied to it. *Hint: Remember to use return false; to stop the form submission from reloading the page. <!DOCTYPE html> <html> <head>    <title>Simple Twitter</title>    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">    <style>    .tweet{border-top:1px solid #dedede; padding:20px;}    </style>    <script...
Once the form in this file is submitted, create a new paragraph that will stack on...
Once the form in this file is submitted, create a new paragraph that will stack on top of the existing paragraphs and will contain the data entered into the textarea. Each new paragraph should have the class 'tweet' applied to it. *Hint: Remember to use return false; to stop the form submission from reloading the page. <!DOCTYPE html> <html> <head> <title>Simple Twitter</title> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous"> <style> .tweet{border-top:1px solid #dedede; padding:20px;} </style> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> </head> <body class="container" style="width:50%"> <h1>Twitter</h1>...
A call center randomly selects and records customer calls. Call handling times in minutes for 20...
A call center randomly selects and records customer calls. Call handling times in minutes for 20 calls are as follows: 6, 26, 8, 2, 6, 3, 10, 14, 4, 5, 3, 17, 9, 8, 9, 5, 3, 28, 21, and 4. Please calculate the 10th quartile, 90th quartile, median, Q1, Q3, sample mean, and sample standard deviation of call handling times.
26) A. At many synapses in the hippocampus, long‑term potentiation depends on the             activation of...
26) A. At many synapses in the hippocampus, long‑term potentiation depends on the             activation of NMDA receptors which have affinities for and respond to __________:              a. GABA. b. glutamate. c. dopamine. d. norepinephrine. e. nitric oxide. B. Based on imaging research of the brain, the region known as DLPFC (dorsolateral    prefrontal cortex) is associated with __________:             a. verbal tasks.             b. executive control.             c. spatial tasks.             d. all of the above.             e. none...
In blood coagulation, there are many enzymes involved in a cascade of activation reactions to ultimately...
In blood coagulation, there are many enzymes involved in a cascade of activation reactions to ultimately form fibrin. There is an inherited disorder in Factor X for a small subgroup of the population (bleeding disorder). It is hypothesized that 50% of this different Factor X is defective in the activation site that allows conversion to Factor Xa. You are charged with developing a pharmaceutical (drug) or biopharmaceutical (biologic) to improve this bleeding disorder. Describe what protein or system you will...
In the Introduction, Harrison claims that the first data (i.e., the first descriptions) about many languages...
In the Introduction, Harrison claims that the first data (i.e., the first descriptions) about many languages come from missionaries. Please discuss two things: Why do missionaries tend to do linguistic fieldwork that others do not? What are the problems, from a cultural/linguistic standpoint, associated with indigenous people’s contact with Christian missionaries?
Protein dimerization is an important mechanism in the activation of many cellular mechanisms. Use the MPF...
Protein dimerization is an important mechanism in the activation of many cellular mechanisms. Use the MPF factor regulation of the G2 checkpoint as an example to explain the role of dimerization.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT