This section specifies the semantics of statements in Cx.


Asserts that an expression is true. Useful for verification.


Assign an expression to a variable or an array.

x = 15;
y[3] = (u4) z;

The assignment statement may be used without a target variable just to force the evaluation of an expression. This is useful to wait for an event by reading from a sync port, but without using the actual data. In this case, you can use an empty assignment statement as follows:

in sync u8 msg;
void loop() {
  // ...
  // wait for data to be available on msg, and discard it;
  // ...


Placed between statements, forces a new cycle to start.

print("in cycle 1");
print("in cycle 2");


Do nothing for a given number of cycles.

print("in cycle 1");
print("in cycle 5");


Prints a message/values. Useful for verification.



Returns a value. In the current version, only valid at the end of a constant function.

return factor << 1;


Write to a port.



Conditional "if" statement.

if (a > 0) {
  print("a greater than zero");
} else if (a < 0) {
  print("a smaller than zero");
} else {
  print("a equals zero");

Both if and for statements have special semantics of reads in conditional called peeking. This means that you may read the data on a port in the condition of the if/loop and still have access to that data in the branch that is chosen:

if ( < { // peeks a and b
  min.write(; // does not cause a new cycle,
// we're still in the same cycle
// after the if, both a and b have been read (b implicitly in this case); // causes the creation of a new cycle


For loop with initial assignment, loop condition, post-iteration assignment.

for (u4 i = 0; i < 5; i++) {
  print("one iteration"); // this message is printed 5 times in the current cycle

for (;; count++) {
  print("cond is true"); // this message is printed one time per cycle until cond becomes false

A for loop can be executed in the current cycle if the following conditions are respected:

  • The loop uses a local variable used solely for iteration.
  • The loop has compile-time constant bounds.
  • The body does not read or write ports, or contains fence or idle instructions.

Otherwise, the loop takes at least one cycle per iteration.


While loop with loop condition.

while ( {

results matching ""

    No results matching ""