This document provides detailed steps for writing a simple level-2 MATLAB S-Function using examples from the demo msfcn_unit_delay.m. It covers initializing attributes, setting up input/output ports, handling state conditions, and defining required callback methods for execution. The document also addresses how to manage discrete states and perform necessary cleanup, offering code snippets as guidance throughout the process.