ChipKraftChipKraft
Start Learning
ChipKraft/Theoretical Concepts/Finite State Machines

Finite State Machines

Moore and Mealy Machines: State, Outputs, and Design

ChipKraft8 min read

Understand finite state machines and compare Moore and Mealy output behavior, timing, and design tradeoffs.

A finite state machine (FSM) is a sequential circuit described by a finite set of states, input signals, transitions, and outputs. The current state summarizes relevant history from the input sequence. On an active clock edge, the machine uses its state and inputs to choose a next state.

Next-state and output logic

An FSM has next-state logic and output logic. The next-state function is state⁺ = f(state, input). The output function depends either on state alone or on both state and input. Flip-flops store the state; combinational logic calculates transitions and outputs.

Moore machine

In a Moore machine, outputs depend only on current state: output = g(state). Outputs change when the state register changes, normally just after a clock edge. This often makes outputs stable and easier to use, though a Moore design may need an extra state to represent an output event.

Mealy machine

In a Mealy machine, outputs depend on current state and current inputs: output = g(state, input). The output can respond during a clock cycle as soon as an input changes and the combinational logic settles. This can reduce state count or response latency, but input glitches can also appear at the output unless handled carefully.

Mealy diagrams: detecting 10 and 101

Transition labels use input / output. The output is produced on the transition that completes the pattern, and the machine can retain a useful suffix for overlapping matches.

Two-state Mealy state diagram detecting the sequence 10, with input/output transition labels
For pattern 10, the machine asserts output 1 on the transition from “seen 1” when input 0 arrives.
Three-state Mealy state diagram detecting overlapping sequence 101, with input/output transition labels
For pattern 101, the match transition returns to “seen 1,” preserving the ending 1 as a possible start of the next match.

Compare the two models

PropertyMooreMealy
Output depends onCurrent stateCurrent state and input
Typical output changeAfter a state transitionAfter state or input changes
State countMay require more statesOften fewer states
Input-to-output pathNo direct combinational pathCan respond within a cycle

Moore diagram for the same pattern

Four-state Moore state diagram detecting sequence 101; output is 1 only in the matched state
This Moore detector asserts output 1 in the matched state. Compare it with the Mealy diagrams above: Moore outputs label states, while Mealy outputs label transitions.

Example: detecting the sequence 10

States can represent how much of the pattern has been seen: no useful prefix, a trailing 1, and a completed 10. A Moore detector asserts its output in the completed state. A Mealy detector can assert on the transition that receives 0 while in the “seen 1” state. Both detect the same sequence, but their output timing and state diagrams differ.

A practical design workflow

  1. Write the required behavior and identify what history must be remembered.
  2. Name each state and explain what it represents.
  3. Draw transitions for every input condition, including overlap cases.
  4. Choose Moore or Mealy output rules and label outputs clearly.
  5. Encode states, derive next-state logic, then verify every transition with a table or simulation.

Choose Moore when predictable state-based outputs are the priority. Choose Mealy when an immediate input response or smaller state graph matters, and check output timing carefully.

Keep learning

Use this concept in a tool

Try the idea interactively, then check how the inputs affect the output.