12

Subroutines and the Stack

A subroutine is a piece of code that is called from a point within a program and executed, and then a return is made to the instruction after the calling point. All computers use subroutines, but some computers provide a programmer with more facilities to implement subroutines than others.

In this chapter, we will look at the ARM’s subroutine handling mechanisms – in particular, the following:

  • The special branch and link instruction
  • The stack
  • A subroutine call and return
  • Block move instructions

The Branch with link instruction

First, we discuss the ARM’s branch and link instruction, bl, which provides a quick and easy way to call a subroutine without using a stack mechanism.

There are two basic ways of implementing ...

Get Computer Architecture with Python and ARM now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.