Lecture 3: Memory, the Stack, Recursion

Introduction

Memory and addressing modes

See also these slides.

Working with arrays

A Program’s Address Space

The Stack (and the Heap)

Stack Frames

How does this work?

Writing Functions

See also these slides.

Writing Recursive Functions

  1. Signature

  2. Pseudocode

  3. Variable mappings

  4. Skeleton

    fact:
        # Prologue:
        enter $0, $0
    
        # Body:
    
        # Epilogue:
        leave
        ret
  5. Body

    fact:
    ...
       # if (n < 2) 
       #   return 1;
       # else
       #   return n * fact(n - 1);
    ...

To be continued…