0

Why are there distinct instructions execution stages(fetch, decode,execute,store)? Aren't these parts of a CPU connected one after another? I have created a simple CPU in digital logic simulator and it simultaneously fetches, decodes and executes an instruction. What exactly forces a CPU to do these steps separately,one at a time, and not simultaneously since each part's input is connected to another's output?

qukert
  • 77

2 Answers2

1

Digital logic simulator is a game. It is not a true representation of what is happening at the physical level.

It is a logic puzzle, and as such does not include a simulation down at the physical hardware level. Things happen "immediately" in it because it calculates the entire chain before it shows you it. It does not include all the clock pulses needed for each signal to propagate through the circuit, presumably because doing so would upset the clean visual design.

To reiterate, whatever you create in that game is not how circuits work in real life. It might give you the essential logic blocks, but it does not give you any of the fine electronic details.

In real electronics signals are not continuous, they are gated and synchronised by a clock pulse that tells each step when they should read an input or write an output. Without that gating signals would propagate nearly immediately and, due to the fact that electronic devices have different wire lengths, different timings, and different operation, the signals out of any group of logic would be nearly random.

You can let the logic free-run, but due to different timing in the circuit the timing outputs of any repeated set of circuitry, such as an 8-bit adder, would be slightly offset from each other. The circuit would eventually settle down to the correct value, but initially go through a lot of values before it settled.

The clock signal allows data to be marshalled in, logic levels to settle, and then data to be marshalled out at a known point in time. The next circuit in line knows that when it receives a clock pulse that it's input from the previous circuit is in a good state, and when that circuit is done it will put out a good set of signals itself on a clock pulse.

You should read up more on combinational and sequential logic. Your game is a cute project on how digital logic can be combined to perform tasks, but it is not an electronics simulator.

Mokubai
  • 95,412
0

I could be misunderstanding (this is not my area of expertise), but I suspect my understanding is the same as @sawdust - I don't see how a logic simulator can do this in a single cycle.

Each distinct instruction is a step, and needs to be done in order - so I can't see how this can all be done in a single cycle. (How does the CPU know to fetch, decode, execute, store and not fetch, decode, store, execute for example)?

davidgo
  • 73,366