Simultaneously incrementing the program counter and loading the Instruction register

StackOverflow https://stackoverflow.com/questions/21988568

  •  15-10-2022
  •  | 
  •  

Question

In my Computer Architecture lectures, I was told that the IR assignment and PC increment are done in parallel. However surely this has an effect on which instruction is loaded.

If PC = 0, then the IR is loaded and then the PC incremented then the IR will hold the instruction that was at address 0.

However if PC = 0, the PC incremented and then the IR is loaded and then the IR will hold the instruction that was at address 1.

So surely they can't be done simultaneously and the order must be defined?

Was it helpful?

Solution

You're not taking into account the wonders of FlipFlops. The exact implementation depends of course on your specific design, but it's perfectly possible to read the value currently latched on some register or latch, while at the same time preparing a different value to be stored there, as long as you know these values are independent (there's also a possibility of doing a "bypass" in more sophisticated designs, but that's besides the point here).

In this case, you'd be reading the current value of the PC (and using it to fetch the code from memory, or cache, or whatever), while preparing the next value (for e.g. PC+4 or some branch target if you know it). This is how pipelines work.

Generally speaking, you either have enough time to do some work withing the same cycle (incrementing PC and using it for code fetch), in which case they'll fit in the same pipestage, or if you can't make it in time - you just break these serial activities to two pipestages, so that they can be done in "parallel" because one of them belongs to the next operation flowing through the pipe, so there's no longer a dependency (aside from corner cases like branches or bubbles)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top