Digital Logic & Building Blocks

a finite state machine

/ FY-nyt /

A finite state machine is the standard pattern for a hardware controller: a circuit that is always in exactly one of a small, fixed set of states, and that moves between them in response to inputs. Think of a vending machine that goes from 'idle' to 'coins inserted' to 'dispensing' and back to 'idle' — at any moment it sits in one named state, and each coin or button press triggers a transition to the next. An FSM captures behaviour over time as a tidy diagram of states (the circles) and transitions (the arrows between them), which is exactly how engineers describe and build the control logic that sequences a machine's actions.

In hardware an FSM has three parts. A state register (a bank of flip-flops) holds the current state. A piece of combinational logic — the next-state logic — looks at the current state and the inputs and computes which state to move to on the next clock edge. A second piece — the output logic — produces the machine's outputs. There are two flavours: in a Moore machine the outputs depend only on the current state (steadier, easier to time); in a Mealy machine they also depend on the inputs (can react one cycle sooner, with fewer states). Each clock tick, the next-state logic settles, and the edge loads the chosen next state into the register — and the cycle repeats.

Why it matters: the FSM is the controller pattern, the brain that tells a datapath what to do and when. A processor's control unit is essentially a finite state machine (or several) that steps an instruction through fetch, decode, execute, and so on, raising the right control signals in each state. Traffic lights, communication protocols, elevator controllers, and the handshakes inside memory and I/O are all FSMs. The 'finite' is the honest heart of it: because there are only finitely many states, the whole behaviour is enumerable and verifiable — but it also means an FSM cannot count without bound or remember an unlimited history; that requires adding more storage outside the state register.

A turnstile FSM has two states: Locked and Unlocked. From Locked, inserting a coin transitions to Unlocked; from Unlocked, pushing through transitions back to Locked. A coin while Unlocked or a push while Locked changes nothing. Two states, four arrows — and that tiny diagram is a complete, buildable specification of the controller.

States and transitions: an FSM is the controller's brain, and a processor's control unit is one of these.

The word finite is a real limit, not decoration. An FSM has a fixed number of states, so it cannot, by itself, count or remember without bound — to handle arbitrarily large counts you must add a register or memory beyond the state register; the control structure alone is not enough.

Also called
FSM有限狀態機狀態機finite automaton