<aside> <img src="/icons/home_green.svg" alt="/icons/home_green.svg" width="40px" />

Back to Home

</aside>

Example: Mealy Machine - Detecting "FRFR" Sequence

Example: Vendor Mealy Machine

Moore FSM vs Mealy FSM in C

Characteristic Moore FSM Mealy FSM
Output Dependency Depends only on current state Depends on current state and input
State Transition Table 1D array 2D array
Output Table 1D array 1D or 2D array

// In main loop


//Moore FSM
next_state = next_state[current_state];
output = output[current_state];

// In main loop

// Mearly FSM
next_state = next_state[current_state][input];
output = output[current_state][input]; 

Exam: Mealy Machine - Detecting "FRFR" Sequence

frfr.png

Introduction to Mealy Machines

A Mealy machine is a finite-state machine where the output depends on both the current state and the input. This allows for more flexibility in output generation and can often lead to simpler state diagrams compared to Moore machines.

Example: Detecting "FRFR" Sequence

Let's implement a Mealy machine that detects the sequence "FRFR" in an input string, counting overlapping occurrences.

Step 1: Define States and Inputs

States: S0 (Initial), S1 (F), S2 (FR), S3 (FRF), S4 (FRFR) Inputs: F, R, X (any other input) Outputs: 0 (no match), 1 (match found)

Step 2: State Transition Table