Back to the 2016 paper

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

20162m

Explain the use of subroutine with the help of suitable example.

Worked SolutionAI Assisted

Subroutine Uses (2 Marks)

A subroutine is a self-contained sequence of instructions called from different points in program to avoid code duplication.

Uses:

  1. Modularity & Reuse: Common task (e.g. I/O, math) written once and called many times — saves memory, improves readability.
  2. Return Address Management: On CALL addr, CPU saves return address (next PC) automatically — either in link register or on top of stack: SP ← SP-1, M[SP] ← PC, PC ← addr.
  3. RET instruction: On RET, address popped back: PC ← M[SP], SP ← SP+1 and execution resumes after call.
  4. Nesting & Recursion: Stack LIFO allows nested calls; parameters passed via registers/stack, and CALL/RET use stack pointer.

Thus subroutine supports structured programming with hardware stack mechanism.

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.