Help you learn how to create and call subroutines in SPARC assembly language programs
Paul, Chapter 7
Study many small C programs and corresponding hand-written assembly language programs
After studying each program, refer to summary sheets to reinforce and generalize the new material that the program illustrates
Review the handout SPARC Subroutine Calling Conventions
Illustrates the subroutine calling conventions
What it does
Same as previous "sum..." programs
How it works
Uses a subroutine
The code: sumsub.c
Defines two subroutines: main and sumBetween
main calls sumBetween with 2 ints as actual parameters
sumBetween returns an int that is the sum of all ints between the 2 given integers
The code: sumsub.S
(Not optimized -- for clarity and to illustrate stack manipulation)
Leaf subroutine
Informally, a subroutine that does not call another
Review the handout SPARC "Leaf" Subroutine Calling Conventions
Why leaf subroutines?
Efficiency: avoids expensive "save" and "restore" instructions
Note: Subroutine sumBetween could, and probably should, be a leaf subroutine...
Illustrates the leaf subroutine calling conventions
See sumsubleaf.S
What it does
How it works
Same as sumsub.S, except uses a leaf subroutine
The code
Same as sumsub.S, except sumBetween is a leaf subroutine
(Not optimized -- for clarity and to illustrate stack manipulation)
Artificial example
Illustrates passing more than 6 actual parameters
Artificial example
Illustrates how C function pointers are implemented in SPARC assembly language
Explicitly use "jmpl addr, rd" or "call ris" instruction to jump to an address that is contained in a register
Copyright © 2002 by Robert M. Dondero, Jr.