|
Section 11: Branching and Looping162
|
|
An exciting feature in the HP-41C is the calculator’s ability
to ‘‘remember’’ where most branches are
located in a program. The HP-41C only has to search for most labels
the first time through the program. When the program branches to that
label the calculator does not have to search again! It knows where the
label is located so it immediately begins execution at that line. The
result is that execution time is greatly reduced because the
calculator does not have to repeatedly search for most labels. This
feature is known as compiling and is generally only found in large
computer systems. For more information about how the HP-41C remembers
labels, refer to
appendix G.
|
|
|
|
Looping techniques like the one illustrated here are common and
extraordinarily useful in programming. By using loops, you take
advantage of one of the most powerful features of the
calculator—the ability to update data and perform calculations
automatically, quickly, and, if you so desire, endlessly.
|
|
You can use unconditional branches to create a loop, as shown above, or
in any part of a program where you wish to transfer execution to another
label. When the calculator executes a GTO
instruction, it searches sequentially through the program and begins
execution at the first specified label it encounters.
|
|
Problems
|
|
|
1.
|
The following program computes x=2n sin(90÷n). Modify this
program by placing a LBL 01 instruction in
line 4, and these instructions at the end of the program (just before
the END ):
|
|
|
|