4. Control terminal

In this chapter, it explains “control internal terminal”,”control input terminal”, and “control output terminal”.
It also explains “seq” block that can be described only in “control terminal”.

In NSL, the flow of “control” (path) is described separately from a flow of the data such as “input”, “output”, and “inout”.
The “control terminal” is a signal that describes the flow of “control”, and it includes the three types of “internal”, “input”, and “output”.
The control terminal in a module is “control internal terminal”, the control terminal that comes in from the outside of a module is “control input terminal”, and the control terminal that goes outside of a module is “control output terminal”.

The control terminal is used together with the element called “function” in sets.
The control terminal activates the “function” that exists in a module from within and without the module.
And, the “function” indicates the one that the behavioral description is consolidated.

4-1. Control internal terminal

The “control input terminal” is a control terminal that activates a “function” from within the module.
Therefore, it cannot activate a “control internal terminal” from without the module.
The description method of “control internal terminal” is as follows.

func_self Name_of_control_internal_terminal

And, the “control” can be activated with dummy argument.
The dummy argument is described as follows.

func_self Name_of_control_internal_terminal (Dummy_argument_1, Dummy_argument_2, …, Dummy_argument_X)

The dummy argument of “control internal terminal” is limited to the “internal terminal”.
The “internal terminal” shown in () becomes a dummy argument, and it transfers the value of the actual argument when activated.

In addition, the activation uses the same syntax as the function call of C language, etc. to discriminate the control from the data on the language specification.
The activation method of “control internal terminal” is as follows.

Name_of_control_internal_terminal ()

And, it is described as follows when an actual argument is given when a “control internal terminal” is activated.

Name_of_control_internal_terminal (Actual_argument_1, Actual_argument_2, …,Actual_argument_X)

Multiple names of “control internal terminal” are specified by being delimited with”,”.
And, the “function” that is a set of behaviors and corresponds to the “control internal terminal” is described using a definition command of “function”.

function Name_of_control_terminal Action_description

First, it explains the action of the “control internal terminal” with an example.
Let’s see the following Example 22.

<<Example 22.Control internal terminal>>
declare ex22 {
   input a[4],b[4] ;
   output f[4] ;
}
module ex22 {
   reg r1=0, r2=0, r3=0 ;
   func_self exec() ; //Expression 1

   r1:=0b1 ;
   r2:=r1 ;
   r3:=r2 ;

   if(~r3 & r2 & r1 ) exec() ; //Expression 2

   func exec f = a + b ; //Expression 3
}

Example 22 shows a usage example of the “control internal terminal”.
In the expression 1, it declares “exec” of the “control internal terminal”.
In the expression 2, it implements an action to call “exec” when the conditional syntax “if” is true.
And, the expression 3 indicates the function action of the “exec”, and implements an action to assign the addition result of “a” and “b” to “f” when the “exec” was called.

Let’s see the simulation result of Example 22.

Next, let’s see the usage example that uses an argument of the “control internal terminal”.

<<Expression 23.Control internal terminal(with argument)>>
declare ex23 {
   output f[4] ;
}
module ex23 {
   wire w1[4], w2[4] ;
   reg r1=0, r2=0, r3=0 ;
   func_self exec_add(w1,w2) ; //Expression 1

   r1:=0b1 ;
   r2:=r1 ;
   r3:=r2 ;

   if(~r3 & r2 & r1 ) exec_add(0x8, 0x4) ; //Expression 2

   func exec_add f = w1 + w2 ; //Expression 3
}

Example 23 shows a usage example of “control internal terminal” with an argument.

In the expression 1,
it declares the control internal terminal “exec_add” with the internal terminals w1 and w2 as a dummy argument.
In the expression 2,
it calls “exec_add” with the actual arguments of 0×8 and 0×4 when the conditional syntax “if” is true.
The actual argument attached to the “exec_add” in the expression 2 is assigned to a dummy argument of the “exec_add” within the same clock.
Also, the expression3 is executed within the same clock when the “exec_add” was called in the expression 2.
The expression3 describes a function action of the “exec_add”.
The expression3 means an action to output the addition result of w1 and w2 to “f” when the “exec_add” was called.

