# Moore and Mealy Machines

Finite automata may have outputs corresponding to each transition. There are two types of finite state machines that generate output −

• Mealy Machine
• Moore machine

### Mealy Machine

A Mealy Machine is an FSM whose output depends on the present state as well as the present input.

It can be described by a 6 tuple (Q, ∑, O, δ, X, q0) where −

·        Q is a finite set of states.

·         is a finite set of symbols called the input alphabet.

·        O is a finite set of symbols called the output alphabet.

·        δ is the input transition function where δ: Q × ∑ → Q

·        X is the output transition function where X: Q × ∑ → O

·        q0 is the initial state from where any input is processed (q0 ∈ Q).

The state table of a Mealy Machine is shown below −

The state diagram of the above Mealy Machine is −

### Moore Machine

Moore machine is an FSM whose outputs depend on only the present state.

A Moore machine can be described by a 6 tuple (Q, ∑, O, δ, X, q0) where −

·        Q is a finite set of states.

·         is a finite set of symbols called the input alphabet.

·        O is a finite set of symbols called the output alphabet.

·        δ is the input transition function where δ: Q × ∑ → Q

·        X is the output transition function where X: Q → O

·        q0 is the initial state from where any input is processed (q0 ∈ Q).

The state table of a Moore Machine is shown below −

The state diagram of the above Moore Machine is −

### Mealy Machine vs. Moore Machine

The following table highlights the points that differentiate a Mealy Machine from a Moore Machine.

## Moore Machine to Mealy Machine

### Algorithm 4

Input − Moore Machine

Output − Mealy Machine

Step 1 − Take a blank Mealy Machine transition table format.

Step 2 − Copy all the Moore Machine transition states into this table format.

Step 3 − Check the present states and their corresponding outputs in the Moore Machine state table; if for a state Qi output is m, copy it into the output columns of the Mealy Machine state table wherever Qi appears in the next state.

### Example

Let us consider the following Moore machine −

Now we apply Algorithm 4 to convert it to Mealy Machine.

Step 1 & 2 −

Step 3 −

## Mealy Machine to Moore Machine

### Algorithm 5

Input − Mealy Machine

Output − Moore Machine

Step 1 − Calculate the number of different outputs for each state (Qi) that are available in the state table of the Mealy machine.

Step 2 − If all the outputs of Qi are same, copy state Qi. If it has n distinct outputs, break Qi into n states as Qin where n = 0, 1, 2…….

Step 3 − If the output of the initial state is 1, insert a new initial state at the beginning which gives 0 output.

### Example

Let us consider the following Mealy Machine −

Here, states ‘a’ and ‘d’ give only 1 and 0 outputs respectively, so we retain states ‘a’ and ‘d’. But states ‘b’ and ‘c’ produce different outputs (1 and 0). So, we divide b into b0, b1 and c into c0, c1.