Search code examples
x86mipscpu-architectureprogram-counter

What does the PC register point to after fetch is completed?


What does the PC register point to after fetch is completed?

Is it the address of the next instruction to be executed, or something else?


Solution

  • In x86, the IP register (Intel's name for the PC) doesn't have a clearly defined value except

    • when it is written to the stack by a call, interrupt, or fault, in which case it has the address of the instruction following the last instruction that completed execution.
    • when it is used for IP-relative addressing, in which case it has the address of the instruction following the instruction that contains the IP-relative address.
    • other cases that I won't go into here, such as task switches.

    Because of pipelining, in no case is that related to the last instruction fetched. In fact, there can be several instructions with IP-relative addresses being executed at the same time, and each of them uses a distinct IP value in its address computation.

    (I presume that the same is true for MIPS, but I can't say.)