Let’s confirm the action.
The logical simulation result is shown as follows.

4-2.Control input terminal

The “control input terminal” is a control terminal that comes in from without a module.
Therefore, it cannot activate it from within the module.
The description method of “control input terminal” is as follows.

func_in Name_of_control_input_terminal

Next, the argument is described as follows.

func_self Name_of_control_terminal (Dummy_argument_1, Dummy_argument_2, …, Dummy_argument_X)

The “internal terminal” shown in () becomes a dummy argument, and it transfers the value of the actual argument when activated.

It is necessary to act from an external module to the “control input terminal” to activate the “control input terminal”.
Please refer to the explanation of Chapter 5 Section 2 Submodule (Control terminal) for the method to activate a “control input terminal”.

In addition, it is also necessary for the “control input terminal” to describe a function.
The description method of the function is as follows as well as “control internal terminal”.

function Name_of_control_terminal Action_description

Let’s see the following Example 24.

<<Example 24.Control input terminal>>
declare ex24 {
   input a, b ;
   output f ;

   func_in exec_and ; //Expression 1
   func_in exec_or ;  //Expression 2
   func_in exec_xor ; //Expression 3
}
module ex24 {
   func exec_and f = a & b ; //Expression 4
   func exec_or f = a | b ;  //Expression 5
   func exec_xor f = a ^ b ; //Expression 6
}

Example 24 indicates a module that has ” Declaration of control input terminal” and “Function action of control terminal”.
The expressions 1, 2, and 3 indicate a declaration of the control input terminals “exec_and”, “exec_or”, and “exec_xor” respectively.
On the other hand, the expressions 4, 5, and 6 indicate the function actions of “exec_and”, “exec_or”, and “exec_xor” respectively.
The expression 4 indicates an action to output the logical AND of “a” and “b” to “f” when the “exec_and” was called.
The expression 5 indicates an action to output the logical OR of “a” and “b” to “f” when the “exec_or” was called.
The expression 6 indicates an action to output the exclusive OR of “a” and “b” to “f” when the “exec_xor” was called.

The logical simulation result is shown as follows.

Though the control “control input terminal” of the bunched-line signal by the “control input terminal”

is 1-bit signal line, a bunched line may be applied to the data of controlled object.
Let’s see the following Example 25.

<<Example 25.Control input terminal 2>>
declare ex25 {
   input a[8],b[8] ;
   output f[8] ;

   func_in exec_add ; //Expression 1
}
module ex25 {
   func exec_add f = a + b ; //Expression 2
}

Example 25 is a usage example of the “control input terminal” that uses a bunched-line signal.
In the expression 1, the control input terminal “exec_add” is declared.
Also, the addition result of “a” and “b” is assigned to “f” in the expression 2.
As mentioned above, it can be used in case of a bunched-line signal just like the single-line.

Similarly, let’s confirm the action.
The logical simulation result is shown as follows.

4-3.Control output terminal

The “control output terminal” is a control terminal that outputs outside a module.
The description method of “control output terminal” is as follows.

func_out Name_of_control_output_terminal

And, a dummy argument can be defined to “control output terminal” as well as “control internal terminal”.
The declaration method of a “control output terminal” with dummy arguments is as follows.

func_out Name_of_control_output_terminal (Dummy_argument_1, Dummy_argument_2, …, Dummy_argument_X)

In addition, since the “control output terminal” is a control terminal that outputs outside a module, it is not necessary to describe the “function action”.
A usage example of “control output terminal” is shown in the following Example 26.

<<Example 26. Control output terminal>>
declare ex26 {
   input a[4], b[4], c ;
   output f[4] ;

   func_out done(f) ; //Expression 1
}
module ex26 {

	if(c) done(a&b) ; //Expression 2
}

