ToolSphere

Activation Records and Parameter Passing

Computer science

Trace factorial stack frames, control and access links, then compare value, reference, value-result and name passing with array and alias examples.

Copy comparison

Enter a whole number, then use Next to follow calls and returns.

factorial(4) = 24; maximum 4 active frames

Factorial program
function factorial(n) {
  if (n <= 1) return 1;
  child = factorial(n - 1);
  return n * child;
}
main: result = factorial(n);

Recursive call stack

factorial(4) = 24 · maximum 4 active factorial frames

Call factorial(4): push F1.

F1: factorial(4) · current frame

FieldValue
Parameter n4
Local childnot returned yet
Return valuenot computed
Control linkmain
Access linkglobal
Return addressresume main after factorial call

Current frame is at the top. Control links follow callers. Factorial is globally declared, so every symbolic access link points to global, not its recursive caller. These fields are a teaching model, not byte offsets or a platform ABI.

Parameter-passing comparison

Value copies inputs; reference shares entry locations; value-result copies back at return; name re-evaluates each actual location.

Initially i=1, a[1]=2, a[2]=3
swap(first,second):
 temp=first; first=second; second=temp;
ModeFinal i, a[1], a[2]
value1, 2, 3
reference2, 1, 3
value-result2, 1, 3
name2, 2, 1
StepFormal values and locationsCaller state
Bind actual arguments to first and second.first=1 at i; second=2 at a[1]i=1; a[1]=2; a[2]=3
temp = firstfirst=1 at i; second=2 at a[1]; temp=1i=1; a[1]=2; a[2]=3
first = secondfirst=2 at i; second=3 at a[2]; temp=1i=2; a[1]=2; a[2]=3
second = tempfirst=2 at i; second=1 at a[2]; temp=1i=2; a[1]=2; a[2]=1
Return to caller.first=2 at i; second=1 at a[2]; temp=1i=2; a[1]=2; a[2]=1

Value-result captures the actual locations at entry and copies local values out in the selected order. Name re-evaluates an actual location on each access. Reference binds locations at entry. Language-specific restrictions can rule out these aliasing examples.

On this browser only

Give feedback

Did this tool help?

Tell us what worked, what didn’t, or what you’d like next.

Opens Google Forms in a new tab with this tool’s name filled in. No sign-in or email required. Feedback is optional.

How to use Activation Records and Parameter Passing

  1. 1Start with the loaded factorial input, or enter a whole number from zero to twelve.
  2. 2Use the execution buttons or slider to inspect frame creation, local results and returns.
  3. 3Compare each frame’s caller control link with its global lexical access link.
  4. 4Choose the array swap or aliased-argument example and inspect all four passing modes.
  5. 5Change the value-result copy-out order, follow the statement trace and copy the comparison.

About Activation Records and Parameter Passing

Follow a recursive call through its stack frames

This activation-record visualizer shows a small factorial program as calls create frames and returns remove them. A loaded example appears immediately. Change the factorial input, then use First, Previous, Next, Last or the execution slider to inspect the stack at a particular event. The result and maximum active factorial-frame count are computed from the same trace as the diagram.

A second panel compares call by value, reference, value-result and name. It runs two fixed examples: an array swap whose index changes during the call, and a procedure with aliased actual arguments. These examples make the differences visible without requiring you to learn another programming-language syntax. This is a deterministic teaching simulation, not an interpreter for pasted programs or a debugger attached to your computer.

Read the fields of an activation record

Each factorial call receives a separate frame with a symbolic identity. The parameter n belongs to that invocation. The local child field records the recursive call's result once the caller resumes. Return value stays uncomputed until the base case or multiplication has produced it. Waiting callers retain their own parameters while the deepest call is running.

The return address says where execution resumes after the call. The control link identifies the caller: main for the initial invocation, then the preceding factorial frame for recursive invocations. These are symbolic names rather than instruction addresses, machine registers or memory offsets. The current frame appears at the top of the stack display, even though snapshots internally retain calls in entry order.

Distinguish control links from access links

A control link follows the dynamic call chain. An access link represents the lexical environment used for nonlocal bindings. The displayed factorial procedure is declared at global scope, so every symbolic access link points to global. Recursion does not make an earlier factorial activation the lexical parent of the new activation.

A real runtime may omit a physical access-link field when global addressing is sufficient. This diagram includes it to explain the distinction; it does not prescribe a calling convention or frame layout for C, Java or a particular processor. Nested procedures would require another lexical-scope example, which this page does not simulate. Do not infer static nesting from whichever frame happened to call a function.

