To illustrate the use of FHDL to code simple state machines, consider the following example.

This state machine would be coded in FHDL as follows.
| example2: | circuit | |
| inputs | x1,x2,x3,x4,x5 | |
| outputs | o1,o2,o3,o4 | |
| asm_state | A,testa,o=o1 | |
| asm_test | testa,(A,B,C,B),c=(x1,x4) | |
| asm_state | B,testb,o=o2 | |
| asm_test | testb,(B,A),c=x5 | |
| asm_state | C,testc,o=o3 | |
| asm_test | testc,(C,D),c=x2 | |
| asm_state | D,testd,o=o4 | |
| asm_test | testd,(D,B),c=x3 | |
| endcircuit |
The following is a more complicated example.

This example would be coded in FHDL as follows.
| example3: | circuit | |
| inputs | x1,x2,x3 | |
| outputs | o1,o2,o3,o4,o6,o6 | |
| asm_state | A,test1,o=o1 | |
| asm_test | test1,(cout1,C,C,cout2),c=(x1,x2) | |
| asm_cond | cout1,B,o=o2 | |
| asm_cond | cout2,D,o=o3 | |
| asm_state | B,test2,o=o4 | |
| asm_test | test2,(B,A),c=x3 | |
| asm_state | C,A,o=(o5,o6) | |
| asm_state | D,A | |
| endcircuit |
If a state machine requires a clock, it must be specified on the circuit statement, and in the list of primary inputs. The following is a modified version of the first two statements of example3, to include a clock.
| example3: | circuit | clock=iclk |
| inputs | x1,iclk,x2,x3 |
If it is necessary for the current state of the state machine to be visible to other logic in your design, place the name current_state in the list of primary outputs. The following is a modification of example3 to include a clock and current_state output.
| example3: | circuit | clock=iclk |
| inputs | x1,x2,x3,iclk | |
| outputs | o1,o2,o3,current_state,o4,o6,o6 |
Once a state machine has been declared, it can be used just like any other subnetwork. The state machine can be used any number of times. Each time the state machine is used, a new copy of the machine is created.