Skip to main content
Engineering LibreTexts

3.4: Comments on the PrintInt program

  • Page ID
    76106
  • \( \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}}\)

    Superficially the programs for printName and printInt seem to be the same, just that a different type of value is being read and printed. However, these programs differ in a small but significant way. Just as in the printName program, the reference to the num variable is passed to the scanf function, and the memory is updated when the value is read. However, when calling the printf function the value of num (not the reference) is stored in r1.

      ldr r1, =num
      ldr r1, [r1, #0]
    

    In these two lines, first the address of num is loaded into r1, and next, the value that is at the address r1+0 is loaded into r1. The printf function is then called with the value of num, not the reference.

    Be careful when reading this code fragment. Understanding the difference between a reference and a value is central to understanding much of assembly, and even affects how you can understand many concepts you will encounter in future classes that involve a HLL. References and values are central to much of computer science.


    This page titled 3.4: Comments on the PrintInt program 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?