Example 26 is a usage example of “control output terminal”.
In the expression 1,
it declares the control output terminal “done” with the dummy argument “f”.
In the expression 2, it calls “done” with the actual argument “a&b” when the conditional syntax “if” is true.

Let’s confirm the action.
The logical simulation result is shown as follows.

4-4.Explanation of “seq” block

The “seq” block is a block that can be described only in “control terminal”.
The “seq” block is a block that executes the action syntax by syntax in order of the top of being described in the block.
The description method of “seq” block is as follows.

seq {
Atomic_action_1
Atomic_action_2
Atomic_action_3
:
:
}

Example 27 is an example of the description method of “seq” block.
Let’s see Example 27.

<<Example 27.”seq” block>>
declare ex27 {
    input	a[4], b[4] ;
    output	f[4] ;
    func_in	exec(a, b) ;
}
module ex27 {
    reg	r1[4] = 0, r2[4] = 0, r3[4] = 0 ;

    func exec seq{
        r1 := a | b ;       //Expression 1
        r2 := r1 & 0b1010 ; //Expression 2
        r3 := r1 ^ r2 ;     //Expression 3
        f = r3 ;            //Expression 4
    }

} // end module

The “seq” block I Example 27 executes the action
in sequence after calling the control input terminal “exec”.
First, the expression 1 is executed when the module was activated, and the expression 2 is done at the second clock.
Then, it executes the expression 3 at the third clock, and a syntax every clock.

Let’s see the simulation result of Example 27.

Explanation of “for” block

The “for” block is a syntax that can be used only in “seq” block, and it expresses a conditional loop.
The following example shows the description method of “for” block.

for (Initial_value; Condition ; changed_value) {
Atomic_action 1
Atomic_action 2
Atomic_action 3
:
:
}

In addition, the procedure to activate the action of “for” block is shown as follows.
0. It executes the action that was written into the initial value of “for” block.
1. It proceeds to 2. when the conditional expression is true, or it ends the action when it is false.
2. It executes the action description of “for” block syntax by syntax in order of the top.
3. It returns to 1. after updating the value of change.

Let’s see the following Example 28 as an action example in the “for” block.

<<Example 28.”for” block>>
declare ex28 {
    output f[4] ;
    func_in exec_for() ;
}
module ex28 {
    reg cnt[4] = 0 ;
    reg r1[4] = 0;

    func exec_for seq {
        for(cnt:=0;cnt<10;cnt++){  //Expression 1
            r1 := r1 + 0x1 ;       //Expression 2
            f = r1 ;               //Expression 3
        }
        r1 := 0xf ;                //Expression 4
   }
}

A “for” block executes an action in the “for” block after using one clock to judge the conditional expression.
Let’s follow up the action of Example 28.

First, the “seq” block is activated when it called the control input terminal “exec_for” of ex28.
It executes the initial value of the “for” block in the expression 1 to judge the conditional expression after it entered the “seq” block.
Since the condition when the block was executed is true, it executes the action in the “for” block in sequence.

In the expression 2, 1 is added to the register r1, and it is rewritten to r1.

Next, in the expression 3, the value of r1 is output to the data terminal “f”.

When the “for” block reached a termination, it judges the conditional expression again after the value of change of the expression 1 executed it.
At the time, it executes the action if the conditional expression is true, and it ends the “for” block if false.

In Example 28, it is designed so that the “for” block breaks when the value of “cnt” exceeded 9.
When the “for” block broke, the “seq” block executes a sequential action to execute the expression 4.
In the expression 4, it executes an action to write in 0xf to the register r1.

The simulation of Example 28 is as follows.

Explanation of “while” block

The “while” block is a syntax that can be used only in “seq” block, and it represents a conditional loop as well as the “for”.
The description method of “while” block is as follows.

while (Conditional expression) {
Atomic action 1
Atomic action 2
Atomic action 3
:
:
}

And, the action of “while” block is as follows.
1. It proceeds to 2. when the conditional expression is true, or it ends the action when it is false.
2. It executes the action description of “while” block syntax by syntax in order of the top.
3. It returns to 1.

