TCS Lect 9 - 10 FSM With Output
TCS Lect 9 - 10 FSM With Output
2. Mealy Machine
• Formal Definition:
M = ( Q , Σ , Δ , δ , λ, q0 )
Δ is Output Alphabet
q0 is an initial state q0 ε Q
q1 q2 q1 1 q2 / 0
q2 q2 q0 0
Output Function:
λ ( q0 ) = 1 0
λ ( q1 ) = 1
λ ( q2 ) = 0 Prepared By: Mr. Vaibhav Ambhire
Moore Machine 1
Transition Function ( δ ):
1
δ ( q0 , 0 ) = q1 δ ( q0 , 1 ) = q2 0
δ ( q1 , 0 ) = q2 δ ( q1 , 1 ) = q1 1
δ ( q2 , 0 ) = q2 δ ( q2 , 1 ) = q0 q2 / 0
• Formal Definition:
M = ( Q , Σ , Δ , δ , λ, q0 )
Δ is Output Alphabet
q0 is an initial state q0 ε Q
• Transition Table: q0 q1
Solution:
0
For 1's complement if input is 0 then output will be 1.
q0 / 0 q1 / 1
If input is 1 then output will be 0.
Solution:
0
Simulation for the input: 1 1 0 1
q0 / 0 q1 / 1
0
1 1
Input 1 1 0 1
State q0 q2 q2 q1 q2 q2 / 0
Output 0 0 0 1 0
Solution:
1 0 1
q0 / C q1 / C q2 / C q3 / A
1
0
q4 / C q5 / B
Solution:
0
Prepared By: Mr. Vaibhav Ambhire
Examples on Moore Machine
Ex. 2 Design a Moore machine for binary number input sequence such that if it has a substring 101 then machine
outputs A, if input has substring 110, it outputs B, otherwise it gives output C
Solution:
0
Prepared By: Mr. Vaibhav Ambhire
Examples on Moore Machine
Ex. 2 Design a Moore machine for binary number input sequence such that if it has a substring 101 then machine
outputs A, if input has substring 110, it outputs B, otherwise it gives output C
Solution:
1 1 0 q2 C
1 q3 A
0 1
q4 / C q5 / B 1 q4 C
1 0 q5 B
0 q0 C
0
Prepared By: Mr. Vaibhav Ambhire
Examples on Mealy Machine 0/0
Ex. 3 Design a Mealy machine to generate 2's complement of given binary number q0
Solution:
1/ 1
For designing 2's complement of binary number, we assume that input is read from LSB to
MSB
Keep that 1 as it is and then change remaining 1's by 0's and 0's by 1's
Ex. 3 Design a Mealy machine to generate 2's complement of given binary number q0
Solution:
1/ 1
Transition Table:
Ex. 3 Design a Mealy machine to generate 2's complement of given binary number q0
Solution:
1/ 1
Simulation for the input: 1 0 1 1
q1
Input 1 1 0 1
State q0 q1 q1 q1 q1
Output 1 0 1 0
1/0
0/1
Resultant Number: 1 1 1 0
0/0
We can observe that to get output 1/ 1
Once we get first 0 we will replace it by 1 and then keep remaining bits as it is
q1
Input 1 1 0 1
State q0 q0 q0 q1 q1
Output 0 0 1 1
0/0
1/ 1
1 0
1 0
Δ = { 0, 1 }
q0 = q0
δ and λ are shown in transition table Prepared By: Mr. Vaibhav Ambhire
Examples
0 1
Ex.1 The Moore machine to determine
1 0 residue mod 3 for binary number is
q0 / 0 q1 / 1 q2 / 2 given.
1 0
Solution:
a a State/ Output
b Input a b
λ
a b b q0 q1 q0 b
q0 / b q1 / a q2 / b q3 / a q1 q1 q2 a
q2 q1 q3 b
a q3 q1 q0 a
b
Solution:
a a
b
Above FSM can be represented as
a b b M = ( Q , Σ , Δ , δ , λ, q0 )
q0 / b q1 / a q2 / b q3 / a
Where Q = { q0, q1, q2, q3 }
a
Σ = { a, b }
b
Δ = { a, b }
q0 = q0
δ and λ are shown in transition
table
Prepared By: Mr. Vaibhav Ambhire
Example
Ex. 3 Design a Moore machine to convert each occurrence of substring abb by aba
Solution:
a a
b
Solution:
2/2
1/1 1/1
0/0
1/1
0/0
0/0 2/2
2/2
1/1
0/0
0/0 2/2
2/2
Solution:
0 0/B
• Example: • Example:
1 1/B
q1/B q0 q1
q0/A
1 1 /A
Prepared By: Mr. Vaibhav Ambhire
FSM with Output
• Applications:
1. Text Editors
- Processing Text
- Uses Regular Expressions for substituting strings
2. Lexical Analysis
- Separate Tokens and recognize them
• Limitations