<aside> <img src="/icons/home_green.svg" alt="/icons/home_green.svg" width="40px" />
</aside>
Example: Mealy Machine - Detecting "FRFR" Sequence
| 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];

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.
Let's implement a Mealy machine that detects the sequence "FRFR" in an input string, counting overlapping occurrences.
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)