Implement component generation script

Now that you have seen both techniques, use the method editor to implement the driver.

  1. In the Explorer view, double-click the getParityBit method name. Then click Source Code in the lower tab of the Method editor.
  2. Type the code below into the method body.
  3. Save your work.

    Note that this is C code with some %-delimited commands. Those commands are part of the Processor Expert scripting language. When Processor Expert generates code, it reads the state of the property and modifies the generated code based on the if/else condition. This minimizes the generated code.

      int i, res = 0;
    
      // Compute parity using shifting and XOR
    
      
      for (i = 0; i < 8; i++) {
    
      
      res = res ^ (Data >> i);
    
      
      }
    
      
      %if %EvenParity = 'yes'
    
      
      return (byte)(res & 1); // mask result
    
      
      %else
    
      
      return (byte)(~res & 1); // mask result
    
      
      %endif
    
      
    Figure 1. Entering code using Processor Expert scripting language

    Entering Code Using the Processor Expert Scripting Language