Hardware Reference
In-Depth Information
also cause the flow of control to be altered when special conditions occur. All
these topics will be discussed in the following sections.
5.6.1 Sequential Flow of Control and Branches
Most instructions do not alter the flow of control. After an instruction is ex-
ecuted, the one following it in memory is fetched and executed. After each in-
struction, the program counter is increased by the instruction length. If observed
over an interval of time that is long compared to the average instruction time, the
program counter is approximately a linear function of time, increasing by the aver-
age instruction length per average instruction time. Stated another way, the dy-
namic order in which the processor actually executes the instructions is the same as
the order in which they appear on the program listing, as shown in Fig. 5-36(a). If
a program contains branches, this simple relation between the order in which in-
structions appear in memory and the order in which they are executed is no longer
true. When branches are present, the program counter is no longer a monotoni-
cally increasing function of time, as shown in Fig. 5-36(b). As a result, it becomes
difficult to visualize the instruction execution sequence from the program listing.
Jumps
Time
(a)
Time
(b)
Figure 5-36. Program counter as a function of time (smoothed).
(a) Without
branches. (b) With branches.
When programmers have trouble keeping track of the sequence in which the
processor will execute the instructions, they are prone to make errors. This obser-
vation led Dijkstra (1968a) to write a then-controversial letter entitled ''GO TO
Statement Considered Harmful,'' in which he suggested avoiding goto statements.
That letter gave birth to the structured programming revolution, one of whose
tenets is the replacement of goto statements with more structured forms of flow
 
 
Search WWH ::




Custom Search