What is Mealy machine?

A state machine whose outputs depend on both the current state and the inputs. Input changes reach outputs within the same cycle, but so can input glitches. A Moore machine's outputs depend only on state.

Field: HDL & Verification

Japanese name: ミーリ型

Definition and structure of a Mealy machine

In a Mealy state machine, outputs depend on both the current state and the current inputs. Like a Moore machine, it consists of a state register, combinational logic for the next state and combinational logic for the outputs, but the inputs connect directly to the output logic. In a state diagram, outputs are written on the transition arrows as input/output rather than inside the states. Because outputs change as soon as inputs change, without waiting for the next clock, a Mealy machine can react one cycle sooner than a Moore machine and often implements the same function with fewer states.

Mealy vs. Moore

In a Moore machine, outputs depend only on the current state and are written inside the states in a state diagram. An input change reaches the outputs only after the clock changes the state, so the response is a cycle later, but input noise does not pass to the outputs and timing is easier to predict. Encoding the states so that outputs come directly from state-register bits also eliminates output glitches. In a Mealy machine, a combinational path runs from inputs to outputs, so input glitches appear at the outputs and timing paths that include the surrounding logic become longer.

Example: a sequence detector

Consider an overlapping sequence detector that outputs 1 when it finds 101 in an input bit stream. A Mealy machine needs only three states: nothing matched, matched 1, and matched 10. In the matched-10 state, the output goes to 1 as soon as a 1 arrives, and the machine moves to matched 1, treating that 1 as the start of the next candidate. A Moore machine needs an extra detected-101 state to represent output 1, giving four states, and its output becomes 1 only after the clock that captures the final 1. The Mealy machine thus uses fewer states and responds faster, while the Moore machine has the edge in output stability.

Design tips in HDL

In Verilog or VHDL it is common to write a sequential block that updates the state register separately from a combinational block that determines the next state and outputs; if the output expressions include inputs, the machine is a Mealy machine. Using asynchronous inputs directly disturbs the outputs, so inputs should be synchronized first. Connecting a Mealy output to the input of another Mealy machine can create a combinational loop, so care is needed. Registering the outputs through flip-flops removes glitches, but the timing then lags by one cycle, just like a Moore machine.

Try it: questions about Mealy machine

Which type of sequential circuit (state machine) has outputs determined only by the current state?

  1. AMealy machine
  2. BMoore machine
  3. CHarvard machine
Show answer and explanation

Answer: B. Moore machine

In a Moore machine, outputs depend only on the current state; in a Mealy machine, they depend on both state and inputs. Moore outputs change only after a clock edge and input changes or glitches do not pass straight to them, so they are stable and predictable, but they respond a clock later and often need more states. Mealy machines need fewer states and react immediately, but input changes pass directly to the outputs. Real designs mix both styles.

What characterizes a Mealy state machine?

  1. AOutputs depend only on the state and do not change until the next clock
  2. BOutputs depend on both current state and inputs, so input changes appear at the output within the same cycle
  3. CIt is combinational logic with no state
Show answer and explanation

Answer: B. Outputs depend on both current state and inputs, so input changes appear at the output within the same cycle

In a Mealy machine the output logic looks at inputs as well as the current state, so outputs change with inputs without waiting for a clock, reacting one cycle sooner. It may also need fewer states. But a combinational path runs from inputs to outputs, so input glitches can appear at outputs and timing paths get longer. Outputs are sometimes re-registered through flip-flops.

FAQ

What is the difference between a Mealy machine and a Moore machine?

A Mealy machine's outputs depend on both the current state and the inputs, while a Moore machine's depend only on the current state. A Mealy machine can respond to inputs in the same cycle and often needs fewer states, but input noise passes to its outputs more easily.

Which should I use, Mealy or Moore?

Mealy suits cases where response speed or fewer states matter; Moore suits cases where output stability and predictable timing matter. Real designs choose per output or combine both.

Can a Mealy machine be converted to a Moore machine?

Yes. Splitting each Mealy state according to the output of the transitions entering it into separate Moore states gives the same input-output relationship. The number of states may increase, however, and the outputs appear one clock later.

Books on HDL & Verification Ad

As an Amazon Associate I earn from qualifying purchases.

Comparisons that include this term

This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.

Back to the glossary