Worked factorial example

For the loaded input, factorial(4) returns 24 and reaches 4 active factorial frames. The deepest stack has parameters 4, 3, 2, 1 in call order. The base case returns a unit result; each suspended caller receives its child result before multiplying by its own saved parameter.

Returning parameter Computed return value
1 1
2 2
3 6
4 24

The final step shows an empty factorial stack because the initial call has returned to main. That does not mean the result disappeared. The status line still shows it. Inputs are whole numbers from zero through twelve; zero follows the same base-case rule as one. Exact integer multiplication is used inside this bounded model.

Compare four parameter-passing rules

Call by value copies the incoming values into independent formal locations. Assigning a formal changes that local copy. Call by reference binds a formal to an actual location at entry, so a write is visible to the caller immediately. In the array example, the referenced element is chosen before the procedure body changes the index.

Value-result also uses local copies during the body, then copies the final formal values back. This simulator captures each actual destination at call entry and exposes the copy-out order as a control. Call by name instead uses read/write accessors that re-evaluate an actual location on each access. For the changing-index array argument, that can select a different element later in the same call.

Worked swap with a changing array index

The example calls swap(i, a[i]) with i equal to the initial index shown in the panel. The body saves first into temp, assigns second into first, then assigns temp into second. Starting values and every intermediate state come from the parameter model, including the formal locations shown in the detailed trace.

Passing rule Final i Final a[1] Final a[2]
value 1 2 3
reference 2 1 3
value-result 2 1 3
name 2 2 1

With name passing, assigning first changes i before second is assigned. The later access to a[i] therefore uses the new index. It does not perform the same exchange as a reference captured at entry. Select a passing mode to inspect the formal values and locations beside the caller state after every statement.

Aliasing makes copy-out order observable

The second example calls p(x, x), starting with x equal to zero. The body assigns one to first and then two to second. Reference and name share the caller's scalar location throughout the call. Value uses independent locals and performs no copy-back. With left-to-right copy-out, the computed final values are:

Passing rule Final x
value 0
reference 2
value-result 2
name 2

Switch value-result to right-to-left copy-out and its final x becomes 1. The copies are independent during the body, but the two destinations alias. The last copy wins. These are explicitly chosen model rules; a real language may define another convention or reject such calls. Do not treat an unspecified copy-out order as a universal language guarantee.

Check your answer and continue the compiler lab

Track locations as well as values. Keep a suspended caller's local data separate from the current callee. Do not erase a return value before the caller receives it, or confuse lexical links with recursive callers. In parameter exercises, state when an array destination is chosen and whether writes happen during the call or at return.

Use the three-address code generator to explore intermediate instructions, the basic-block flow graph to inspect control flow, and the simple code generator for register and address descriptors. The compiler lab groups the related stages. Copy comparison saves the factorial context, the selected example, the copy-out convention and all four final caller states.

Frequently asked questions

What is an activation record in a compiler?

It is the information associated with one procedure invocation, often called a stack frame. This model displays a parameter, local child result, return value, return address and symbolic control/access links.

How does recursion use the call stack?

Each active factorial invocation keeps its own frame while its child runs. Returning removes the child frame and lets its caller resume with the returned value.

What is the difference between a control link and an access link?

A control link identifies the dynamic caller. An access link represents the lexically enclosing environment; factorial is globally declared here, so its access links all point to global.

Why is the stack empty at the last step?

The initial factorial call has returned to main, so no factorial activation remains active. The computed result stays visible above the stack.

Can I paste my own recursive program?

The page simulates a fixed factorial procedure and two fixed parameter-passing examples. It does not parse arbitrary source or inspect a native process.

Does call by value change the caller variable?

Assignments to these scalar value formals change independent local copies. The simulator performs no copy-back for value passing.

How does call by reference handle an array argument?

This model captures the actual element location when the call begins. Later changes to the index do not redirect that captured reference.

Why does call by name change the swap result?

Its accessor re-evaluates a[i] each time the formal is accessed. Changing i during the body can therefore redirect a later write to another array element.

Is value-result the same as reference passing?

Value-result uses local copies during execution and writes them back at return. Aliased actual arguments can produce different results, and this page lets you select copy-out order explicitly.

Are these activation records actual machine addresses?

No: frame identities, return addresses and links are symbolic teaching fields. Their physical representation depends on the implementation and calling convention.

Have a suggestion for Activation Records and Parameter Passing?Share your feedback ↗