2 end, instruction 95 – Campbell Scientific CR7 Measurement and Control System User Manual

Page 47

Advertising
background image

SECTION 3. INSTRUCTION SET BASICS

3-5

execute if the comparison is true. The Else
Instruction, 94, is optional and is followed by the
instructions to execute if the comparison is
false. The End Instruction, 95, marks the end
of the branching started by the IF Instruction.
Subsequent instructions are executed
regardless of the outcome of the comparison
(Figure 3.8-1).

FIGURE 3.8-1. If Then/Else Execution

Sequence

If Then/Else comparisons may be nested to
form logical AND or OR branching. Figure 3.8-
2 illustrates an AND construction. If conditions A
and B are true, the instructions included
between IF B and the first End Instruction will
be executed. If either of the conditions is false,
execution will jump to the corresponding End
Instruction, skipping the instructions between.

FIGURE 3.8-2. Logical AND Construction

Figure 3.8-3 illustrates the instruction sequence
that will result in subroutine X being executed if
either A or B is true.

IF A (88-92 with command 30)
Call subroutine X (86, command=X)
ELSE (94)
IF B (88-92 with command 30)

Call subroutine X (86, command=X)
END B (95)
END A (95)

FIGURE 3.8-3. Logical OR Construction

A logical OR can also be constructed by setting
a flag if a comparison is true. (The flag is
cleared before making the comparisons.) After
all comparisons have been made, execute the
desired instructions if the flag is set.

The Begin Case Instruction 93 and If Case
Instruction 83 allow a series of tests on the
value in an input location. The case test is
started with Instruction 93 which specifies the
location to test. A series of Instructions 83 are
then used to compare the value in the location
with fixed values. When the value in the input
location is less than the fixed value specified in
Instruction 83 the command in that Instruction
83 is executed; when the next Instruction 83 is
encountered, execution branches to the END
Instruction 95 which closes the case test (see
Instruction 93).

3.8.2 END, INSTRUCTION 95

END, Instruction 95, is required to mark the end
of:

1.

A Subroutine (starts with Instruction 85)

2.

A Loop (starts with Instruction 87)

3.

An IF ... THEN DO sequence (starts with
one of Instructions 89-93 with the THEN DO
command 30).

4.

A case statement (starts with Instruction 93)

The IF instructions 89-93 require Instruction 95
only when the THEN DO command 30 is used.

If one of the above instructions is used without
the corresponding END, the CR7 will display
error 22 when compiling the program. Error 21
is displayed if END is used without being
preceded by one of these instructions (Section
3.10).

An END instruction is always paired with the
most recent instruction that requires an END
and does not already have one. A way of
visualizing this is to draw lines between each
instruction requiring an END and the END
paired with it (as in Figure 3.8-2). The lines
must not cross. To debug logic or find a
missing or extra END error, list the program and
draw the lines.

Advertising