Hardware Reference
In-Depth Information
FIGURE A.14 Breakdown of control flow instructions into three classes: calls or re-
turns, jumps, and conditional branches . Conditional branches clearly dominate. Each type
is counted in one of three bars. The programs and computer used to collect these statistics
are the same as those in Figure A.8 .
Addressing Modes For Control Flow Instructions
The destination address of a control flow instruction must always be specified. This destin-
ation is specified explicitly in the instruction in the vast majority of cases—procedure return
being the major exception, since for return the target is not known at compile time. The
most common way to specify the destination is to supply a displacement that is added to the
program counter (PC). Control flow instructions of this sort are called PC-relative . PC-relative
branches or jumps are advantageous because the target is often near the current instruction,
and specifying the position relative to the current PC requires fewer bits. Using PC-relative
addressing also permits the code to run independently of where it is loaded. This property,
called position independence , can eliminate some work when the program is linked and is also
useful in programs linked dynamically during execution.
To implement returns and indirect jumps when the target is not known at compile time, a
method other than PC-relative addressing is required. Here, there must be a way to specify the
target dynamically, so that it can change at runtime. This dynamic address may be as simple
as naming a register that contains the target address; alternatively, the jump may permit any
addressing mode to be used to supply the target address.
These register indirect jumps are also useful for four other important features:
Case or switch statements, found in most programming languages (which select among one
of several alternatives)
Virtual functions or methods in object-oriented languages like C++ or Java (which allow dif-
ferent routines to be called depending on the type of the argument)
High-order functions or function pointers in languages like C or C++ (which allow functions to
be passed as arguments, giving some of the flavor of object-oriented programming)
Dynamically shared libraries (which allow a library to be loaded and linked at runtime only
when it is actually invoked by the program rather than loaded and linked statically before
the program is run)
 
Search WWH ::




Custom Search