Vai al contenuto

Calling Functions

Functions (as defined in the relevant section) are invoked by placing the function name in the operator field. This invocation takes the following form:LD 1MUX 5, var0, -6.5, 3.14ST vRESNote that the first argument is not contained in the input list, but the accumulator is used as the first argument of the function. Additional arguments (starting with the 2nd), if required, are given in the operand field, separated by commas, in the order of their declaration. For example, operator MUX in the table above takes 5 operands, the first of which is loaded into the accumulator, whereas the remaining 4 arguments are orderly reported after the function name.The following rules apply to function invocation.
  • Assignments to VAR_INPUT arguments may be empty, constants, or variables.
  • Execution of a function ends upon reaching a RET instruction or the physical end of the function. When this happens, the output variable of the function is copied into the accumulator.
Calling Function BlocksFunction blocks (as defined in the relevant section) can be invoked conditionally and unconditionally via the CAL operator. This invocation takes the following form:LD A ADD 5ST INST5.IN1LD 3.141592ST INST5.IN2CAL INST5LD INST5.OUT1ST vRESLD INST5.OUT2ST vVALIDThis method of invocation is equivalent to a CAL with an argument list, which contains only one variable with the name of the FB instance.Input arguments are passed to / output arguments are read from the FB instance through ST / LD operations performed on operands taking the following form:FBInstanceName.IO_varwhere
KeywordDescription
FBInstanceNameName of the instance to be invoked.
IO_varInput or output variable to be written / read.