Mealy and Moore machines

advertisement
TDDI11: Embedded Software
Mealy & Moore Machines
Mealy & Moore Machines
State machines
• There are two kinds of state machines
Th
t ki d f t t
hi
– Mealy and Moore
– Equally powerful
• Note: Finite state machines or finite automata are two names of the same thing
Finite Automata with Output
•
A Moore machine is a collection of 5 things:
1. a finite set of states q0,q1,q2,…, where q0 is designated the start state
2. an alphabet
p
 of input
p letters
3. an alphabet Γ of output characters
4. a transition table that shows for each state and each input letter what
state to go to next.
5. an output table that shows what character is output (or printed) when
entering
g a state.
((state, letter from )
transition
state
Finite Automata with Output
Example: states = {q0,q1,q2,q3} ={a,b} ={0,1}
Old state Output by the New state
Old
t t
O t t b th
N
t t
old state After input a After input b –q
q0
1 q
q1 q3
1
q1
0 q3 q1
q2
0 q0 q3
q3
1 q3 q2
q0 /
1
a
q2 /
0
a
b
b
b
q1 /
0
b
abab
a
q3 /
1
a
10010
Finite Automata with Output
Example: A machine that counts ‘aab’s
b
a
a
a
q0 /
0
b
q1 /
0
a
q2 /
0
b
q3 /
1
b
Input
a a a b a b b a a b b
State q0 q1 q2 q2 q3 q1 q0 q0 q1 q2 q3 q0
Output
0 0 0 0 1 0 0 0 0 0 1 0
Printing 1  found a word that end in aab
Finite Automata with Output
•
A Mealy machine is:
1 a finite set of states q
1.
fi i
f
h
i
0,q1,q2,…, where q
0 is designated the start state
2 an alphabet 
2.
an alphabet  of input letters
of input letters
3. an alphabet  of output characters
4 a finite set of transitions that indicate, for each state 4.
fi it
t ft
iti
th t i di t f
h t t
and letter of the input alphabet, the state to go to next and the character that is output.
next and the character that is output.
state
input/output
state
Finite Automata with Output
a/0
b/0
a/0
q0
b/0
q1
a/0
b/0
q2
a/0
b/1
q3
Finite Automata with Output
Example
a/0
q0
b/0
q1
a/1
a/0
b/1
q3
a/1
baaba
b/1
b/1
q2
01110
• Mealy and Moore machines are equivalent
M l
dM
hi
i l t
– If Mealy machine capture a model, so does a Moore machine
hi
• Moore model might require more states to model a system but simpler to understand
b i l
d
d
• Mealy model might require less states to model but might be more complex to understand
Download