Page 162 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 162
6.1 Local Variables 139
6.1 Local Variables
In this section we offer a mechanism that will help you write much clearer programs,
The main contribution to clarity is modularization of a program into smaller segments.
Think small, and the relationships within your program will be clearer. The problem
with programs that are not so modularized is that a change to correct a bug in one part of
the program may cause a bug in another part. If this propagation of errors explodes
cancerously, your program becomes useless. The way to squelch this propagation is to
divide the program into segments and to control the interaction between the segments
with standard techniques. The main source of uncontrolled interaction is the storage of
data for different segments. In this section, we introduce you to the tools to break up a
program into segments and to store efficiently the data needed by these segments.
A program segment is a sequence of instructions that are stored one after another in
memory as part of your program. An entry point of the segment is any instruction of
the segment that can be executed after some instruction which is not in the segment. An
exit point of the segment is any instruction that can be executed just before some
instruction that is not in the segment. Figure 6.2a shows the flowchart of a program
segment with multiple entry and exit points. For simplicity, however, you may think of
a segment as having one entry point, which is the first instruction in the segment, and
one exit point, which is the last instruction in the segment. See Figure 6,2b.
Figure 6.2. Program Segment with a Plurality of Entry and Exit Points