Skip to main content
Engineering LibreTexts

9: Function Format and Recursion

  • Page ID
    76135
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    In Chapter 7 the basic use of functions was covered. However Chapter 7 did not cover the proper format and use of functions. Functions are much like procedural program structures from Chapter 8 in that there are certain recommended conventions that programmers should follow. Programs that follow these forms are nearly always cleaner, easier to implement and maintain, and tend to be more correct than programs that do not.

    This chapter will be about how to implement a function using these standard formats. It will rely on the Procedure Call Standard for Arm Architecture (AAPCS) for much of this information. The conventions and overall structure of a function will follow a standard, and implementation of functions to this standard will result in functions that are easier and more correct than ones that try to implement functions using ad hoc structures.

    To illustrate why standard function formats are better than ad hoc methods, the chapter will implement functions using recursion. Recursion is thought by many readers to be hard even in a HLL, and thus to be insurmountable in assembly. However by using standard function formats the readers will be shown how recursion is as easily implemented in assembly as in any HLL, and possibly easier to understand because the mechanism of using the program stack to implement recursion will be transparent. Examples will also be given of how even small deviation from the standard format can lead to erroneous programs.


    This page titled 9: Function Format and Recursion is shared under a CC BY 4.0 license and was authored, remixed, and/or curated by Charles W. Kann III via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.

    • Was this article helpful?