
8
SUBROUTINES AND STACK
CHAPTER OBJECTIVES
Usage of subroutines makes the program size optimum and off ers a scope of its
modular development. During the use of subroutines, stack is used for related
data storage. In this chapter, the reader is introduced to these two aspects and
related instructions details. After completion of the chapter, the reader should
be able to understand
• How subroutines and stack work.
• When and how to incorporate subroutines.
• Functioning of instructions like LCALL, ACALL, RET, PUSH and POP.
• Importance and usage of stack and stack pointer (SP).
8.1 | Need of Subroutines
Imagine a situation where an 8051 microcontr ...