Answer:
The FSM uses the states along with the generation at the P output on each of the positive edges of the CLK. The memory stores the previous state in the machine and the decoder generates a P output based on the previous state.
Step-by-step explanation:
The code is in the image.