Skip to content
BetterDL

Mealy machine

Also called: Mealy, Mealy FSM, Mealy output, Mealy model

A finite state machine whose outputs depend on the present state and the present inputs, so they are written on the arrows as input/output.

In a Mealy machine, the output gates read the state flip-flops and the input wires. So the output belongs to an arrow, not a state.

  • In a state diagram, each arrow is labeled input/output. 0/1 means "on input 0, output 1 and follow this arrow".
  • In a state table, each cell holds next state / output: one output per cell, not per row.
  • The output equation mentions an input, for example Z = .

Because the output reads the input directly, it can change as soon as the input changes, without waiting for a clock edge. That makes a Mealy machine react one cycle earlier than a moore machine, and it often needs fewer states: a sequence detector for an n-bit pattern needs only n.

The flip side: a Mealy output can glitch whenever the input glitches, and it's only valid once the input has settled. Designers often register a Mealy output, or pick Moore, when a clean signal matters.

When tracing a Mealy machine, read the output on the arrow you take.

start0/01/00/01/00/11/0ABC

Worked examples

Example

Tracing a Mealy 110 detector

The diagram detects 110, overlapping: A = nothing, B = seen 1, C = seen 11. Apply 1, 1, 0, 1, 1, 0 from A.

  1. 1.

    1: A → B on 1/0. Output 0.

  2. 2.

    1: B → C on 1/0. Output 0.

  3. 3.

    0: C → A on 0/1. Output 1 (110 complete).

  4. 4.

    1: A → B, output 0. 1: B → C, output 0. 0: C → A, output 1.

  5. 5.

    Outputs: 0, 0, 1, 0, 0, 1, the same as the Moore 110 detector, with one state fewer.

Example

Mealy vs Moore on a clock

The Mealy and Moore 110 detectors both start in their first state. The clock rises at the start of slots 1, 3, 5 and 7, and X changes just after each edge: 1, 1, 0, 0, one value per clock cycle.

CLKXMealy ZMoore Z
  1. 1.

    Cycle 1: Mealy in A, Moore in S0. Both Z = 0.

  2. 2.

    Cycle 2: the edge saw X = 1. Mealy in B, Moore in S1. Both Z = 0.

  3. 3.

    Cycle 3: the edge saw X = 1 again. Mealy in C, Moore in S2. Now X = 0 completes 110: Mealy Z = 1 straight away, because it reads X.

  4. 4.

    Cycle 4: the edge saw X = 0. Moore moves into S3, so Moore Z = 1 now, one cycle after Mealy. Mealy is back in A with Z = 0.

Common mistakes

  • Writing the output inside the state. A Mealy state has no single output; it depends on the input.

  • Reading the output from the next arrow instead of the one being taken.

  • Assuming the output waits for the clock. A Mealy output can change mid-cycle when the input changes.

Practice Mealy machine

Interactive questions with instant feedback and a worked solution for every wrong answer.

Learn it step by step

Mealy machine is taught in Finite State Machines.