Seven-Step Program: Simplest "Leaf Function" Example

A "leaf function" is one that doesn't call any other function. If you drew a tree illustrating function calls in the program, it would be a leaf node in the tree. If the leaf function does not change any saved registers, it does not need to save anything to the Stack.


Calling Program:

Procedure:

Calling Program:


	    # CODE STRUCTURE

caller:     ...

            # put arguments in $a0 - $a3
            jal leafFunc
            # after call, do stuff using value(s) in $v0, $v1

            ...
          
            # return to "super-caller" or op. sys.


leafFunc: # body of subfunction (assume arguments are in $a0 - $a3) # put return value(s) in $v0, $v1 jr $ra

Alyce Brady, Kalamazoo College