Page 195 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 195
172 Chapter 6 Assembly Language Subroutines
6,5 Summary
This chapter introduced the subroutine. It was dissected into parts to show alternative
techniques for each part. Stacked local variables were studied along with alternatives for
accessing local variables of nested program segments. Calling and returning mechanisms
were studied, and the principal one, using BSR and RTS, was shown to have several
alternatives, including ones that save the registers and restore them efficiently.
Alternatives such as SWI and TRAP were studied. We then turned to the techniques that
are used to pass arguments. The register, global, stack, in-line argument list, before the
subroutine entry point, and table techniques were considered.
You should now be able to write subroutines, call them, and pass arguments to
them in an effective manner. You should be prepared to use them in the following
chapters to manipulate data structures, perform arithmetic, and interface to I/O hardware.
Moreover, you should know how to approach a problem using top-down design or how
to test a module with a driver. The need for the last two techniques is not apparent to the
student who writes a lot of small programs and never faces the problem of writing a large
program. When he or she does face that problem without the tools that we have
introduced, inefficiencies and chaos generally will be the result. We introduced these
techniques early and suggest that you use them whenever you can do so, even if they are
not absolutely needed.
Do You Know These Terms?
See the end of chapter 1 for instructions.
top-down design input parameter reset call by result
calling and input argument initialized call by reference
returning output parameter extended local call by name
mechanism output argument access handler
program segment local variable stack marker software interrupt
input parameter global variable calling routine SWI handler
output parameter stacked local calling sequence debugger
pass parameters variable in-line argument monitor
local variable binding list breakpoint
program segment allocation after the call emulate
entry point deallocation case hardware
exit point accessing call by value interrupts
reset