10.4.6. Macro conditional statements

RealView Debugger provides a set of macro flow control statements. These statements are very similar to C conditional statements and can be either simple or compound. Compound statements must be enclosed in curly braces ({}). The macro conditional statements are:

BREAK

The BREAK statement causes the innermost FOR...DO-WHILE loop, or WHILE loop to be exited immediately.

The BREAK statement has the following syntax:

break;

CONTINUE

The CONTINUE statement causes the remainder of the FOR...DO-WHILE loop, or WHILE loop to be ignored and the next iteration of the loop to execute.

The CONTINUE statement has the following syntax:

continue;

DO-WHILE

The DO-WHILE statement executes a given statement one or more times until an expression evaluates to False. If you have more than one statement in the DO-WHILE loop these must be enclosed in curly braces ({}).

The DO-WHILE statement has the following syntax:

do {
statement;                       /* execute this statement */
[statement;]...                  /* additional statements */
} while (expression);            /* while this expression is true */

FOR

The FOR statement is useful for executing a statement a given number of times. It evaluates expression_1 and then evaluates expression_2 to see if it is True, that is nonzero, or False, that is zero. If expression_2 evaluates to True, all statements are executed once.

Next expression_3 is evaluated, and expression_2 is evaluated again to see if it is True or False. If expression_2 is True, all statements are executed again and the cycle continues. If expression_2 is False, all statements are bypassed and execution continues at the next statement outside the FOR loop.

Where you have more than one statement in the FOR loop these must be enclosed by curly braces ({}).

The FOR statement has the following syntax:

for
    (expression_1;       /* evaluate only once */
    expression_2;        /* evaluate before each iteration */
    expression_3)        /* evaluate after each iteration */
{
statement;               /* execute this statement */
                         /* while expression_2 is true */
[statement;]...          /* additional statements */}

The term expression_1 can be used to initialize a variable to be used in the loop. It is evaluated once, before the first iteration of the loop. The term expression_2 determines whether to execute or terminate the loop and is evaluated before each iteration. If the term expression_2 evaluates to True, that is nonzero, the loop is executed. If expression_2 is False, that is zero, the loop is terminated. The term expression_3 can be used to increment a loop counter, and is evaluated after each iteration. This is illustrated in Example 10.2.

Example 10.2.  Using a FOR statement

j=0;
for (i = 0; i<3; i++)
    j = j+5;
k = 47;

In this example of the FOR statement:

  • expression_1 is i=0

  • expression_2 is i<3

  • expression_3 is i++

  • statement is j = j+5

  • The next statement outside the FOR loop is k = 47;.

The following actions take place:

  1. On entering the FOR loop, j has a value of 0, and i is set to 0.

  2. Since i<3 is True, 0<3, statement is executed, and j is set to 5.

  3. i is incremented, i++, and i becomes 1.

  4. Since i<3 is True (1<3), statement is executed, and j is set to 10.

  5. i is incremented (i++) and i becomes 2.

  6. Since i<3 is true (2<3), statement is executed, and j is set to 15.

  7. i is incremented (i++) and i becomes 3.

  8. Since i<3 is False (3 is not less than 3), statement is not executed, and j remains 15.

  9. The next statement, outside the FOR loop, is executed, that is k = 47;.

IF

The IF statement is the simplest form of a macro conditional statement. It is always followed by an expression enclosed in parentheses. If the expression evaluates to zero, that is False, the statement following the expression is bypassed. If the expression evaluates to a value other than zero, that is True, the statement following the expression is executed. If you have more than one statement in the IF statement these must be enclosed in curly braces ({}).

The IF statement has the following syntax:

if (expression)              /* If this expression is true */
{
statement;                   /* execute this statement */
[statement;]...              /* additional statements */
}

IF-ELSE

The IF-ELSE statement provides a way to specify an alternative statement to execute if the IF statement evaluates to False. If the expression evaluates to True, that is nonzero, statement_1 and any following statements are executed, but statement_2 and any following statements are not executed. If the expression evaluates to False, that is zero, statement_2 and any following statements are executed, but statement_1 and any following statements are not executed. If you have more than one statement in the IF section or in the ELSE section these must be enclosed in curly braces ({}).

The syntax of the IF-ELSE statement is as follows:

if (expression)              /* If expression is true */
{
statement_1;                 /* execute statement_1 */
[statement;]...              /* and these additional statements */
}
else                         /* If expression is false */
{
statement_2;                 /* execute statement_2 */
[statement;]...              /* and these additional statements */
}

RETURN

The RETURN statement is used to return a value from a macro. The expression is evaluated, and the resulting value is returned to the caller. If a breakpoint macro returns a value of True, that is nonzero, program execution continues. If it returns a value of False, that is zero, program execution is halted. If a macro never returns a value, the macro_type must be declared as void when it is defined.

The RETURN statement has the following syntax:

return [(]expression[)];

WHILE

The WHILE statement evaluates an expression and executes the following statement or statements until the expression evaluates to False.

The WHILE statement must be followed by an expression in parentheses. As long as the expression evaluates to True, all following statements are repeatedly executed. When the expression evaluates to False, all statements are bypassed and execution continues at the next statement outside the WHILE loop. If you have more than one statement in the loop these must be enclosed in curly braces ({}).

The syntax of the WHILE statement is as follows:

while (expression)           /* while this expression is true */
{
statement;                   /* execute this statement */
[statement;]...              /* and these additional statements */
}
Copyright © 2003, 2004 ARM Limited. All rights reserved.ARM DUI 0234B
Non-Confidential