Moore vs Mealy machine: the same detector built both ways
Moore and Mealy machines are the two kinds of finite state machine. In a Moore machine the outputs depend only on the current state, so each state has its output written inside it and the outputs change only on clock edges. In a Mealy machine the outputs depend on the current state and the current inputs, so the output is written on the transitions, and it can change as soon as an input changes. Both can describe the same behaviour; they differ in how many states they need, when the output appears and how clean it is. In short: Mealy usually needs fewer states and answers one clock sooner; Moore gives outputs that change only on the clock edge and cannot glitch with the input.
What each one is good at
A Moore machine is good when outputs must be stable: because they come from the flip-flops alone (through logic that depends only on the state), an input that bounces in the middle of a clock cannot reach them, and every output lasts a whole number of clocks. That makes Moore outputs safe to feed other clocked logic directly. A Mealy machine is good when states or time are scarce: the output can use the input directly, so a state that exists only to hold an output disappears, and the reaction comes in the same clock as the input that causes it. The price is that a Mealy output follows its inputs combinationally, so designs that need a clean output often register it, which costs the clock it saved.
Both machines, live in digiwleea
Both versions of a 1011 sequence detector run live in digiwleea, built from D flip-flops and gates and checked clock by clock before the pages are built. The Moore 1011 detector has five states (nothing, 1, 10, 101, 1011) and needs three flip-flops; Z comes from the state alone. The Mealy 1011 detector has four states and two flip-flops; Z = Q1 Q0 X lights during the clock of the final 1. The timing table below runs the same input through both. More machines to try: a turnstile, a vending machine and a traffic light controller, with the theory in the sequence detector lesson.
Moore and Mealy side by side
| Moore | Mealy | |
|---|---|---|
| Outputs depend on | State only | State and current input |
| Where outputs are drawn | Inside the states | On the transitions |
| 1011 detector | 5 states, 3 flip-flops | 4 states, 2 flip-flops |
| When the output appears | After the clock edge, one clock later | In the same clock as the input |
| Output changes | Only on clock edges | Whenever the input changes |
| Glitches from the input | No | Possible |
The same input through both detectors
| Clock | X | Moore state | Moore Z | Mealy state | Mealy Z |
|---|---|---|---|---|---|
| 1 | 1 | S0 | 0 | S0 | 0 |
| 2 | 0 | S1 | 0 | S1 | 0 |
| 3 | 1 | S2 | 0 | S2 | 0 |
| 4 | 1 | S3 | 0 | S3 | 1 |
| 5 | 0 | S4 | 1 | S1 | 0 |
| 6 | 1 | S2 | 0 | S2 | 0 |
| 7 | 1 | S3 | 0 | S3 | 1 |
| 8 | 0 | S4 | 1 | S1 | 0 |
X = 1011011, then 0. Each row is one clock: the state during that clock, and the output during that clock. The Mealy Z lights during clocks 4 and 7, as the final 1 arrives; the Moore Z lights in clocks 5 and 8, after the edge that enters S4. Both find the overlapping second match.
No sign-up is needed to start: open the lab and place your first transistor, or read the free theory course. The account (and the AI tutor) are optional.
More comparisons: Digital logic concepts compared
See for yourself: build a logic gate from transistors in the simulator, then follow the path from sand to an 8-bit CPU.
Open the digiwleea lab →Frequently asked
What is the difference between a Moore and a Mealy machine?
In a Moore machine the outputs depend only on the current state, so they change only on clock edges. In a Mealy machine the outputs depend on the current state and the current inputs, so they can change as soon as an input does.
Which needs fewer states, Moore or Mealy?
Usually Mealy. A Moore machine needs a state for each distinct output, while a Mealy machine can produce the output on a transition. A 1011 detector needs five states as Moore and four as Mealy.
Which is faster, Moore or Mealy?
A Mealy machine responds in the same clock as the input that causes the output; the equivalent Moore machine responds one clock later, after the edge that enters the output state.
Why can a Mealy output glitch?
Because the input feeds the output logic directly. If the input changes or bounces during a clock, the output can change with it. Moore outputs come only from the state, which changes only on clock edges.
How do you convert a Mealy machine to a Moore machine?
Split every state that is entered with different outputs into one copy per output value, and write that output inside the copy. The Moore machine may need more states and responds one clock later. Going from Moore to Mealy, move each state's output onto the transitions that enter it.
How do you tell from a state diagram whether it is Moore or Mealy?
In a Moore diagram the outputs are written inside the states, like S4 / Z = 1. In a Mealy diagram they are written on the arrows with the input, like 1 / 1 for input 1, output 1.