Optional Input Ports - 2025.2 English - UG1483

Vitis Model Composer User Guide (UG1483)

Document ID
UG1483
Release Date
2025-11-20
Version
2025.2 English

This example shows how to use the parameter passing mechanism of MCode blocks to specify whether to use optional input ports on MCode blocks.

The following M-code, which defines M-function xl_m_addsub is in file xl_m_addsub.m:

function s = xl_m_addsub(a, b, sub)
  if sub
    s = a - b;
  else
    s = a + b;
  end

The following diagram shows a Subsystem containing two MCode blocks that use M-function xl_m_addsub.

Figure 1. Two MCode Blocks Using M-Function Generated by Your Tool

The labeled add is shown in the following figure.

Figure 2. Block Interface Editor of the MCode Block

As a result, the add block features two input ports a and b; it performs full precision addition. Input parameter sub of the MCode block labeled addsub is not bound with any value. Consequently, the addsub block features three input ports: a, b, and sub; it performs full precision addition or subtraction based on the value of input port sub.