Back to the 2015 paper

Module 2: x86 Architecture, CPU Control, I/O, Memory System Design

20152m

Briefly explain subroutine call and return.

Worked SolutionAI Assisted

Subroutine Call / Return Mechanism (2 Marks)

Uses stack to save return address and transfer control:

CALL (Call Subroutine):

  1. Push return address: SP ← SP - 1; M[SP] ← PC (PC holds next sequential address after CALL)
  2. Jump to subroutine: PC ← effective address of subroutine (branch target)

Assembly: CALL 2050H does above in one micro-sequence.

RET (Return):

  1. Pop return address: PC ← M[SP]; SP ← SP + 1
  2. Fetch resumes at saved location.

Stack LIFO supports nesting: each CALL pushes new address, each RET pops in reverse order, enabling recursion. Link register variant saves PC in LR instead of memory stack for low-overhead leaf calls.

Similar questions

Budget AppAndroid App

Pocketly on Android

Log daily food, travel, and hostel expenses instantly. Set monthly spending limits and see where your money goes without complex spreadsheets.