Let’s see the following Example 29 as an example of “while” block.

<<Example 29.”while” block>>
declare ex29 {
   input a ;
   output f[4] ;
   func_in exec_while(a) ;
}
module ex29 {
   reg r1[4] = 0 ;
   
   func exec_while seq {
      while(a) {           //Expression 1
         r1 := r1 + 0x1 ;  //Expression 2
         f = r1 ;          //Expression 3
      }
      
      r1 := 0xf ;   //Expression 4
   }
}

Let’s follow up the action of Example 29.
When it called the control input terminal “exec_while” of ex29, the “seq” block is activated, and the “while” block starts.
When the “while” block was activated, it first judge the conditional expression.
At the time, it uses one clock to judge the conditional expression.
It executes the action in the “while” block if the conditional expression is true, or it ends executing no action if false.
In case of ex29, the expression 1 is the conditional expression of “while” block.
In case of the expression 1, it becomes true when the signal of 0b1 reached the data input terminal, and it is judged to be false when the signal of 0b0 reached it.

When the conditional expression of the “while” block is true, the expression 2 is executed.
The expression 2 is an action to add 0×1 to the value of r1, and rewrite it to r1.

Next, it executes an action, in the expression 3 that outputs the value of r1 to “f”.
And, when it reached a termination of the “while” block, it judges the conditional expression again.
At the time, it continues to execute the “while” block if true, or it ends if false.

In case of ex29, it is designed to execute the loop as long as “a” is 0b1 when the conditional expression is judged.
It executes an action to write in 0xf to r1 in the expression 4 when a “while” syntax ended.

Let’s see the simulation result of the following Example 29.

Explanation of label

Though sequential action is executed in “seq” block, it is necessary to return to an arbitrary position when a repetitive action is specified.
The syntax that assists such a repetitive action includes the syntax of “label”.
When a “label” is defined in a “seq” block, it is possible to move to the “label” position with “goto”.
It is necessary to declare the “label” in the “seq” block to be used.
The description method of “label” is as follows.

label_name Label_name

The definition of “label” in a “seq” block is described as follows.

Label_name :

And, when it moves to the label position, it is described as follows in the same “seq” block.

goto Label_name

One clock is used for a transition of the process that uses “goto” syntax.
The description example of “label” is as follows.

seq {
label_name Label_name1, Label_name2 Atomic_action1
goto Label_name2
Label_name1 :
Atomic_action2
Atomic_action3
Label_name2 :
Atomic_action4
goto Label_name1
}

Let’s see Example 30 as a description example of “seq” block.

<<Example 30.goto syntax>>
declare ex30 {
    output f[4] ;
    func_in exec_label ;
}
module ex30 {

    reg r1[4] = 0 ;

    func exec_label seq {
        label_name  label1, label2 ; //Expression 1

			goto label2 ;            //Expression 2
        label1 :
            r1 := r1 + 0x1 ;         //Expression 3      
        label2 :
            if(r1 < 0x5) goto label1 ;  //Expression 4

        f = r1 ;                     //Expression 5
    }
}

In ex30, the "seq" block is activated when it called the control input signal "exec_label".
The "label" is a syntax to move the order of the action execution of the "seq" block to an arbitrary position.
In Example 30, it declares the two labels of "label1" and "label2" in the expression 1.
The label of the "seq" block itself does not represent any action.
Therefore, in Example 30, the expression 2 is first executed when the "seq" block was activated.
Since the expression 2 is an atomic action that intends to move to the label "label2", it is the expression 4 just after the label "label2" that is executed next to the expression 2.
The expression 4, when the conditional expression is true represents an action that moves to the label "label1" with a "if" syntax.
When it jumped to the label "label1", it executes the immediate expression 3.
The expression 3 represents an atomic action that adds 0x1 to r1, and rewrites it to r1.
After the expression 3 was executed, it executes the expression 4 in sequential action again.
When the expression 4 is false, it executes the expression 5 that is the next sequential action.
The expression 5 represents an atomic action to output r1 to "f".

