The difference between Miles and Moore

Is there a difference between the Myaly and Moore state machines, does it make any real difference when it comes to implementing C? What's the difference?

Once upon a time, it was much easier for me to understand the advantages / disadvantages of Mealy / Moore when it comes to RTL. The whole conclusion, depending on the current state / output depending on the current state + the difference in the current inputs, makes sense, as well as the fact that Miles could be made with 1 smaller state, in some cases also makes sense. Comparing the timing diagrams with each FSM implementation also made the difference between them clearer.

Let's say I make a state machine in C. In one case, the LUT depends on the state / current inputs (Mealy), and in Moore, the LUT just looks at the current state and returns the next one. In any case, the exit occurs after returning from the LUT (I think, although I could be wrong). I didn’t think that Mealy has an advantage when coding in C. Topics such as code readability, speed, code density, ease of design can be relevant topics - from my point of view, the two models seem almost the same.

Perhaps this difference is only a topic for scientists, and in practice in C implementations the difference is negligible. If you know the key ways to implement the C-automaton C, which will be different from Mealy and Moore, and if there are real advantages (which are also significant), I would be interested to know. I would like to emphasize - I am not asking about RTL implementation.

I saw another Miles / Moore entry here: Miles v / s. Moore

But this is not the level of explanation I'm looking for.

+7
source share
2 answers

You have a mechanical procedure for transforming one formalism into another, so there is no structural difference between them.

Speaking of differences in implementation, the two formalisms differ only in the output function, which tells you which character should be output. In particular:

  • In Moore, the output depends only on the current state.
  • On a Miles machine, the output depends on the current state and current input.

The Moore machine might be a little easier to implement, because you have less information to track when it comes to generating output, but the difference will be very small.

Here's what a simple Moore machine looks like in C:

int state = INITIAL; while (!isTerminal(state)) { char input = nextInputSymbol(); fprintf(output, "%c", nextOutputSymbol(state)); state = nextState(state, input); } 

and here’s Miley’s car:

 int state = INITIAL; while (!isTerminal(state)) { char input = nextInputSymbol(); fprintf(output, "%c", nextOutputSymbol(input, state)); state = nextState(state, input); } 

as you can see, the only difference is the definition of nextOutputSymbol() . Whether the implementation of this function is simpler for one or another formalism, it really depends on the particular application.

nextInputSymbol is just a procedure for getting a new character (maybe scanf or the like), and nextState will depend on the particular machine, but its complexity will not change much between Mealy and the Moore equivalent.

In particular, both nextOutputSymbol and nextState down to finding a table or chain of switch or if/else without real implementation complexity. Actually, it's just boring to write.

NOTE I skipped error checking in code snippets so that we focus on the main point of the discussion. Real world code would perform additional checks, such as handling EOF on nextInputSymbol or break on error conditions.

+4
source

Moore's car: the output depends only on the current state. Car "Miles": the output depends on both the current state and the current input.

+1
source

All Articles