问题
I'm not so familiar with computing (software) theory, and I thought about this question - does the PC (program counter) always have to change (I guess, upon each new clock tick)?
I searched a bit online, and found Commodore 64 Programmers Reference Manual (heh :)) that confirms it: "...Commodore 64 (or, for that matter, any computer), the program counter is always changing" (as well as Chapter 6: Hard, soft or firm?); but I just wanted to have it commented here.
I was thinking, if an instruction set the PC (or rather next PC), so the next execution address is same as its current one, there would be no way to exit that loop (unless there is some extern interrupt, of course)?
回答1:
The program counter changes when it needs to change. If your current instruction takes a while, or your program isn't the current one being executed (remember, most computers are running more than one thread of execution) then it is not necessary that it change on every clock tick.
Yes, changing the PC so that it changes itself to the beginning of a set of instructions that sets itself to the beginning of a set of instructions that sets itself... as you can see, yes, this would cause an infinite loop. This is pretty much what the old '20 GOTO 10' situation was about.
回答2:
Generally speaking, the program counter doesn't have to change on every clock tick. An instruction could take a number of clock ticks to execute, and then when it finished, the program counter would change.
来源:https://stackoverflow.com/questions/6984365/does-the-program-counter-always-have-to-change-upon-a-clock-tick