So, let's the simulation result of Example 30.

●Return value
Return value can be set to a control terminal.
Return value is a syntax to which a specified value returns when the control terminal was activated.
Return value returns a value in the same clock in which the control terminal was activated.

Then, it explains in order of control internal terminal, control input terminal, and control output terminal.
First, the return value of a control internal terminal is described as follows.

func_self Function_name (Argument):Return_value_terminal_name

Argument and return value of a control internal terminal can describe only an internal terminal.
A return value is set in a function action, and it is described as follows.

return ( Value )

Let's see Example 4-10 of the return value that uses a control internal terminal.

Example4-10)Return value of the control internal terminal
declare funcs_return {
}
module funcs_return {
    reg trigger[3] = 0 ;
    reg sum[4] = 0 ;
    wire a[4], b[4], c[4];
    func_self exec_add(a, b) : c ;      //The control internal terminal is declared
                                        //by setting the internal terminal a,b as an argument,
                                        //and c as a return value.

    trigger := { trigger[1:0], 0b1 } ;

    if(trigger == 0b011) sum := exec_add(0b0011, 0b0100) ;  //Activation of the control internal terminal

    func exec_add {
        return (a + b) ;                //Setting a+b to the return value
    }
}

Example 4-10 shows an addition that uses a control internal terminal.
In the example, the control internal terminal "exec_add" was activated,
and the adding result is written into the register "sum".
"0b0011" and "0b0100" were passed to the argument,
and "0b0111" of the adding result is output to "exec_add" as a return value.

So, let's simulate an example4-10.

Next, a return value of the control input terminal is described as follows.

func_in Function_name (Argument):Return_value_terminal_name

The argument of the control input terminal can describe only a data input terminal,
and the return value can describe only a data output terminal.
The return value is set in a function action just like a control internal terminal.

Let's see an example of the return value that uses a control input terminal.

Example4-11)Return value of a control input terminal
declare funci_return {
    input inA[4] ;
    input inB[4] ;
    output outF[4] ;

    func_in exec_sub(inA, inB) : outF ; //The control input terminal is declared
                                        //by setting inA,inB to the argument,
                                        //and outF to the return value.
}
module funci_return {

    func exec_sub {
        return (inA - inB) ;            //Setting inA-inB to the return value
    }
}

In Example 4-10, an argument is passed to the control input terminal "exec_sub".
It is a module that outputs the difference between the arguments as a return value.

The return value of the control output terminal is described as follows.

func_out Function_name(Argument):Return_value_terminal_name

The argument of the control output terminal can describe only a data output terminal.
And, the return value can describe only a data input terminal.
The return value is set in the function action just like a control internal terminal.

Let's see an example of the return value in a control output terminal.

Example4-12)Return value of the control output terminal
declare test_sub {
    input ack ;
    output outA[4], outB[4] ;
    func_out exec(outA, outB) : ack ;    //The control output terminal "exec" is declared
                                         //by setting "outA","outB" to the argument,
                                         //and "ack" to the return value.
}
module test_sub {
    reg trigger[4] = 0 ;
    reg end_flag = 0 ;

    trigger := { trigger[2:0], 0b1 } ;

    if(trigger==0b0111) {
        exec(0b0011, 0b1100) ;          //Activation of the control output terminal "exec"
    }

    if(ack) end_flag := 0b1 ;
}

declare funco_return {
    //NULL
}
module funco_return {
    test_sub U_SUB ;
    reg result[4] = 0 ;

    func U_SUB.exec {                       //Function action of "exec"
        result := U_SUB.outA + U_SUB.outB ; //Storing the adding result of "outA" and "outB" into "result"
        return (1) ;                        //Outputting the return value "1"
    }
}

In Example 4-12, it is structured with an upper module "funco_return", and a lower module "test_sub".

The control output terminal "test_sub" is declared applying an argument.
And, the function action of "test_sub" is described in "funco_return".
Lastly, these operations are accepted in the same clock until the return value returns to "test_sub".

So, let's simulate an example4-12.