Handel-C also provides a number of short cut assignment statements. Note that these cannot be used in expressions as they can in conventional C but only in stand alone statements.
Statement Expansionvar++;
var = var+1;
++var;
var = var+1;
var--;
var=var-1;
--var;
var=var-1;
var += expr
var = var + expr
var -= expr
var = var - expr
var *= expr
var = var * expr
var <<= const
var = var << const
var >>= const
var = var >> const
var &= expr
var = var & expr
var |= expr
var = var | expr
var ^= expr
var = var ^ expr
See also: Arithmetic, Relational, Logical operators
Handel-C provides the normal C break statement both for terminating loops and separation of case branches in switch and prialt statements. When used within a while, do...while or for loop, the loop is terminated and execution continues from the statement following the loop. For example:
for (x=0; x<32; x++)
{
if (a[x]==0) break;
b[x]=a[x];
}
// Execution continues hereSee also: for, prialt, switch, while
Handel-C provides a delay statement not found in conventional C which does nothing but takes one clock cycle to do it. This may be useful to avoid resource conflicts (for example to prevent two accesses to one RAM in a single clock cycle) or to adjust execution timing.
if (x < 10)
{
x++;
}
else
{
delay;
}
Handel-C provides for loops similar to those in conventional C.
Each of the initialisation, test and iteration statements are optional and may be omitted if not required. As with all other Handel-C constructs, Statement may be replaced with a block of statements. For example:
for (Initialisation ; Test ; Iteration)
Statement
for ( ; x>y ; x++ )
{ a = b; c = d; }
Handel-C provides the standard C conditional execution construct as follows:
if (Expression)
{Statement}
else
{Statement}As in conventional C, the else portion may be omitted if not required. For example:
if (x == 1) x = x + 1;
See also: Conditional operator, Select
Handel-C provides a prialt statement not found in conventional C for selective channel communication.
prialt {
case CommsStatement:
Statement
break;
......
default:
Statement
break;
}The prialt statement can be used to select between communication on a number of channels depending on the readiness of the other end of the channel communication. CommsStatement must be one of the following forms:
Channel ? Variable //read to variable
Channel ! Expression //write to variableThe first communication statement in the list of cases which becomes ready to transfer data will execute. The statements up to the next break statement will then be executed.
In a prialt statement with no default case, execution will halt until one of the channels is ready to communicate.
In a prialt statement with a default case, if none of the channels is ready to communicate immediately then the default branch statements will execute and the prialt statement will terminate.The prialt construct does not allow the same channel to be listed twice in its cases and fall through of cases is prohibited. This means that each case must be paired with its own break statement.
See also: break
The following example executes three assignments sequentially:
x = 1;
y = 2;
z = 3;In contrast, the following example executes all three assignments in parallel and in the same clock cycle:
par {
x = 1;
y = 2;
z = 3;
}In the diagram below, statements in the same colour will execute concurrently.
So for example,x = 1
and the secondpar{}
block will execute concurrenty;
a = 1
andb = 1
will execute sequentially. However,y = 1
,
z = 1
, anda = 1
, will execute concurrently.
Handel-C provides switch statements similar to those in conventional C.
switch (Expression)
{
case Constant:
Statement
break;
case 10:
a = b;
case 11:
c = d;
break;
case 12:
e = f;
break;
......
default:
Statement
break;
}Values following case
and default keywords must be compile time constants.
The switch expression is evaluated and checked against each of the case compile time constants. The statement guarded by the matching constant is executed until a break statement is encountered.
If no matches are found, the default statement is executed, but if no default option is provided, no statements are executed. Each of the Statement lines above may be replaced with a block of statements by enclosing the block in {...} brackets.
As with conventional C, it is possible to make execution drop through case branches by omitting a break statement.
Here, if x is 10, b is assigned to a and d is assigned to c, if x is 11, d is assigned to c and if x is 12, f is assigned to e.
See also: break
Handel-C provides while loops exactly as in conventional C:
while (Expression) Statement
The contents of the while loop may be executed zero or more times depending on the value of Expression. While Expression is true then Statement is executed repeatedly. Again, Statement may be replaced with a block of statements. For example:
x = 0;
while (x != 45)
{
y = y + 5;
x = x + 1;
}
// Or to make loop execute at least once
do
{
a = a + b;
x = x - 1;
} while (x>y);See also: break, for