Electronic – Why do we need a flip-flop in this circuit

circuit-designdigital-logicflipfloplogic-gatesmultiplexer

Supposing I built some machine x3 that is capable of multiplying the input by 3. If I want to multiply some number with 3^3 then I should use 3 instances of the machine.

My book asked for another solution using minimal hardware. The solution appears in the image I have added, where S is 0 for the first clock cycle and then for other cycles it's 1 to allow previous result to enter and multiply it by 3.

But I can't understand why we need the flip-flop here? Why can't we just connect the output of x3 directly to the mux? What's the problem with that?

I know it's wrong because removing the flip-flop will result in using less hardware so if it was true my book would mention it.

enter image description here

Best Answer

I mean...you don't technically need a clock, but if you decided beforehand you want to use a clock then you would need the flip flop.

Why would you want to use a clock? It makes timing and synchronization in system easier to control and more predictable which makes it easier to design and test for. Really important in a large, or even moderately sized system.

Flip-flops are the quintessential edge-triggered logic. Along with the fact that they have memory, this makes them the gate-keeper component that can block when there is no clock edge, sample signals on the clock edge, and preserve the output signal away from a clock edge. Flip-flops allow the the clock control the flow of signals from one component to the next.

In your example, if you did not use a clock and removed the flip flop you would be relying on the propagation delay in the wire from the output of the 3x block to the input of the mux. If you're lucky, it would continuously multiply at an insanely fast, uncontrollable speed. If you're not lucky it would try and multiply when the signal at the input was at half transition and give out garbage over and over again.

To slow it down you would need a really long wire to delay things which introduces other issues and is precarious. Or, you use a flip-flop controlled by a clock regulate when the output gets fed back to the input.

For more information, look up "synchronous vs asynchronous design".