AQA A-level Computer Science (7517)Specification point 4.1.1.15

AQA 7517 4.1.1.15: Role of stack frames in subroutine calls

The free BugBot lessons that teach this point, a robot to try it on, and the past-paper questions that test it.

What it covers

At GCSE you wrote subroutines, passed them parameters and used their return values (F4.2), and you saw that a local variable exists only while its subroutine runs (F4.3). You never had to ask how the computer manages that. When patrol calls leg, and leg finishes, how does the processor know where in patrol to carry on? Where do leg's parameters and local variables live, and why do they vanish when it returns? The answer is the call stack, and it is also what makes recursion possible, which is the subject of the next two lessons.

  • What has to be remembered
  • Pushing and popping frames
  • Each call has its own locals
  • Modelling the stack yourself
  • When the stack runs out
Read the free lesson (20 min)

Or do it in the simulator, with tasks that mark themselves

Lessons that teach it

  1. A2.1 Stack frames and the call stack Recursion and computational thinking
    Return addresses, parameters and local variables: what a subroutine call pushes, and what a return pops.
  2. A2.3 Recursion versus iteration Recursion and computational thinking
    The same algorithm both ways, the cost of a frame per call, repeated work, and stack overflow.
  3. A2.10 Project: out of the dead end Recursion and computational thinking
    Model a maze, solve it by recursive backtracking, and drive the robot out along the route.

Try it on a robot

The task from A2.1 Stack frames and the call stack, running here. Change the program and press Run.

The specification is AQA's own document; this page says which of our lessons teach point 4.1.1.15 and is not endorsed by the board.