pTAL Guidelines for TAL Programmers

Coding Guidelines
pTAL Guidelines for TAL Programmers527256-002
2-44
Hardware Indicators: Where to Test
Hardware Indicators: Where to Test
Guideline: Test a hardware indicator only after a statement that sets or resets it.
In TAL you can test the carry bit after any statement. The value that you test might not
have been set in the preceding statement, as in Example 2-51 on page 2-44.
Example 2-51 on page 2-44 is not valid in pTAL because the signed multiplication
operator (*) does not set the carry bit. The pTAL compiler reports an error for the
statement IF $CARRY THEN....
Condition Code: Testing Multiple Conditions
Guideline: Use nested IF statements to test the condition code for more than one
value.
You can test the condition code for more than one value by using nested IF
statements. The condition code must be the only operand of the conditional expression
in each IF statement except for the innermost IF statement, which can include
additional terms following the condition code.
Example 2-52 on page 2-44 shows a valid nested IF statement in which the second
test of the condition code is in the THEN part of the innermost IF statement.
Example 2-53 on page 2-45 shows a valid nested IF statement in which the second
test of the condition code is in the ELSE part of the outermost IF statement.
Example 2-51. Valid Test of a Hardware Indicator
INT i := 0;
...
i := i * 1;
IF $CARRY THEN ...
Example 2-52. Testing Condition Code in THEN Part of Nested IF Statement
i := i + 1;
IF <> THEN ! OK: Only a condition code
BEGIN
IF < AND i <> 10 THEN ! OK: Conditional expression in
BEGIN ! innermost IF tests condition code
... ! code followed by relational test
END
ELSE
BEGIN ! OK: Either (condition code is >)
... ! or(condition code is <) & (I=10)
END
END;